From 2997c2ef9489c9455fcd1d826d5825845c3067b8 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 9 May 2019 14:42:52 -0400 Subject: [PATCH 01/80] Test --- sopel_modules/SpiceBot_AI/AI.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot_AI/AI.py b/sopel_modules/SpiceBot_AI/AI.py index 19e0772..322fe57 100644 --- a/sopel_modules/SpiceBot_AI/AI.py +++ b/sopel_modules/SpiceBot_AI/AI.py @@ -185,7 +185,8 @@ def bot_command_nick(bot, trigger): elif fulltrigger.lower().startswith("can you see"): target = spicemanip.main(triggerargs, "4+") or None if not target: - target = 'me' + bot.osd(trigger.nick + ", I can see clearly.") + return if target in [trigger.nick, 'me']: bot.osd(trigger.nick + ", I can see you.") else: @@ -200,7 +201,7 @@ def bot_command_nick(bot, trigger): # TODO return - if not inlist(bot, triggercommand, bot.memory['SpiceBot_CommandsQuery']['commands']["nickname"].keys()): + else: closestmatches = similar_list(bot, triggercommand, bot.memory['SpiceBot_CommandsQuery']['commands']["nickname"].keys(), 3, 'reverse') From b22dbfef15648b45cecec7f5182fc0e785f61265 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 9 May 2019 14:51:27 -0400 Subject: [PATCH 02/80] jedi list --- sopel_modules/SpiceBot_AI/AI.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sopel_modules/SpiceBot_AI/AI.py b/sopel_modules/SpiceBot_AI/AI.py index 322fe57..682e1fa 100644 --- a/sopel_modules/SpiceBot_AI/AI.py +++ b/sopel_modules/SpiceBot_AI/AI.py @@ -134,7 +134,7 @@ def bot_command_nick(bot, trigger): bot.osd(trigger.nick + ", what would you like me to beam you?") return - elif fulltrigger.lower().startswith(tuple(["beam me to"])): + elif fulltrigger.lower().startswith("beam me to"): location = spicemanip.main(triggerargs, "4+") or None if location: bot.osd("locks onto " + trigger.nick + "s coordinates and transports them to " + location, 'action') @@ -142,7 +142,7 @@ def bot_command_nick(bot, trigger): bot.osd(trigger.nick + ", where would you like me to beam you?") return - elif fulltrigger.lower().startswith(tuple(["beam me up"])): + elif fulltrigger.lower().startswith("beam me up"): bot.osd("locks onto " + trigger.nick + "s coordinates and transports them to the transporter room.", 'action') return @@ -153,7 +153,7 @@ def bot_command_nick(bot, trigger): if trigger.is_privmsg: jedi = None else: - jedilist = bot.channels[trigger.sender].privileges.keys() + jedilist = list(bot.channels[trigger.sender].privileges.keys()) for nonjedi in [bot.nick, trigger.nick]: if nonjedi in jedilist: jedilist.remove(nonjedi) From 45879894e8170d59c1add04c2ea2e56452ac56db Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 10 May 2019 07:54:03 -0400 Subject: [PATCH 03/80] Do more forced replacement on osd --- sopel_modules/SpiceBot_osd/__init__.py | 138 ++++++++++++++++++------- 1 file changed, 102 insertions(+), 36 deletions(-) diff --git a/sopel_modules/SpiceBot_osd/__init__.py b/sopel_modules/SpiceBot_osd/__init__.py index 105158a..2ae82be 100644 --- a/sopel_modules/SpiceBot_osd/__init__.py +++ b/sopel_modules/SpiceBot_osd/__init__.py @@ -37,17 +37,24 @@ def setup(bot): # Inject OSD bot_logging(bot, 'SpiceBot_OSD', "Implanting OSD function into bot") bot.osd = SopelOSD.osd - sopel.bot.SopelWrapper.osd = SopelOSD.SopelWrapper.osd + sopel.bot.SopelWrapper.osd = SopelWrapperOSD.osd tools.get_available_message_bytes = ToolsOSD.get_available_message_bytes tools.get_sendable_message_list = ToolsOSD.get_sendable_message_list tools.get_message_recipientgroups = ToolsOSD.get_message_recipientgroups # overwrite default bot messaging bot_logging(bot, 'SpiceBot_OSD', "Overwrite Default Sopel messaging commands") - sopel.bot.SopelWrapper.say = SopelOSD.SopelWrapper.say - sopel.bot.SopelWrapper.action = SopelOSD.SopelWrapper.action - sopel.bot.SopelWrapper.notice = SopelOSD.SopelWrapper.notice - sopel.bot.SopelWrapper.reply = SopelOSD.SopelWrapper.reply + bot.osd = SopelOSD.osd + bot.say = SopelOSD.say + bot.action = SopelOSD.action + bot.notice = SopelOSD.notice + bot.reply = SopelOSD.reply + bot.msg = SopelOSD.msg + sopel.bot.SopelWrapper.say = SopelWrapperOSD.say + sopel.bot.SopelWrapper.action = SopelWrapperOSD.action + sopel.bot.SopelWrapper.notice = SopelWrapperOSD.notice + sopel.bot.SopelWrapper.reply = SopelWrapperOSD.reply + sopel.bot.SopelWrapper.msg = SopelWrapperOSD.msg # verify config settings for server bot_logging(bot, 'SpiceBot_OSD', "Checking for config settings") @@ -318,39 +325,98 @@ class SopelOSD: finally: self.sending.release() - class SopelWrapper(object): + def say(self, text, recipient, max_messages=1): + """Send ``text`` as a PRIVMSG to ``recipient``. + In the context of a triggered callable, the ``recipient`` defaults to + the channel (or nickname, if a private message) from which the message + was received. + """ + self.osd(text, recipient, 'PRIVMSG', max_messages) - def osd(self, messages, recipients=None, text_method='PRIVMSG', max_messages=-1): - if recipients is None: - recipients = self._trigger.sender - self._bot.osd(self, messages, recipients, text_method, max_messages) + def notice(self, text, dest, max_messages=1): + """Send an IRC NOTICE to a user or a channel. - def say(self, message, destination=None, max_messages=1): - if destination is None: - destination = self._trigger.sender - self._bot.osd(self, message, destination, 'PRIVMSG', 1) - # self._bot.say(message, destination, max_messages) + Within the context of a triggered callable, ``dest`` will default to + the channel (or nickname, if a private message), in which the trigger + happened. + """ + self.osd(text, dest, 'NOTICE', max_messages) - def action(self, message, destination=None, max_messages=1): - if destination is None: - destination = self._trigger.sender - self._bot.osd(self, message, destination, 'ACTION', 1) - # self._bot.action(message, destination, max_messages) + def action(self, text, dest, max_messages=1): + """Send ``text`` as a CTCP ACTION PRIVMSG to ``dest``. - def notice(self, message, destination=None, max_messages=1): - if destination is None: - destination = self._trigger.sender + The same loop detection and length restrictions apply as with + :func:`say`, though automatic message splitting is not available. + + Within the context of a triggered callable, ``dest`` will default to + the channel (or nickname, if a private message), in which the trigger + happened. + """ + self.osd(text, dest, 'ACTION', max_messages) + + def reply(self, text, dest, reply_to, notice=False, max_messages=1): + """Prepend ``reply_to`` to ``text``, and send as a PRIVMSG to ``dest``. + + If ``notice`` is ``True``, send a NOTICE rather than a PRIVMSG. + + The same loop detection and length restrictions apply as with + :func:`say`, though automatic message splitting is not available. + + Within the context of a triggered callable, ``reply_to`` will default to + the nickname of the user who triggered the call, and ``dest`` to the + channel (or nickname, if a private message), in which the trigger + happened. + """ + text = '%s: %s' % (reply_to, text) + if notice: + self.osd(text, dest, 'NOTICE', max_messages) + else: + self.osd(text, dest, 'PRIVMSG', max_messages) + + def msg(self, recipient, text, max_messages=1): + # Deprecated, but way too much of a pain to remove. + self.osd(text, recipient, 'PRIVMSG', max_messages) + + +class SopelWrapperOSD(object): + + def osd(self, messages, recipients=None, text_method='PRIVMSG', max_messages=-1): + if recipients is None: + recipients = self._trigger.sender + self._bot.osd(self, messages, recipients, text_method, max_messages) + + def msg(self, destination=None, message='', max_messages=1): + if destination is None: + destination = self._trigger.sender + self._bot.osd(self, message, destination, 'PRIVMSG', 1) + # self._bot.say(message, destination, max_messages) + + def say(self, message, destination=None, max_messages=1): + if destination is None: + destination = self._trigger.sender + self._bot.osd(self, message, destination, 'PRIVMSG', 1) + # self._bot.say(message, destination, max_messages) + + def action(self, message, destination=None, max_messages=1): + if destination is None: + destination = self._trigger.sender + self._bot.osd(self, message, destination, 'ACTION', 1) + # self._bot.action(message, destination, max_messages) + + def notice(self, message, destination=None, max_messages=1): + if destination is None: + destination = self._trigger.sender + self._bot.osd(self, message, destination, 'NOTICE', 1) + # self._bot.notice(message, destination, max_messages) + + def reply(self, message, destination=None, reply_to=None, notice=False, max_messages=1): + if destination is None: + destination = self._trigger.sender + if reply_to is None: + reply_to = self._trigger.nick + message = '%s: %s' % (reply_to, message) + if notice: self._bot.osd(self, message, destination, 'NOTICE', 1) - # self._bot.notice(message, destination, max_messages) - - def reply(self, message, destination=None, reply_to=None, notice=False, max_messages=1): - if destination is None: - destination = self._trigger.sender - if reply_to is None: - reply_to = self._trigger.nick - message = '%s: %s' % (reply_to, message) - if notice: - self._bot.osd(self, message, destination, 'NOTICE', 1) - else: - self._bot.osd(self, message, destination, 'PRIVMSG', 1) - # self._bot.reply(message, destination, reply_to, notice, max_messages) + else: + self._bot.osd(self, message, destination, 'PRIVMSG', 1) + # self._bot.reply(message, destination, reply_to, notice, max_messages) From 15d419c481f745855678999c2c058bb8d5eed8e8 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 10 May 2019 09:10:25 -0400 Subject: [PATCH 04/80] don't apply rules --- .../SpiceBot_CommandsQuery/QueryCommand.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py b/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py index bd3dd48..bf1f735 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py +++ b/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py @@ -21,12 +21,13 @@ def query_detection(bot, trigger): commands_list = dict() for commandstype in bot.memory['SpiceBot_CommandsQuery']['commands'].keys(): - for com in bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype].keys(): - if com not in commands_list.keys(): - if commandstype == 'nickname': - commands_list[str(bot.nick) + " " + com] = bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype][com] - else: - commands_list[com] = bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype][com] + if commandstype != 'rule': + for com in bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype].keys(): + if com not in commands_list.keys(): + if commandstype == 'nickname': + commands_list[str(bot.nick) + " " + com] = bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype][com] + else: + commands_list[com] = bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype][com] triggerargsarray = spicemanip.main(trigger, 'create') From 6b88c28ebed2d7845789cc742d1dc068ef2570b6 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 10 May 2019 09:17:27 -0400 Subject: [PATCH 05/80] More AI development --- sopel_modules/SpiceBot_AI/AI.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sopel_modules/SpiceBot_AI/AI.py b/sopel_modules/SpiceBot_AI/AI.py index 682e1fa..ba91227 100644 --- a/sopel_modules/SpiceBot_AI/AI.py +++ b/sopel_modules/SpiceBot_AI/AI.py @@ -34,6 +34,16 @@ def bot_command_goodbye_b(bot, trigger): bot_command_goodbye(bot, trigger) +@sopel.module.rule(r'(?i)(thank|thanks) (you|),? $nickname[ \t]*$') +def bot_command_thanks(bot, trigger): + bot.reply("You're welcome.") + + +@sopel.module.rule('$nickname thank you', '$nickname thanks') +def bot_command_thanks_b(bot, trigger): + bot_command_thanks(bot, trigger) + + @sopel.module.rule('$nickname!') def exclaim(bot, trigger): bot.say(trigger.nick + '!') From e51d2ff3aef44d3a0d7ce4b47679261a8b700d0b Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 10 May 2019 09:38:07 -0400 Subject: [PATCH 06/80] Insert bot.kick method --- sopel_modules/SpiceBot_Kick/__init__.py | 97 +++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 sopel_modules/SpiceBot_Kick/__init__.py diff --git a/sopel_modules/SpiceBot_Kick/__init__.py b/sopel_modules/SpiceBot_Kick/__init__.py new file mode 100644 index 0000000..c752bd4 --- /dev/null +++ b/sopel_modules/SpiceBot_Kick/__init__.py @@ -0,0 +1,97 @@ +# coding=utf8 +"""Sopel Kick + +Sopel Kick is an easy way to kick users from channels +""" + +# pylama:ignore=W0611 + + +from __future__ import unicode_literals, absolute_import, division, print_function + +import sopel.bot +from sopel import tools, module +from sopel.tools import Identifier +from sopel.module import HALFOP +from sopel.config.types import StaticSection, ValidatedAttribute + +from sopel_modules.SpiceBot_SBTools import bot_logging + +import time +from collections import abc +import sys + + +__author__ = 'Sam Zick' +__email__ = 'sam@deathbybandaid.net' +__version__ = '0.1.2' + + +def configure(config): + config.define_section("MAXTARGCONFIG_KICK", MAXTARGCONFIG_KICK, validate=False) + config.MAXTARGCONFIG_KICK.configure_setting('kick', 'MAXTARG limit for KICK') + + +def setup(bot): + + # Inject KICK + bot_logging(bot, 'SpiceBot_Kick', "Implanting Kick function into bot") + bot.kick = SopelKICK.kick + sopel.bot.SopelWrapper.kick = SopelWrapperKICK.kick + + # verify config settings for server + bot_logging(bot, 'SpiceBot_Kick', "Checking for config settings") + bot.config.define_section("MAXTARGCONFIG_KICK", MAXTARGCONFIG_KICK, validate=False) + + +@module.event('005') +@module.rule('.*') +def parse_event_005(bot, trigger): + if trigger.args[-1] != 'are supported by this server': + return + parameters = trigger.args[1:-1] + for param in parameters: + if '=' in param: + if param.startswith("TARGMAX"): + param = str(param).split('=')[1] + settings = str(param).split(',') + for setting in settings: + settingname = str(setting).split(':')[0] + if settingname.upper() in ['KICK']: + try: + value = str(setting).split(':')[1] or None + except IndexError: + value = None + if value: + bot.config.MAXTARGCONFIG_KICK.kick = int(value) + + +class MAXTARGCONFIG_KICK(StaticSection): + kick = ValidatedAttribute('kick', default=1) + + +class SopelKICK: + + def kick(self, nick, channel, text=None): + """Send an IRC KICK command. + Within the context of a triggered callable, ``channel`` will default to the + channel in which the call was triggered. If triggered from a private message, + ``channel`` is required (or the call to ``kick()`` will be ignored). + The bot must be a channel operator in specified channel for this to work. + .. versionadded:: 7.0 + """ + if self.channels[channel].privileges[self.nick] < HALFOP: + self.write(['KICK', channel, nick], text) + + +class SopelWrapperKICK(object): + + def kick(self, nick, channel=None, message=None): + if channel is None: + if self._trigger.is_privmsg: + return + else: + channel = self._trigger.sender + if nick is None: + return + self._bot.kick(nick, channel, message) From 249877631c15e3169eb0f0d026770897491dc64a Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 10 May 2019 09:39:05 -0400 Subject: [PATCH 07/80] test thanks --- sopel_modules/SpiceBot_AI/AI.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_AI/AI.py b/sopel_modules/SpiceBot_AI/AI.py index ba91227..72cea37 100644 --- a/sopel_modules/SpiceBot_AI/AI.py +++ b/sopel_modules/SpiceBot_AI/AI.py @@ -34,7 +34,7 @@ def bot_command_goodbye_b(bot, trigger): bot_command_goodbye(bot, trigger) -@sopel.module.rule(r'(?i)(thank|thanks) (you|),? $nickname[ \t]*$') +@sopel.module.rule(r'(?i)(thank you|thanks),? $nickname[ \t]*$') def bot_command_thanks(bot, trigger): bot.reply("You're welcome.") From 1c0ce32496e9bb416c6e5a4bc5962d1b23c0cbce Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 10 May 2019 09:47:47 -0400 Subject: [PATCH 08/80] found the message bug --- sopel_modules/SpiceBot_Logs/Logs_Command.py | 2 +- sopel_modules/SpiceBot_osd/__init__.py | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/sopel_modules/SpiceBot_Logs/Logs_Command.py b/sopel_modules/SpiceBot_Logs/Logs_Command.py index 3014765..e1e1617 100644 --- a/sopel_modules/SpiceBot_Logs/Logs_Command.py +++ b/sopel_modules/SpiceBot_Logs/Logs_Command.py @@ -28,7 +28,7 @@ def bot_command_logs(bot, trigger): bot.osd("Current valid log(s) include: " + spicemanip.main(bot.memory['SpiceBot_Logs']["logs"].keys(), 'andlist'), trigger.sender, 'action') return - logtype = inlist_match(bot, logtype, bot.memory['SpiceBot_Logs'].keys()) + logtype = inlist_match(bot, logtype, bot.memory['SpiceBot_Logs']["logs"].keys()) if logtype == "Sopel_systemd": logindex = systemd_logs_fetch(bot) diff --git a/sopel_modules/SpiceBot_osd/__init__.py b/sopel_modules/SpiceBot_osd/__init__.py index 2ae82be..02bf978 100644 --- a/sopel_modules/SpiceBot_osd/__init__.py +++ b/sopel_modules/SpiceBot_osd/__init__.py @@ -385,11 +385,9 @@ class SopelWrapperOSD(object): recipients = self._trigger.sender self._bot.osd(self, messages, recipients, text_method, max_messages) - def msg(self, destination=None, message='', max_messages=1): - if destination is None: - destination = self._trigger.sender + def msg(self, destination, message, max_messages=1): self._bot.osd(self, message, destination, 'PRIVMSG', 1) - # self._bot.say(message, destination, max_messages) + # self._bot.msg(destination, message, max_messages) def say(self, message, destination=None, max_messages=1): if destination is None: From a0aa7076e3925420c05387c47154a0d29373d274 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 10 May 2019 09:50:12 -0400 Subject: [PATCH 09/80] rule only takes one argument --- sopel_modules/SpiceBot_AI/AI.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_AI/AI.py b/sopel_modules/SpiceBot_AI/AI.py index 72cea37..304080a 100644 --- a/sopel_modules/SpiceBot_AI/AI.py +++ b/sopel_modules/SpiceBot_AI/AI.py @@ -39,11 +39,16 @@ def bot_command_thanks(bot, trigger): bot.reply("You're welcome.") -@sopel.module.rule('$nickname thank you', '$nickname thanks') +@sopel.module.rule('$nickname thank you') def bot_command_thanks_b(bot, trigger): bot_command_thanks(bot, trigger) +@sopel.module.rule('$nickname thanks') +def bot_command_thanks_c(bot, trigger): + bot_command_thanks(bot, trigger) + + @sopel.module.rule('$nickname!') def exclaim(bot, trigger): bot.say(trigger.nick + '!') From d61db4b06b7a63a1fb2a7a2e623183ee5dc7f457 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 11 May 2019 09:33:48 -0400 Subject: [PATCH 10/80] Don't ever append an empty string --- sopel_modules/SpiceBot_osd/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot_osd/__init__.py b/sopel_modules/SpiceBot_osd/__init__.py index 02bf978..4b07083 100644 --- a/sopel_modules/SpiceBot_osd/__init__.py +++ b/sopel_modules/SpiceBot_osd/__init__.py @@ -192,11 +192,15 @@ class ToolsOSD: last_space = message.rfind(' ', 0, max_length) if last_space == -1: # No last space, just split where it is possible - text_list.append(message[:max_length]) + splitappend = message[:max_length] + if not splitappend.isspace(): + text_list.append(splitappend) message = message[max_length:] else: # Split at the last best space found - text_list.append(message[:last_space]) + splitappend = message[:last_space] + if not splitappend.isspace(): + text_list.append(splitappend) message = message[last_space:] if len(message.encode('utf-8')): text_list.append(message) From 31997b3c58272bacbdf8d3e279d9c431ea1b2830 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 11 May 2019 09:37:57 -0400 Subject: [PATCH 11/80] Verify message is not space --- sopel_modules/SpiceBot_osd/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot_osd/__init__.py b/sopel_modules/SpiceBot_osd/__init__.py index 4b07083..baa2b0e 100644 --- a/sopel_modules/SpiceBot_osd/__init__.py +++ b/sopel_modules/SpiceBot_osd/__init__.py @@ -188,7 +188,7 @@ class ToolsOSD: messages_list[-1] = messages_list[-1] + message_padding + message else: text_list = [] - while len(message.encode('utf-8')) > max_length: + while len(message.encode('utf-8')) > max_length and not message.isspace(): last_space = message.rfind(' ', 0, max_length) if last_space == -1: # No last space, just split where it is possible @@ -202,7 +202,7 @@ class ToolsOSD: if not splitappend.isspace(): text_list.append(splitappend) message = message[last_space:] - if len(message.encode('utf-8')): + if len(message.encode('utf-8')) and not message.isspace(): text_list.append(message) messages_list.extend(text_list) From 305cbf8f9d96a7b01e7cb69c804fa0999942488a Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 11 May 2019 09:37:10 -0400 Subject: [PATCH 12/80] Add AI Commit --- sopel_modules/SpiceBot_AI/AI.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_AI/AI.py b/sopel_modules/SpiceBot_AI/AI.py index 304080a..eda930e 100644 --- a/sopel_modules/SpiceBot_AI/AI.py +++ b/sopel_modules/SpiceBot_AI/AI.py @@ -44,7 +44,7 @@ def bot_command_thanks_b(bot, trigger): bot_command_thanks(bot, trigger) -@sopel.module.rule('$nickname thanks') +@sopel.module.nickname_commands('thanks') def bot_command_thanks_c(bot, trigger): bot_command_thanks(bot, trigger) From b1cf70e043fac51f1214b5923da334b2478a2776 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 11 May 2019 16:14:30 -0400 Subject: [PATCH 13/80] more verbose logic for text splitting --- sopel_modules/SpiceBot_osd/__init__.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/sopel_modules/SpiceBot_osd/__init__.py b/sopel_modules/SpiceBot_osd/__init__.py index baa2b0e..ce6dd3c 100644 --- a/sopel_modules/SpiceBot_osd/__init__.py +++ b/sopel_modules/SpiceBot_osd/__init__.py @@ -177,15 +177,14 @@ class ToolsOSD: if not isinstance(messages, list): messages = [messages] - messages_list = [''] + messages_list = [] message_padding = 4 * " " for message in messages: - if len((messages_list[-1] + message_padding + message).encode('utf-8')) <= max_length: - if messages_list[-1] == '': - messages_list[-1] = message - else: - messages_list[-1] = messages_list[-1] + message_padding + message + if not len(messages_list) and len(message.encode('utf-8')) <= max_length: + messages_list[-1] = message + elif len(messages_list) and len((messages_list[-1] + message_padding + message).encode('utf-8')) <= max_length: + messages_list[-1] = messages_list[-1] + message_padding + message else: text_list = [] while len(message.encode('utf-8')) > max_length and not message.isspace(): @@ -204,7 +203,13 @@ class ToolsOSD: message = message[last_space:] if len(message.encode('utf-8')) and not message.isspace(): text_list.append(message) - messages_list.extend(text_list) + for splitmsg in text_list: + if not len(messages_list) and len(splitmsg.encode('utf-8')) <= max_length: + messages_list[-1] = splitmsg + elif len(messages_list) and len((messages_list[-1] + message_padding + splitmsg).encode('utf-8')) <= max_length: + messages_list[-1] = messages_list[-1] + message_padding + splitmsg + else: + messages_list.append(splitmsg) return messages_list From 120dfec954a460aa5a01afa5809492cb0648b3c6 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 11 May 2019 16:39:07 -0400 Subject: [PATCH 14/80] Split AI functionality --- sopel_modules/SpiceBot_AI/AI.py | 64 ------------------- sopel_modules/SpiceBot_AI/AI_Acknowledge.py | 15 +++++ sopel_modules/SpiceBot_AI/AI_Goodbye.py | 19 ++++++ sopel_modules/SpiceBot_AI/AI_Hello.py | 19 ++++++ sopel_modules/SpiceBot_AI/AI_InsultHandler.py | 10 +++ sopel_modules/SpiceBot_AI/AI_Lazy.py | 15 +++++ sopel_modules/SpiceBot_AI/AI_Thanks.py | 20 ++++++ sopel_modules/SpiceBot_AI/__init__.py | 6 ++ 8 files changed, 104 insertions(+), 64 deletions(-) create mode 100644 sopel_modules/SpiceBot_AI/AI_Acknowledge.py create mode 100644 sopel_modules/SpiceBot_AI/AI_Goodbye.py create mode 100644 sopel_modules/SpiceBot_AI/AI_Hello.py create mode 100644 sopel_modules/SpiceBot_AI/AI_InsultHandler.py create mode 100644 sopel_modules/SpiceBot_AI/AI_Lazy.py create mode 100644 sopel_modules/SpiceBot_AI/AI_Thanks.py diff --git a/sopel_modules/SpiceBot_AI/AI.py b/sopel_modules/SpiceBot_AI/AI.py index eda930e..97adc03 100644 --- a/sopel_modules/SpiceBot_AI/AI.py +++ b/sopel_modules/SpiceBot_AI/AI.py @@ -10,70 +10,6 @@ from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, googlesearch, bot_ from sopel_modules.SpiceBot_Events.System import bot_events_check -@sopel.module.rule(r'(?i)(hi|hello|hey),? $nickname[ \t]*$') -def bot_command_hello(bot, trigger): - hello = spicemanip.main(['Hi', 'Hey', 'Hello'], "random") - punctuation = spicemanip.main(['', '!', '?'], "random") - bot.osd(hello + ' ' + trigger.nick + punctuation) - - -@sopel.module.nickname_commands('hello', 'hi', 'hey') -def bot_command_hello_b(bot, trigger): - bot_command_hello(bot, trigger) - - -@sopel.module.rule(r'(?i)(bye|goodbye|gtg|seeya|cya|ttyl|g2g|gnight|goodnight),? $nickname[ \t]*$') -def bot_command_goodbye(bot, trigger): - byemsg = spicemanip.main(['Bye', 'Goodbye', 'Seeya', 'Auf Wiedersehen', 'Au revoir', 'Ttyl'], "random") - punctuation = spicemanip.main(['!', ''], "random") - bot.say(byemsg + ' ' + trigger.nick + punctuation) - - -@sopel.module.nickname_commands("bye", "goodbye", "gtg", "seeya", "cya", "ttyl", "g2g", "gnight", "goodnight") -def bot_command_goodbye_b(bot, trigger): - bot_command_goodbye(bot, trigger) - - -@sopel.module.rule(r'(?i)(thank you|thanks),? $nickname[ \t]*$') -def bot_command_thanks(bot, trigger): - bot.reply("You're welcome.") - - -@sopel.module.rule('$nickname thank you') -def bot_command_thanks_b(bot, trigger): - bot_command_thanks(bot, trigger) - - -@sopel.module.nickname_commands('thanks') -def bot_command_thanks_c(bot, trigger): - bot_command_thanks(bot, trigger) - - -@sopel.module.rule('$nickname!') -def exclaim(bot, trigger): - bot.say(trigger.nick + '!') - - -@sopel.module.rule('$nickname\?') -def imhere(bot, trigger): - bot.say("I'm here, " + trigger.nick) - - -@sopel.module.rule(r'(?i)(Fuck|Screw) (you|off),? $nickname[ \t]*$') -def bot_command_srewyou(bot, trigger): - bot.osd("Watch your mouth, " + trigger.nick + ", or I'll tell your mother!") - - -@sopel.module.rule(r'(?i)(Damnit|Lazy)? $nickname[ \t]*$') -def bot_command_damnlazy(bot, trigger): - bot.osd("I do not tell you how to do your job, " + trigger.nick + "!!!") - - -@sopel.module.rule('$nickname is lazy') -def bot_command_damnlazy_b(bot, trigger): - bot.osd("I do not tell you how to do your job, " + trigger.nick + "!!!") - - @sopel.module.nickname_commands('(.*)') def bot_command_nick(bot, trigger): diff --git a/sopel_modules/SpiceBot_AI/AI_Acknowledge.py b/sopel_modules/SpiceBot_AI/AI_Acknowledge.py new file mode 100644 index 0000000..e9e626e --- /dev/null +++ b/sopel_modules/SpiceBot_AI/AI_Acknowledge.py @@ -0,0 +1,15 @@ +# coding=utf-8 + +from __future__ import unicode_literals, absolute_import, division, print_function + +import sopel.module + + +@sopel.module.rule('$nickname!') +def exclaim(bot, trigger): + bot.say(trigger.nick + '!') + + +@sopel.module.rule('$nickname\?') +def imhere(bot, trigger): + bot.say("I'm here, " + trigger.nick) diff --git a/sopel_modules/SpiceBot_AI/AI_Goodbye.py b/sopel_modules/SpiceBot_AI/AI_Goodbye.py new file mode 100644 index 0000000..7f93bef --- /dev/null +++ b/sopel_modules/SpiceBot_AI/AI_Goodbye.py @@ -0,0 +1,19 @@ +# coding=utf-8 + +from __future__ import unicode_literals, absolute_import, division, print_function + +import sopel.module + +import spicemanip + + +@sopel.module.rule(r'(?i)(bye|goodbye|gtg|seeya|cya|ttyl|g2g|gnight|goodnight),? $nickname[ \t]*$') +def bot_command_goodbye(bot, trigger): + byemsg = spicemanip.main(['Bye', 'Goodbye', 'Seeya', 'Auf Wiedersehen', 'Au revoir', 'Ttyl'], "random") + punctuation = spicemanip.main(['!', ''], "random") + bot.say(byemsg + ' ' + trigger.nick + punctuation) + + +@sopel.module.nickname_commands("bye", "goodbye", "gtg", "seeya", "cya", "ttyl", "g2g", "gnight", "goodnight") +def bot_command_goodbye_b(bot, trigger): + bot_command_goodbye(bot, trigger) diff --git a/sopel_modules/SpiceBot_AI/AI_Hello.py b/sopel_modules/SpiceBot_AI/AI_Hello.py new file mode 100644 index 0000000..ee30964 --- /dev/null +++ b/sopel_modules/SpiceBot_AI/AI_Hello.py @@ -0,0 +1,19 @@ +# coding=utf-8 + +from __future__ import unicode_literals, absolute_import, division, print_function + +import sopel.module + +import spicemanip + + +@sopel.module.rule(r'(?i)(hi|hello|hey),? $nickname[ \t]*$') +def bot_command_hello(bot, trigger): + hello = spicemanip.main(['Hi', 'Hey', 'Hello'], "random") + punctuation = spicemanip.main(['', '!', '?'], "random") + bot.osd(hello + ' ' + trigger.nick + punctuation) + + +@sopel.module.nickname_commands('hello', 'hi', 'hey') +def bot_command_hello_b(bot, trigger): + bot_command_hello(bot, trigger) diff --git a/sopel_modules/SpiceBot_AI/AI_InsultHandler.py b/sopel_modules/SpiceBot_AI/AI_InsultHandler.py new file mode 100644 index 0000000..910dd7b --- /dev/null +++ b/sopel_modules/SpiceBot_AI/AI_InsultHandler.py @@ -0,0 +1,10 @@ +# coding=utf-8 + +from __future__ import unicode_literals, absolute_import, division, print_function + +import sopel.module + + +@sopel.module.rule(r'(?i)(Fuck|Screw) (you|off),? $nickname[ \t]*$') +def bot_command_srewyou(bot, trigger): + bot.osd("Watch your mouth, " + trigger.nick + ", or I'll tell your mother!") diff --git a/sopel_modules/SpiceBot_AI/AI_Lazy.py b/sopel_modules/SpiceBot_AI/AI_Lazy.py new file mode 100644 index 0000000..a3385a6 --- /dev/null +++ b/sopel_modules/SpiceBot_AI/AI_Lazy.py @@ -0,0 +1,15 @@ +# coding=utf-8 + +from __future__ import unicode_literals, absolute_import, division, print_function + +import sopel.module + + +@sopel.module.rule(r'(?i)(Damnit|Lazy)? $nickname[ \t]*$') +def bot_command_damnlazy(bot, trigger): + bot.osd("I do not tell you how to do your job, " + trigger.nick + "!!!") + + +@sopel.module.rule('$nickname is lazy') +def bot_command_damnlazy_b(bot, trigger): + bot_command_damnlazy(bot, trigger) diff --git a/sopel_modules/SpiceBot_AI/AI_Thanks.py b/sopel_modules/SpiceBot_AI/AI_Thanks.py new file mode 100644 index 0000000..01f21d1 --- /dev/null +++ b/sopel_modules/SpiceBot_AI/AI_Thanks.py @@ -0,0 +1,20 @@ +# coding=utf-8 + +from __future__ import unicode_literals, absolute_import, division, print_function + +import sopel.module + + +@sopel.module.rule(r'(?i)(thank you|thanks),? $nickname[ \t]*$') +def bot_command_thanks(bot, trigger): + bot.reply("You're welcome.") + + +@sopel.module.rule('$nickname thank you') +def bot_command_thanks_b(bot, trigger): + bot_command_thanks(bot, trigger) + + +@sopel.module.nickname_commands('thanks') +def bot_command_thanks_c(bot, trigger): + bot_command_thanks(bot, trigger) diff --git a/sopel_modules/SpiceBot_AI/__init__.py b/sopel_modules/SpiceBot_AI/__init__.py index b1447b6..ba6da7a 100644 --- a/sopel_modules/SpiceBot_AI/__init__.py +++ b/sopel_modules/SpiceBot_AI/__init__.py @@ -2,6 +2,12 @@ from __future__ import unicode_literals, absolute_import, division, print_function from .AI import * +from .AI_Hello import * +from .AI_Goodbye import * +from .AI_Thanks import * +from .AI_Acknowledge import * +from .AI_Lazy import * +from .AI_InsultHandler import * __author__ = 'Sam Zick' __email__ = 'sam@deathbybandaid.net' From 26022a2a2cb864e3506595fd20fbb718ab663afc Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 11 May 2019 16:46:34 -0400 Subject: [PATCH 15/80] Adjust osd logic --- sopel_modules/SpiceBot_AI/AI_Ping.py | 15 +++++++++++++++ sopel_modules/SpiceBot_AI/__init__.py | 1 + sopel_modules/SpiceBot_osd/__init__.py | 5 ----- 3 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 sopel_modules/SpiceBot_AI/AI_Ping.py diff --git a/sopel_modules/SpiceBot_AI/AI_Ping.py b/sopel_modules/SpiceBot_AI/AI_Ping.py new file mode 100644 index 0000000..4931797 --- /dev/null +++ b/sopel_modules/SpiceBot_AI/AI_Ping.py @@ -0,0 +1,15 @@ +# coding=utf-8 + +from __future__ import unicode_literals, absolute_import, division, print_function + +import sopel.module + + +@sopel.module.rule(r'(?i)(ping),? $nickname[ \t]*$') +def bot_command_ping(bot, trigger): + bot.say("Pong") + + +@sopel.module.nickname_commands('ping') +def bot_command_ping_b(bot, trigger): + bot_command_ping(bot, trigger) diff --git a/sopel_modules/SpiceBot_AI/__init__.py b/sopel_modules/SpiceBot_AI/__init__.py index ba6da7a..18cca3e 100644 --- a/sopel_modules/SpiceBot_AI/__init__.py +++ b/sopel_modules/SpiceBot_AI/__init__.py @@ -8,6 +8,7 @@ from .AI_Thanks import * from .AI_Acknowledge import * from .AI_Lazy import * from .AI_InsultHandler import * +from .AI_Ping import * __author__ = 'Sam Zick' __email__ = 'sam@deathbybandaid.net' diff --git a/sopel_modules/SpiceBot_osd/__init__.py b/sopel_modules/SpiceBot_osd/__init__.py index ce6dd3c..d4929a4 100644 --- a/sopel_modules/SpiceBot_osd/__init__.py +++ b/sopel_modules/SpiceBot_osd/__init__.py @@ -54,7 +54,6 @@ def setup(bot): sopel.bot.SopelWrapper.action = SopelWrapperOSD.action sopel.bot.SopelWrapper.notice = SopelWrapperOSD.notice sopel.bot.SopelWrapper.reply = SopelWrapperOSD.reply - sopel.bot.SopelWrapper.msg = SopelWrapperOSD.msg # verify config settings for server bot_logging(bot, 'SpiceBot_OSD', "Checking for config settings") @@ -394,10 +393,6 @@ class SopelWrapperOSD(object): recipients = self._trigger.sender self._bot.osd(self, messages, recipients, text_method, max_messages) - def msg(self, destination, message, max_messages=1): - self._bot.osd(self, message, destination, 'PRIVMSG', 1) - # self._bot.msg(destination, message, max_messages) - def say(self, message, destination=None, max_messages=1): if destination is None: destination = self._trigger.sender From 39515b4365988b61c20324ed502563a8f288a291 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 11 May 2019 16:51:20 -0400 Subject: [PATCH 16/80] revert osd logic --- sopel_modules/SpiceBot_osd/__init__.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/sopel_modules/SpiceBot_osd/__init__.py b/sopel_modules/SpiceBot_osd/__init__.py index d4929a4..7bd3142 100644 --- a/sopel_modules/SpiceBot_osd/__init__.py +++ b/sopel_modules/SpiceBot_osd/__init__.py @@ -176,14 +176,15 @@ class ToolsOSD: if not isinstance(messages, list): messages = [messages] - messages_list = [] + messages_list = [''] message_padding = 4 * " " for message in messages: - if not len(messages_list) and len(message.encode('utf-8')) <= max_length: - messages_list[-1] = message - elif len(messages_list) and len((messages_list[-1] + message_padding + message).encode('utf-8')) <= max_length: - messages_list[-1] = messages_list[-1] + message_padding + message + if len((messages_list[-1] + message_padding + message).encode('utf-8')) <= max_length: + if messages_list[-1] == '': + messages_list[-1] = message + else: + messages_list[-1] = messages_list[-1] + message_padding + message else: text_list = [] while len(message.encode('utf-8')) > max_length and not message.isspace(): @@ -202,13 +203,7 @@ class ToolsOSD: message = message[last_space:] if len(message.encode('utf-8')) and not message.isspace(): text_list.append(message) - for splitmsg in text_list: - if not len(messages_list) and len(splitmsg.encode('utf-8')) <= max_length: - messages_list[-1] = splitmsg - elif len(messages_list) and len((messages_list[-1] + message_padding + splitmsg).encode('utf-8')) <= max_length: - messages_list[-1] = messages_list[-1] + message_padding + splitmsg - else: - messages_list.append(splitmsg) + messages_list.extend(text_list) return messages_list From e013aebda44bec6282713523a14b27f117d15e5c Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 11 May 2019 16:59:05 -0400 Subject: [PATCH 17/80] parenthethis --- sopel_modules/SpiceBot_AI/AI_Thanks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_AI/AI_Thanks.py b/sopel_modules/SpiceBot_AI/AI_Thanks.py index 01f21d1..be80f7f 100644 --- a/sopel_modules/SpiceBot_AI/AI_Thanks.py +++ b/sopel_modules/SpiceBot_AI/AI_Thanks.py @@ -10,7 +10,7 @@ def bot_command_thanks(bot, trigger): bot.reply("You're welcome.") -@sopel.module.rule('$nickname thank you') +@sopel.module.rule('$nickname (thank you)') def bot_command_thanks_b(bot, trigger): bot_command_thanks(bot, trigger) From 6f7989889e41e5bfca94a59dabbfc64367e1fb7a Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 11 May 2019 17:02:16 -0400 Subject: [PATCH 18/80] true love --- sopel_modules/SpiceBot_AI/AI_Love.py | 20 ++++++++++++++++++++ sopel_modules/SpiceBot_AI/__init__.py | 1 + 2 files changed, 21 insertions(+) create mode 100644 sopel_modules/SpiceBot_AI/AI_Love.py diff --git a/sopel_modules/SpiceBot_AI/AI_Love.py b/sopel_modules/SpiceBot_AI/AI_Love.py new file mode 100644 index 0000000..66cd4f3 --- /dev/null +++ b/sopel_modules/SpiceBot_AI/AI_Love.py @@ -0,0 +1,20 @@ +# coding=utf-8 + +from __future__ import unicode_literals, absolute_import, division, print_function + +import sopel.module + + +@sopel.module.rule(r'(?i)(I love you|loveya),? $nickname[ \t]*$') +def bot_command_love(bot, trigger): + bot.reply("You're welcome.") + + +@sopel.module.rule('$nickname (loveya|I love you)') +def bot_command_love_b(bot, trigger): + bot_command_love(bot, trigger) + + +@sopel.module.nickname_commands('loveya') +def bot_command_love_c(bot, trigger): + bot_command_love(bot, trigger) diff --git a/sopel_modules/SpiceBot_AI/__init__.py b/sopel_modules/SpiceBot_AI/__init__.py index 18cca3e..93aecc7 100644 --- a/sopel_modules/SpiceBot_AI/__init__.py +++ b/sopel_modules/SpiceBot_AI/__init__.py @@ -9,6 +9,7 @@ from .AI_Acknowledge import * from .AI_Lazy import * from .AI_InsultHandler import * from .AI_Ping import * +from .AI_Love import * __author__ = 'Sam Zick' __email__ = 'sam@deathbybandaid.net' From 12f24d1e4b4330782a0bb1eabc5961c4276f5d3f Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 11 May 2019 17:02:42 -0400 Subject: [PATCH 19/80] fix response --- sopel_modules/SpiceBot_AI/AI_Love.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_AI/AI_Love.py b/sopel_modules/SpiceBot_AI/AI_Love.py index 66cd4f3..7c9a367 100644 --- a/sopel_modules/SpiceBot_AI/AI_Love.py +++ b/sopel_modules/SpiceBot_AI/AI_Love.py @@ -7,7 +7,7 @@ import sopel.module @sopel.module.rule(r'(?i)(I love you|loveya),? $nickname[ \t]*$') def bot_command_love(bot, trigger): - bot.reply("You're welcome.") + bot.reply("I love you too.") @sopel.module.rule('$nickname (loveya|I love you)') From ecca6495b5c4cca9235cb1135fdb697fd0b7ffc6 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 11 May 2019 17:04:02 -0400 Subject: [PATCH 20/80] add like --- sopel_modules/SpiceBot_AI/AI_Love.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sopel_modules/SpiceBot_AI/AI_Love.py b/sopel_modules/SpiceBot_AI/AI_Love.py index 7c9a367..4693e2b 100644 --- a/sopel_modules/SpiceBot_AI/AI_Love.py +++ b/sopel_modules/SpiceBot_AI/AI_Love.py @@ -18,3 +18,13 @@ def bot_command_love_b(bot, trigger): @sopel.module.nickname_commands('loveya') def bot_command_love_c(bot, trigger): bot_command_love(bot, trigger) + + +@sopel.module.rule(r'(?i)(I like you),? $nickname[ \t]*$') +def bot_command_like(bot, trigger): + bot.reply("I like you too.") + + +@sopel.module.rule('$nickname (I like you)') +def bot_command_like_b(bot, trigger): + bot_command_like(bot, trigger) From e6025b16e53c3605f29632ad465db31f629e8c50 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 11 May 2019 17:06:15 -0400 Subject: [PATCH 21/80] one more step --- sopel_modules/SpiceBot_AI/AI_Love.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sopel_modules/SpiceBot_AI/AI_Love.py b/sopel_modules/SpiceBot_AI/AI_Love.py index 4693e2b..8674317 100644 --- a/sopel_modules/SpiceBot_AI/AI_Love.py +++ b/sopel_modules/SpiceBot_AI/AI_Love.py @@ -20,6 +20,11 @@ def bot_command_love_c(bot, trigger): bot_command_love(bot, trigger) +@sopel.module.rule('(I love) $nickname') +def bot_command_love_d(bot, trigger): + bot_command_like(bot, trigger) + + @sopel.module.rule(r'(?i)(I like you),? $nickname[ \t]*$') def bot_command_like(bot, trigger): bot.reply("I like you too.") @@ -28,3 +33,8 @@ def bot_command_like(bot, trigger): @sopel.module.rule('$nickname (I like you)') def bot_command_like_b(bot, trigger): bot_command_like(bot, trigger) + + +@sopel.module.rule('(I like) $nickname') +def bot_command_like_c(bot, trigger): + bot_command_like(bot, trigger) From ba3bd5b3660de18407a872271bdefcd0eb2e637f Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 13 May 2019 07:48:27 -0400 Subject: [PATCH 22/80] debug test --- sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py b/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py index bf1f735..6bbbc64 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py +++ b/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py @@ -79,6 +79,7 @@ def query_detection(bot, trigger): return elif not querycommand: + bot.say("no query command") return else: From 1471bdac0cd761b92fea29c2000928a93aaa7d38 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 13 May 2019 10:08:37 -0400 Subject: [PATCH 23/80] attempt reversion --- Installation Files/requirements-os.sh | 3 +++ .../SpiceBot_CommandsQuery/QueryCommand.py | 15 +++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Installation Files/requirements-os.sh b/Installation Files/requirements-os.sh index 31f9763..0df25d2 100644 --- a/Installation Files/requirements-os.sh +++ b/Installation Files/requirements-os.sh @@ -39,6 +39,9 @@ mkdir /run/sopel echo $$ > /run/sopel/sopel-SpiceBotSERV.pid chmod -R 777 /run/sopel/ +apt install mysql-server libmysqlclient-dev -y +pip3 install mysql + cp /home/sopel/SpiceBot/System-Files/Config/SpiceBot.cfg /home/sopel/SpiceBot.cfg cp /home/sopel/SpiceBot/System-Files/systemd/SpiceBot.service /lib/systemd/system/SpiceBot.service diff --git a/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py b/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py index 6bbbc64..f8da999 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py +++ b/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py @@ -21,13 +21,13 @@ def query_detection(bot, trigger): commands_list = dict() for commandstype in bot.memory['SpiceBot_CommandsQuery']['commands'].keys(): - if commandstype != 'rule': - for com in bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype].keys(): - if com not in commands_list.keys(): - if commandstype == 'nickname': - commands_list[str(bot.nick) + " " + com] = bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype][com] - else: - commands_list[com] = bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype][com] + # if commandstype != 'rule': + for com in bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype].keys(): + if com not in commands_list.keys(): + if commandstype == 'nickname': + commands_list[str(bot.nick) + " " + com] = bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype][com] + else: + commands_list[com] = bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype][com] triggerargsarray = spicemanip.main(trigger, 'create') @@ -79,7 +79,6 @@ def query_detection(bot, trigger): return elif not querycommand: - bot.say("no query command") return else: From ff7ed67bbabd6245288b7cc9a35ac323501d9233 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 13 May 2019 10:17:21 -0400 Subject: [PATCH 24/80] debug --- .../SpiceBot_CommandsQuery/QueryCommand.py | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py b/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py index f8da999..727783e 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py +++ b/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py @@ -21,18 +21,23 @@ def query_detection(bot, trigger): commands_list = dict() for commandstype in bot.memory['SpiceBot_CommandsQuery']['commands'].keys(): - # if commandstype != 'rule': - for com in bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype].keys(): - if com not in commands_list.keys(): - if commandstype == 'nickname': - commands_list[str(bot.nick) + " " + com] = bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype][com] - else: - commands_list[com] = bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype][com] + if commandstype != 'rule': + for com in bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype].keys(): + if com not in commands_list.keys(): + if commandstype == 'nickname': + commands_list[str(bot.nick) + " " + com] = bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype][com] + else: + commands_list[com] = bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype][com] triggerargsarray = spicemanip.main(trigger, 'create') # command issued, check if valid - querycommand = spicemanip.main(triggerargsarray, 1).lower()[1:] + querycommand = spicemanip.main(triggerargsarray, 1).lower()[1:] or None + if not querycommand: + return + bot.say(str(querycommand)) + bot.say("no querycommand") + if len(querycommand) == 1: commandlist = [] for command in commands_list.keys(): @@ -45,7 +50,7 @@ def query_detection(bot, trigger): bot.notice("The following commands match " + str(querycommand) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick) return - elif querycommand.endswith(tuple(["+"])): + elif querycommand.endswith("+"): querycommand = querycommand[:-1] if querycommand not in commands_list.keys(): bot.notice("The " + str(querycommand) + " does not appear to be valid.") @@ -57,7 +62,7 @@ def query_detection(bot, trigger): bot.notice("The following commands match " + str(querycommand) + ": " + spicemanip.main(validcomlist, 'andlist') + ".", trigger.nick) return - elif querycommand.endswith(tuple(['?'])): + elif querycommand.endswith('?'): querycommand = querycommand[:-1] sim_com, sim_num = [], [] for com in commands_list.keys(): @@ -78,9 +83,6 @@ def query_detection(bot, trigger): bot.notice("The following commands match " + str(querycommand) + ": " + str(querycommand) + ".", trigger.nick) return - elif not querycommand: - return - else: commandlist = [] for command in commands_list.keys(): From 85af5aa89df3fdc0b49758fecaac2c2a1944d1f1 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 13 May 2019 10:31:51 -0400 Subject: [PATCH 25/80] debug coding --- .../SpiceBot_CommandsQuery/CommandsQuery.py | 21 +++++++++++++++++-- .../SpiceBot_CommandsQuery/QueryCommand.py | 16 +++++++------- sopel_modules/SpiceBot_SBTools/__init__.py | 3 +++ 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py index 548d746..51b4d10 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py +++ b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py @@ -18,7 +18,7 @@ def setup(bot): bot_events_startup_register(bot, ['2002']) if 'SpiceBot_CommandsQuery' not in bot.memory: - bot.memory['SpiceBot_CommandsQuery'] = {"counts": 0, "commands": {}, "nickrules": []} + bot.memory['SpiceBot_CommandsQuery'] = {"counts": 0, 'commands_all': {}, "commands": {}, "nickrules": []} for comtype in ['module', 'nickname', 'rule']: if comtype not in bot.memory['SpiceBot_CommandsQuery']['commands'].keys(): @@ -152,6 +152,15 @@ def setup(bot): if command not in bot.memory['SpiceBot_CommandsQuery']['nickrules']: bot.memory['SpiceBot_CommandsQuery']['nickrules'].append(command) + for commandstype in bot.memory['SpiceBot_CommandsQuery']['commands'].keys(): + if commandstype != 'rule': + for com in bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype].keys(): + if com not in bot.memory['SpiceBot_CommandsQuery']['commands_all'].keys(): + if commandstype == 'nickname': + bot.memory['SpiceBot_CommandsQuery']['commands_all'][str(bot.nick) + " " + com] = bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype][com] + else: + bot.memory['SpiceBot_CommandsQuery']['commands_all'][com] = bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype][com] + bot_events_trigger(bot, 2002, "SpiceBot_CommandsQuery") @@ -173,7 +182,7 @@ def bot_events_complete(bot, trigger): def commandsquery_register(bot, command_type, validcoms, aliasfor=None): if 'SpiceBot_CommandsQuery' not in bot.memory: - bot.memory['SpiceBot_CommandsQuery'] = {"counts": 0, "commands": {}, "nickrules": []} + bot.memory['SpiceBot_CommandsQuery'] = {"counts": 0, 'commands_all': {}, "commands": {}, "nickrules": []} if not isinstance(validcoms, list): validcoms = [validcoms] @@ -203,6 +212,14 @@ def commandsquery_register(bot, command_type, validcoms, aliasfor=None): if comalias not in bot.memory['SpiceBot_CommandsQuery']['commands'][command_type].keys(): bot.memory['SpiceBot_CommandsQuery']['commands'][command_type][comalias] = {"aliasfor": aliasfor} + for comalias in comaliases: + if command_type != 'rule': + if comalias not in bot.memory['SpiceBot_CommandsQuery']['commands_all'].keys(): + if command_type == 'nickname': + bot.memory['SpiceBot_CommandsQuery']['commands_all'][str(bot.nick) + " " + comalias] = bot.memory['SpiceBot_CommandsQuery']['commands'][command_type][comalias] + else: + bot.memory['SpiceBot_CommandsQuery']['commands_all'][comalias] = bot.memory['SpiceBot_CommandsQuery']['commands'][command_type][comalias] + @sopel.module.event('2002') @sopel.module.rule('.*') diff --git a/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py b/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py index 727783e..ed3cefd 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py +++ b/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py @@ -9,6 +9,8 @@ from difflib import SequenceMatcher from operator import itemgetter from sopel_modules.SpiceBot_Events.System import bot_events_check +from sopel_modules.SpiceBot_SBTools import sopel_triggerargs + import spicemanip @@ -19,15 +21,11 @@ def query_detection(bot, trigger): while not bot_events_check(bot, '2002'): pass - commands_list = dict() - for commandstype in bot.memory['SpiceBot_CommandsQuery']['commands'].keys(): - if commandstype != 'rule': - for com in bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype].keys(): - if com not in commands_list.keys(): - if commandstype == 'nickname': - commands_list[str(bot.nick) + " " + com] = bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype][com] - else: - commands_list[com] = bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype][com] + commands_list = bot.memory['SpiceBot_CommandsQuery']['commands_all'] + + triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'query_command') + bot.say(str(triggerargs)) + bot.say(str(triggercommand)) triggerargsarray = spicemanip.main(trigger, 'create') diff --git a/sopel_modules/SpiceBot_SBTools/__init__.py b/sopel_modules/SpiceBot_SBTools/__init__.py index fb4054b..22d5ea6 100644 --- a/sopel_modules/SpiceBot_SBTools/__init__.py +++ b/sopel_modules/SpiceBot_SBTools/__init__.py @@ -47,6 +47,9 @@ def sopel_triggerargs(bot, trigger, command_type='module_command'): if command_type in ['nickname_command']: command = spicemanip.main(triggerargs, 2).lower() triggerargs = spicemanip.main(triggerargs, '3+', 'list') + elif command_type in ['query_command']: + command = spicemanip.main(triggerargs, 1).lower()[1:] + triggerargs = spicemanip.main(triggerargs, '2+', 'list') else: command = spicemanip.main(triggerargs, 1).lower()[1:] triggerargs = spicemanip.main(triggerargs, '2+', 'list') From 15cda51e72cde60e5dc8127c8c9015ee3f18046a Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 13 May 2019 10:42:45 -0400 Subject: [PATCH 26/80] kill db addons --- sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py b/sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py index 7c07129..7977fe7 100644 --- a/sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py +++ b/sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py @@ -12,6 +12,7 @@ import json def setup(bot): + pass # Inject Database Functions bot_logging(bot, 'SpiceBot_Databaseaddons', "Implanting Database functions into bot") SopelDB.reset_nick_value = SopelDBCache.reset_nick_value From 73a75b33470135661abe030ce6ba2ec6d815c94c Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 13 May 2019 10:50:48 -0400 Subject: [PATCH 27/80] Loggind updates --- sopel_modules/SpiceBot_Logs/ErrorDisplay.py | 5 +++++ .../SpiceBot_StartupMonologue/StartupMonologue_Display.py | 1 + 2 files changed, 6 insertions(+) diff --git a/sopel_modules/SpiceBot_Logs/ErrorDisplay.py b/sopel_modules/SpiceBot_Logs/ErrorDisplay.py index 39e50a3..c89f04b 100644 --- a/sopel_modules/SpiceBot_Logs/ErrorDisplay.py +++ b/sopel_modules/SpiceBot_Logs/ErrorDisplay.py @@ -5,6 +5,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel.module from sopel_modules.SpiceBot_Events.System import bot_events_recieved +from sopel_modules.SpiceBot_SBTools import bot_logging from .Logs import stdio_logs_fetch @@ -25,6 +26,10 @@ def bot_startup_monologue_start(bot, trigger): searchphrasefound.append(str(searchphrase) + " dict file(s) failed") if len(searchphrasefound): + for foundphase in searchphrasefound: + bot_logging(bot, 'SpiceBot_Logs', str(foundphase)) searchphrasefound.insert(0, "Notice to Bot Admins: ") searchphrasefound.append("Run the debug command for more information.") bot.osd(searchphrasefound, bot.channels.keys()) + else: + bot_logging(bot, 'SpiceBot_Logs', "No issues found at bot startup!") diff --git a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py index 6f1310c..80e8f9f 100644 --- a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py +++ b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py @@ -64,3 +64,4 @@ def bot_startup_monologue_display(bot, trigger): bot.osd(bot.memory['SpiceBot_StartupMonologue'], bot.channels.keys(), 'ACTION') bot_events_trigger(bot, 2005, "SpiceBot_StartupMonologue") + bot_logging(bot, 'SpiceBot_StartupMonologue', "Startup Monologue has been issued to all channels.") From 6a2633d3831967f688362a6b9bc9363602d2cb8b Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 13 May 2019 10:56:35 -0400 Subject: [PATCH 28/80] query command processing changes --- .../SpiceBot_CommandsQuery/QueryCommand.py | 53 +++++++++---------- sopel_modules/SpiceBot_SBTools/__init__.py | 3 -- 2 files changed, 24 insertions(+), 32 deletions(-) diff --git a/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py b/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py index ed3cefd..c1f18a9 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py +++ b/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py @@ -24,47 +24,42 @@ def query_detection(bot, trigger): commands_list = bot.memory['SpiceBot_CommandsQuery']['commands_all'] triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'query_command') - bot.say(str(triggerargs)) - bot.say(str(triggercommand)) - - triggerargsarray = spicemanip.main(trigger, 'create') # command issued, check if valid - querycommand = spicemanip.main(triggerargsarray, 1).lower()[1:] or None - if not querycommand: + if not triggercommand: return - bot.say(str(querycommand)) - bot.say("no querycommand") + bot.say("no triggercommand") + bot.say(str(triggercommand)) - if len(querycommand) == 1: + if len(triggercommand) == 1: commandlist = [] for command in commands_list.keys(): - if command.lower().startswith(querycommand): + if command.lower().startswith(triggercommand): commandlist.append(command) if commandlist == []: - bot.notice("No commands match " + str(querycommand) + ".", trigger.nick) + bot.notice("No commands match " + str(triggercommand) + ".", trigger.nick) return else: - bot.notice("The following commands match " + str(querycommand) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick) + bot.notice("The following commands match " + str(triggercommand) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick) return - elif querycommand.endswith("+"): - querycommand = querycommand[:-1] - if querycommand not in commands_list.keys(): - bot.notice("The " + str(querycommand) + " does not appear to be valid.") + elif triggercommand.endswith("+"): + triggercommand = triggercommand[:-1] + if triggercommand not in commands_list.keys(): + bot.notice("The " + str(triggercommand) + " does not appear to be valid.") return - realcom = querycommand - if "aliasfor" in commands_list[querycommand].keys(): - realcom = commands_list[querycommand]["aliasfor"] + realcom = triggercommand + if "aliasfor" in commands_list[triggercommand].keys(): + realcom = commands_list[triggercommand]["aliasfor"] validcomlist = commands_list[realcom]["validcoms"] - bot.notice("The following commands match " + str(querycommand) + ": " + spicemanip.main(validcomlist, 'andlist') + ".", trigger.nick) + bot.notice("The following commands match " + str(triggercommand) + ": " + spicemanip.main(validcomlist, 'andlist') + ".", trigger.nick) return - elif querycommand.endswith('?'): - querycommand = querycommand[:-1] + elif triggercommand.endswith('?'): + triggercommand = triggercommand[:-1] sim_com, sim_num = [], [] for com in commands_list.keys(): - similarlevel = SequenceMatcher(None, querycommand.lower(), com.lower()).ratio() + similarlevel = SequenceMatcher(None, triggercommand.lower(), com.lower()).ratio() sim_com.append(com) sim_num.append(similarlevel) sim_num, sim_com = (list(x) for x in zip(*sorted(zip(sim_num, sim_com), key=itemgetter(0)))) @@ -74,21 +69,21 @@ def query_detection(bot, trigger): if listnumb <= 10: relist.append(str(item)) listnumb += 1 - bot.notice("The following commands may match " + str(querycommand) + ": " + spicemanip.main(relist, 'andlist') + ".", trigger.nick) + bot.notice("The following commands may match " + str(triggercommand) + ": " + spicemanip.main(relist, 'andlist') + ".", trigger.nick) return - elif querycommand in commands_list.keys(): - bot.notice("The following commands match " + str(querycommand) + ": " + str(querycommand) + ".", trigger.nick) + elif triggercommand in commands_list.keys(): + bot.notice("The following commands match " + str(triggercommand) + ": " + str(triggercommand) + ".", trigger.nick) return else: commandlist = [] for command in commands_list.keys(): - if command.lower().startswith(querycommand): + if command.lower().startswith(triggercommand): commandlist.append(command) if commandlist == []: - bot.notice("No commands match " + str(querycommand) + ".", trigger.nick) + bot.notice("No commands match " + str(triggercommand) + ".", trigger.nick) return else: - bot.notice("The following commands match " + str(querycommand) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick) + bot.notice("The following commands match " + str(triggercommand) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick) return diff --git a/sopel_modules/SpiceBot_SBTools/__init__.py b/sopel_modules/SpiceBot_SBTools/__init__.py index 22d5ea6..fb4054b 100644 --- a/sopel_modules/SpiceBot_SBTools/__init__.py +++ b/sopel_modules/SpiceBot_SBTools/__init__.py @@ -47,9 +47,6 @@ def sopel_triggerargs(bot, trigger, command_type='module_command'): if command_type in ['nickname_command']: command = spicemanip.main(triggerargs, 2).lower() triggerargs = spicemanip.main(triggerargs, '3+', 'list') - elif command_type in ['query_command']: - command = spicemanip.main(triggerargs, 1).lower()[1:] - triggerargs = spicemanip.main(triggerargs, '2+', 'list') else: command = spicemanip.main(triggerargs, 1).lower()[1:] triggerargs = spicemanip.main(triggerargs, '2+', 'list') From 42924f645bdada8ad5076d7e8ac6868d4ffc4dbf Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 13 May 2019 11:48:25 -0400 Subject: [PATCH 29/80] code cleanup --- .../SpiceBot_CommandsQuery/QueryCommand.py | 95 ++++++++----------- .../SpiceBot_Database_Tools/DatabaseTools.py | 2 +- sopel_modules/SpiceBot_GifSearch/gif.py | 2 +- sopel_modules/SpiceBot_GifSearch/gifapi.py | 2 +- sopel_modules/SpiceBot_GifSearch/gifsearch.py | 10 +- sopel_modules/SpiceBot_SBTools/__init__.py | 13 ++- 6 files changed, 55 insertions(+), 69 deletions(-) diff --git a/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py b/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py index c1f18a9..b778530 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py +++ b/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py @@ -5,11 +5,8 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel import sopel.module -from difflib import SequenceMatcher -from operator import itemgetter - from sopel_modules.SpiceBot_Events.System import bot_events_check -from sopel_modules.SpiceBot_SBTools import sopel_triggerargs +from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, similar_list, letters_in_string import spicemanip @@ -26,64 +23,46 @@ def query_detection(bot, trigger): triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'query_command') # command issued, check if valid - if not triggercommand: + if not triggercommand or not len(triggercommand): return - bot.say("no triggercommand") - bot.say(str(triggercommand)) - if len(triggercommand) == 1: - commandlist = [] - for command in commands_list.keys(): - if command.lower().startswith(triggercommand): - commandlist.append(command) - if commandlist == []: - bot.notice("No commands match " + str(triggercommand) + ".", trigger.nick) - return - else: - bot.notice("The following commands match " + str(triggercommand) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick) - return + if not letters_in_string(triggercommand): + return - elif triggercommand.endswith("+"): + if triggercommand.endswith("+"): triggercommand = triggercommand[:-1] + if not triggercommand or not len(triggercommand): + return if triggercommand not in commands_list.keys(): - bot.notice("The " + str(triggercommand) + " does not appear to be valid.") - return - realcom = triggercommand - if "aliasfor" in commands_list[triggercommand].keys(): - realcom = commands_list[triggercommand]["aliasfor"] - validcomlist = commands_list[realcom]["validcoms"] - bot.notice("The following commands match " + str(triggercommand) + ": " + spicemanip.main(validcomlist, 'andlist') + ".", trigger.nick) - return - - elif triggercommand.endswith('?'): - triggercommand = triggercommand[:-1] - sim_com, sim_num = [], [] - for com in commands_list.keys(): - similarlevel = SequenceMatcher(None, triggercommand.lower(), com.lower()).ratio() - sim_com.append(com) - sim_num.append(similarlevel) - sim_num, sim_com = (list(x) for x in zip(*sorted(zip(sim_num, sim_com), key=itemgetter(0)))) - closestmatch = spicemanip.main(sim_com, 'reverse', "list") - listnumb, relist = 1, [] - for item in closestmatch: - if listnumb <= 10: - relist.append(str(item)) - listnumb += 1 - bot.notice("The following commands may match " + str(triggercommand) + ": " + spicemanip.main(relist, 'andlist') + ".", trigger.nick) - return - - elif triggercommand in commands_list.keys(): - bot.notice("The following commands match " + str(triggercommand) + ": " + str(triggercommand) + ".", trigger.nick) - return - - else: - commandlist = [] - for command in commands_list.keys(): - if command.lower().startswith(triggercommand): - commandlist.append(command) - if commandlist == []: - bot.notice("No commands match " + str(triggercommand) + ".", trigger.nick) - return + triggercommand += "?" else: - bot.notice("The following commands match " + str(triggercommand) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick) + realcom = triggercommand + if "aliasfor" in commands_list[triggercommand].keys(): + realcom = commands_list[triggercommand]["aliasfor"] + validcomlist = commands_list[realcom]["validcoms"] + if not len(validcomlist): + bot.notice("No commands match " + str(triggercommand) + ".", trigger.nick) + else: + bot.notice("The following commands match " + str(triggercommand) + ": " + spicemanip.main(validcomlist, 'andlist') + ".", trigger.nick) return + + if triggercommand.endswith("?"): + triggercommand = triggercommand[:-1] + if not triggercommand or not len(triggercommand): + return + closestmatches = similar_list(bot, triggercommand, commands_list.keys(), 10, 'reverse') + if not len(closestmatches): + bot.notice("No commands match " + str(triggercommand) + ".", trigger.nick) + else: + bot.notice("The following commands may match " + str(triggercommand) + ": " + spicemanip.main(closestmatches, 'andlist') + ".", trigger.nick) + return + + commandlist = [] + for command in commands_list.keys(): + if command.lower().startswith(triggercommand): + commandlist.append(command) + + if not len(commandlist): + bot.notice("No commands match " + str(triggercommand) + ".", trigger.nick) + else: + bot.notice("The following commands match " + str(triggercommand) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick) diff --git a/sopel_modules/SpiceBot_Database_Tools/DatabaseTools.py b/sopel_modules/SpiceBot_Database_Tools/DatabaseTools.py index 816c56f..c598857 100644 --- a/sopel_modules/SpiceBot_Database_Tools/DatabaseTools.py +++ b/sopel_modules/SpiceBot_Database_Tools/DatabaseTools.py @@ -58,7 +58,7 @@ def db_adjust_list(bot, nick, entries, key, adjustmentdirection): for x in adjustlistnew: if x not in adjustlist: adjustlist.append(x) - if adjustlist == []: + if not len(adjustlist): db_reset_value(bot, nick, key) else: db_set_nick_value(bot, nick, key, adjustlist) diff --git a/sopel_modules/SpiceBot_GifSearch/gif.py b/sopel_modules/SpiceBot_GifSearch/gif.py index 9a93975..52d272f 100644 --- a/sopel_modules/SpiceBot_GifSearch/gif.py +++ b/sopel_modules/SpiceBot_GifSearch/gif.py @@ -19,7 +19,7 @@ def gif_trigger(bot, trigger): pass triggerargs, triggercommand = sopel_triggerargs(bot, trigger) - if triggerargs == []: + if not len(triggerargs): return bot.osd("Please present a query to search.") query = spicemanip.main(triggerargs, 0) diff --git a/sopel_modules/SpiceBot_GifSearch/gifapi.py b/sopel_modules/SpiceBot_GifSearch/gifapi.py index 6748cae..05a7b0e 100644 --- a/sopel_modules/SpiceBot_GifSearch/gifapi.py +++ b/sopel_modules/SpiceBot_GifSearch/gifapi.py @@ -23,7 +23,7 @@ def gifapi_triggers(bot, trigger): if triggercommand not in bot.memory["SpiceBot_GifSearch"]['valid_gif_api_dict'].keys(): return - if triggerargs == []: + if not len(triggerargs): return bot.osd("Please present a query to search.") query = spicemanip.main(triggerargs, 0) diff --git a/sopel_modules/SpiceBot_GifSearch/gifsearch.py b/sopel_modules/SpiceBot_GifSearch/gifsearch.py index 7f8ba88..fb9581d 100644 --- a/sopel_modules/SpiceBot_GifSearch/gifsearch.py +++ b/sopel_modules/SpiceBot_GifSearch/gifsearch.py @@ -167,7 +167,7 @@ def getGif(bot, searchdict): if str(searchdict["searchquery"]) not in bot.memory["SpiceBot_GifSearch"]['cache'][currentapi].keys(): bot.memory["SpiceBot_GifSearch"]['cache'][currentapi][str(searchdict["searchquery"])] = [] - if bot.memory["SpiceBot_GifSearch"]['cache'][currentapi][str(searchdict["searchquery"])] == []: + if not len(bot.memory["SpiceBot_GifSearch"]['cache'][currentapi][str(searchdict["searchquery"])]): try: page = requests.get(url, headers=header) @@ -195,7 +195,7 @@ def getGif(bot, searchdict): resultsarray.append(cururl) # make sure there are results - if resultsarray != []: + if len(resultsarray): # Create Temp dict for every result tempresultnum = 0 @@ -215,10 +215,10 @@ def getGif(bot, searchdict): verifygoodlinks.append(gifresult) bot.memory["SpiceBot_GifSearch"]['cache'][currentapi][str(searchdict["searchquery"])] = verifygoodlinks - if bot.memory["SpiceBot_GifSearch"]['cache'][currentapi][str(searchdict["searchquery"])] != []: + if len(bot.memory["SpiceBot_GifSearch"]['cache'][currentapi][str(searchdict["searchquery"])]): gifapiresults.extend(bot.memory["SpiceBot_GifSearch"]['cache'][currentapi][str(searchdict["searchquery"])]) - if gifapiresults == []: + if not len(gifapiresults): return {"error": "No Results were found for '" + searchdict["query"] + "' in the " + str(spicemanip.main(searchdict['gifsearch'], 'orlist')) + " api(s)"} random.shuffle(gifapiresults) @@ -243,7 +243,7 @@ def getGif(bot, searchdict): newlist.append(tempdict) gifapiresults = newlist - if gifapiresults == []: + if not len(gifapiresults): return {"error": "No Results were found for '" + searchdict["query"] + "' in the " + str(spicemanip.main(searchdict['gifsearch'], 'orlist')) + " api(s)"} # return dict diff --git a/sopel_modules/SpiceBot_SBTools/__init__.py b/sopel_modules/SpiceBot_SBTools/__init__.py index fb4054b..46284d8 100644 --- a/sopel_modules/SpiceBot_SBTools/__init__.py +++ b/sopel_modules/SpiceBot_SBTools/__init__.py @@ -84,7 +84,7 @@ def command_permissions_check(bot, trigger, privslist): else: commandrunconsensus.append('True') - if privslist == []: + if not len(privslist): commandrunconsensus.append('True') if 'True' not in commandrunconsensus: @@ -236,13 +236,13 @@ def similar_list(bot, searchitem, searchlist, matchcount=1, searchorder='reverse sim_listitems, sim_num = [], [] for listitem in searchlist: - similarlevel = similar(searchitem.lower(), listitem.lower()) + similarlevel = SequenceMatcher(None, searchitem.lower(), listitem.lower()).ratio() if similarlevel >= .75: sim_listitems.append(listitem) sim_num.append(similarlevel) if len(sim_listitems) and len(sim_num): - sim_num, sim_listitems = array_arrangesort(bot, sim_num, sim_listitems) + sim_num, sim_listitems = (list(x) for x in zip(*sorted(zip(sim_num, sim_listitems), key=itemgetter(0)))) if searchorder == 'reverse': sim_listitems = spicemanip.main(sim_listitems, 'reverse', "list") @@ -257,6 +257,13 @@ def array_arrangesort(bot, sortbyarray, arrayb): return sortbyarray, arrayb +def letters_in_string(text): + if text.isupper() or text.islower(): + return False + else: + return True + + """Channel Functions""" From 8fe7254b20052e48f46e56d9377c28871f82f684 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 13 May 2019 11:56:19 -0400 Subject: [PATCH 30/80] True --- sopel_modules/SpiceBot_Logs/ErrorDisplay.py | 2 +- .../SpiceBot_StartupMonologue/StartupMonologue_Display.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot_Logs/ErrorDisplay.py b/sopel_modules/SpiceBot_Logs/ErrorDisplay.py index c89f04b..f4ecbb4 100644 --- a/sopel_modules/SpiceBot_Logs/ErrorDisplay.py +++ b/sopel_modules/SpiceBot_Logs/ErrorDisplay.py @@ -32,4 +32,4 @@ def bot_startup_monologue_start(bot, trigger): searchphrasefound.append("Run the debug command for more information.") bot.osd(searchphrasefound, bot.channels.keys()) else: - bot_logging(bot, 'SpiceBot_Logs', "No issues found at bot startup!") + bot_logging(bot, 'SpiceBot_Logs', "No issues found at bot startup!", True) diff --git a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py index 80e8f9f..68836c5 100644 --- a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py +++ b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py @@ -64,4 +64,4 @@ def bot_startup_monologue_display(bot, trigger): bot.osd(bot.memory['SpiceBot_StartupMonologue'], bot.channels.keys(), 'ACTION') bot_events_trigger(bot, 2005, "SpiceBot_StartupMonologue") - bot_logging(bot, 'SpiceBot_StartupMonologue', "Startup Monologue has been issued to all channels.") + bot_logging(bot, 'SpiceBot_StartupMonologue', "Startup Monologue has been issued to all channels.", True) From b511462b154b86f54b2818837e2705e2995dca01 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 13 May 2019 12:07:27 -0400 Subject: [PATCH 31/80] more error logging tweaks --- sopel_modules/SpiceBot_Logs/ErrorDisplay.py | 8 ++------ sopel_modules/SpiceBot_SBTools/__init__.py | 6 +++--- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/sopel_modules/SpiceBot_Logs/ErrorDisplay.py b/sopel_modules/SpiceBot_Logs/ErrorDisplay.py index f4ecbb4..db978ab 100644 --- a/sopel_modules/SpiceBot_Logs/ErrorDisplay.py +++ b/sopel_modules/SpiceBot_Logs/ErrorDisplay.py @@ -18,12 +18,8 @@ def bot_startup_monologue_start(bot, trigger): searchphrasefound = [] for line in debuglines: - if "modules failed to load" in str(line) and "0 modules failed to load" not in str(line): - searchphrase = str(line).replace(" modules failed to load", "") - searchphrasefound.append(str(searchphrase) + " module(s) failed") - elif "dict files failed to load" in str(line) and "0 dict files failed to load" not in str(line): - searchphrase = str(line).replace(" dict files failed to load", "") - searchphrasefound.append(str(searchphrase) + " dict file(s) failed") + if str(line).endswith("failed to load") and not str(line).startswith("0"): + searchphrasefound.append(line) if len(searchphrasefound): for foundphase in searchphrasefound: diff --git a/sopel_modules/SpiceBot_SBTools/__init__.py b/sopel_modules/SpiceBot_SBTools/__init__.py index 46284d8..406abe1 100644 --- a/sopel_modules/SpiceBot_SBTools/__init__.py +++ b/sopel_modules/SpiceBot_SBTools/__init__.py @@ -440,10 +440,10 @@ def read_directory_json_to_dict(bot, directories, configtypename="Config File", if filecount: if bot: - bot_logging(bot, log_from, 'Registered %d %s files,' % (filecount, configtypename)) - bot_logging(bot, log_from, '%d %s files failed to load' % (fileopenfail, configtypename)) + bot_logging(bot, log_from, 'Registered %d %s dict files,' % (filecount, configtypename)) + bot_logging(bot, log_from, '%d %s dict files failed to load' % (fileopenfail, configtypename), True) else: if bot: - bot_logging(bot, log_from, "Warning: Couldn't load any %s files" % (configtypename)) + bot_logging(bot, log_from, "Warning: Couldn't load any %s dict files" % (configtypename)) return configs_dict From 7bdbf6ec6c86e747f759e699be5f2e69f287edd7 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 13 May 2019 12:25:15 -0400 Subject: [PATCH 32/80] logtypes --- sopel_modules/SpiceBot_Logs/Logs_Command.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot_Logs/Logs_Command.py b/sopel_modules/SpiceBot_Logs/Logs_Command.py index e1e1617..de9da49 100644 --- a/sopel_modules/SpiceBot_Logs/Logs_Command.py +++ b/sopel_modules/SpiceBot_Logs/Logs_Command.py @@ -6,7 +6,7 @@ import sopel.module import spicemanip -from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, command_permissions_check, inlist, inlist_match +from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, command_permissions_check, inlist, inlist_match, similar_list from sopel_modules.SpiceBot_Events.System import bot_events_check from .Logs import systemd_logs_fetch, stdio_logs_fetch @@ -24,10 +24,19 @@ def bot_command_logs(bot, trigger): triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'nickname_command') logtype = spicemanip.main(triggerargs, 1) or None - if not logtype or not inlist(bot, logtype, bot.memory['SpiceBot_Logs']["logs"].keys()): + if not logtype: bot.osd("Current valid log(s) include: " + spicemanip.main(bot.memory['SpiceBot_Logs']["logs"].keys(), 'andlist'), trigger.sender, 'action') return + if not inlist(bot, logtype, bot.memory['SpiceBot_Logs']["logs"].keys()): + closestmatches = similar_list(bot, logtype, bot.memory['SpiceBot_Logs']["logs"].keys(), 10, 'reverse') + if not len(closestmatches): + bot.notice("No valid logs match " + str(logtype) + ".", trigger.nick) + else: + bot.notice("The following commands may match " + str(logtype) + ": " + spicemanip.main(closestmatches, 'andlist') + ".", trigger.nick) + + return + logtype = inlist_match(bot, logtype, bot.memory['SpiceBot_Logs']["logs"].keys()) if logtype == "Sopel_systemd": From 0dd48dd10034e74d2f9c34d2c1d6bfc1b5b95fb1 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 13 May 2019 12:27:37 -0400 Subject: [PATCH 33/80] wrong --- sopel_modules/SpiceBot_SBTools/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot_SBTools/__init__.py b/sopel_modules/SpiceBot_SBTools/__init__.py index 406abe1..1bb1bed 100644 --- a/sopel_modules/SpiceBot_SBTools/__init__.py +++ b/sopel_modules/SpiceBot_SBTools/__init__.py @@ -259,9 +259,9 @@ def array_arrangesort(bot, sortbyarray, arrayb): def letters_in_string(text): if text.isupper() or text.islower(): - return False - else: return True + else: + return False """Channel Functions""" From 59ee2f41f551e3584b759bee5501c8bc8596e08f Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 13 May 2019 12:47:15 -0400 Subject: [PATCH 34/80] stdio imporvements --- sopel_modules/SpiceBot_Logs/Logs.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/sopel_modules/SpiceBot_Logs/Logs.py b/sopel_modules/SpiceBot_Logs/Logs.py index 3fdc3ed..b376bd2 100644 --- a/sopel_modules/SpiceBot_Logs/Logs.py +++ b/sopel_modules/SpiceBot_Logs/Logs.py @@ -68,7 +68,7 @@ def join_log_channel(bot, trigger): def stdio_logs_fetch(bot): - stdio_ignore = ["Loaded:"] + stdio_ignore = [] for logtype in bot.memory['SpiceBot_Logs']["logs"].keys(): stdio_ignore.append("[" + logtype + "]") @@ -94,10 +94,15 @@ def stdio_logs_fetch(bot): filelines = [] debuglines = [] + loadedmodules = [] for line in filelines: - if not line.startswith(tuple(stdio_ignore)): - if not line.isspace(): + if not line.startswith("Loaded:"): + loadedmodules.append(str(line).split("Loaded:")[-1]) + else: + if not line.startswith(tuple(stdio_ignore)) and not line.isspace(): debuglines.append(str(line)) + loadedmodules = "Loaded: " + spicemanip.main(loadedmodules, 'andlist') + debuglines.insert(1, loadedmodules) return debuglines From 2a92b4679f9d940e6d7f812a8a09fe1a19eed351 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 13 May 2019 12:59:59 -0400 Subject: [PATCH 35/80] more descriptive errors --- .../SpiceBot_CommandsQuery/QueryCommand.py | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py b/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py index b778530..eee1a29 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py +++ b/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py @@ -30,29 +30,34 @@ def query_detection(bot, trigger): return if triggercommand.endswith("+"): + triggercommand = triggercommand[:-1] if not triggercommand or not len(triggercommand): return - if triggercommand not in commands_list.keys(): - triggercommand += "?" - else: - realcom = triggercommand - if "aliasfor" in commands_list[triggercommand].keys(): - realcom = commands_list[triggercommand]["aliasfor"] - validcomlist = commands_list[realcom]["validcoms"] - if not len(validcomlist): - bot.notice("No commands match " + str(triggercommand) + ".", trigger.nick) - else: - bot.notice("The following commands match " + str(triggercommand) + ": " + spicemanip.main(validcomlist, 'andlist') + ".", trigger.nick) - return + + if triggercommand not in commands_list.keys(): + closestmatches = similar_list(bot, triggercommand, commands_list.keys(), 10, 'reverse') + dispmsg = ["Cannot find any alias commands: No valid commands match " + str(triggercommand) + ".", + "The following commands match " + str(triggercommand) + ": " + spicemanip.main(closestmatches, 'andlist') + "."] + bot.notice(dispmsg, trigger.nick) + return + + realcom = triggercommand + if "aliasfor" in commands_list[triggercommand].keys(): + realcom = commands_list[triggercommand]["aliasfor"] + validcomlist = commands_list[realcom]["validcoms"] + bot.notice("The following commands match " + str(triggercommand) + ": " + spicemanip.main(validcomlist, 'andlist') + ".", trigger.nick) + return if triggercommand.endswith("?"): + triggercommand = triggercommand[:-1] if not triggercommand or not len(triggercommand): return + closestmatches = similar_list(bot, triggercommand, commands_list.keys(), 10, 'reverse') if not len(closestmatches): - bot.notice("No commands match " + str(triggercommand) + ".", trigger.nick) + bot.notice("Cannot find any similar commands for " + str(triggercommand) + ".", trigger.nick) else: bot.notice("The following commands may match " + str(triggercommand) + ": " + spicemanip.main(closestmatches, 'andlist') + ".", trigger.nick) return @@ -63,6 +68,6 @@ def query_detection(bot, trigger): commandlist.append(command) if not len(commandlist): - bot.notice("No commands match " + str(triggercommand) + ".", trigger.nick) + bot.notice("No commands start with " + str(triggercommand) + ".", trigger.nick) else: - bot.notice("The following commands match " + str(triggercommand) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick) + bot.notice("The following commands start with " + str(triggercommand) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick) From a3b2d4250e857b76e6143ed4f201b360a45d9448 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 13 May 2019 13:27:16 -0400 Subject: [PATCH 36/80] revert changes --- .../SpiceBot_CommandsQuery/CommandsQuery.py | 21 ++----------------- .../SpiceBot_CommandsQuery/QueryCommand.py | 10 ++++++++- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py index 51b4d10..548d746 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py +++ b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py @@ -18,7 +18,7 @@ def setup(bot): bot_events_startup_register(bot, ['2002']) if 'SpiceBot_CommandsQuery' not in bot.memory: - bot.memory['SpiceBot_CommandsQuery'] = {"counts": 0, 'commands_all': {}, "commands": {}, "nickrules": []} + bot.memory['SpiceBot_CommandsQuery'] = {"counts": 0, "commands": {}, "nickrules": []} for comtype in ['module', 'nickname', 'rule']: if comtype not in bot.memory['SpiceBot_CommandsQuery']['commands'].keys(): @@ -152,15 +152,6 @@ def setup(bot): if command not in bot.memory['SpiceBot_CommandsQuery']['nickrules']: bot.memory['SpiceBot_CommandsQuery']['nickrules'].append(command) - for commandstype in bot.memory['SpiceBot_CommandsQuery']['commands'].keys(): - if commandstype != 'rule': - for com in bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype].keys(): - if com not in bot.memory['SpiceBot_CommandsQuery']['commands_all'].keys(): - if commandstype == 'nickname': - bot.memory['SpiceBot_CommandsQuery']['commands_all'][str(bot.nick) + " " + com] = bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype][com] - else: - bot.memory['SpiceBot_CommandsQuery']['commands_all'][com] = bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype][com] - bot_events_trigger(bot, 2002, "SpiceBot_CommandsQuery") @@ -182,7 +173,7 @@ def bot_events_complete(bot, trigger): def commandsquery_register(bot, command_type, validcoms, aliasfor=None): if 'SpiceBot_CommandsQuery' not in bot.memory: - bot.memory['SpiceBot_CommandsQuery'] = {"counts": 0, 'commands_all': {}, "commands": {}, "nickrules": []} + bot.memory['SpiceBot_CommandsQuery'] = {"counts": 0, "commands": {}, "nickrules": []} if not isinstance(validcoms, list): validcoms = [validcoms] @@ -212,14 +203,6 @@ def commandsquery_register(bot, command_type, validcoms, aliasfor=None): if comalias not in bot.memory['SpiceBot_CommandsQuery']['commands'][command_type].keys(): bot.memory['SpiceBot_CommandsQuery']['commands'][command_type][comalias] = {"aliasfor": aliasfor} - for comalias in comaliases: - if command_type != 'rule': - if comalias not in bot.memory['SpiceBot_CommandsQuery']['commands_all'].keys(): - if command_type == 'nickname': - bot.memory['SpiceBot_CommandsQuery']['commands_all'][str(bot.nick) + " " + comalias] = bot.memory['SpiceBot_CommandsQuery']['commands'][command_type][comalias] - else: - bot.memory['SpiceBot_CommandsQuery']['commands_all'][comalias] = bot.memory['SpiceBot_CommandsQuery']['commands'][command_type][comalias] - @sopel.module.event('2002') @sopel.module.rule('.*') diff --git a/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py b/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py index eee1a29..9751d75 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py +++ b/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py @@ -18,7 +18,15 @@ def query_detection(bot, trigger): while not bot_events_check(bot, '2002'): pass - commands_list = bot.memory['SpiceBot_CommandsQuery']['commands_all'] + commands_list = dict() + for commandstype in bot.memory['SpiceBot_CommandsQuery']['commands'].keys(): + if commandstype != 'rule': + for com in bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype].keys(): + if com not in commands_list.keys(): + if commandstype == 'nickname': + commands_list[str(bot.nick) + " " + com] = bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype][com] + else: + commands_list[com] = bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype][com] triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'query_command') From 23404108f605169fd6d4e075cf7599ac644318a4 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 13 May 2019 13:38:32 -0400 Subject: [PATCH 37/80] add lower --- sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py b/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py index 9751d75..5e05f93 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py +++ b/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py @@ -44,9 +44,10 @@ def query_detection(bot, trigger): return if triggercommand not in commands_list.keys(): + dispmsg = ["Cannot find any alias commands: No valid commands match " + str(triggercommand) + "."] closestmatches = similar_list(bot, triggercommand, commands_list.keys(), 10, 'reverse') - dispmsg = ["Cannot find any alias commands: No valid commands match " + str(triggercommand) + ".", - "The following commands match " + str(triggercommand) + ": " + spicemanip.main(closestmatches, 'andlist') + "."] + if len(closestmatches): + dispmsg.append("The following commands match " + str(triggercommand) + ": " + spicemanip.main(closestmatches, 'andlist') + ".") bot.notice(dispmsg, trigger.nick) return @@ -72,7 +73,7 @@ def query_detection(bot, trigger): commandlist = [] for command in commands_list.keys(): - if command.lower().startswith(triggercommand): + if command.lower().startswith(str(triggercommand).lower()): commandlist.append(command) if not len(commandlist): From b2a7c5e3caafa7f56666808ab1f0029d04d6c3ff Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 13 May 2019 14:37:29 -0400 Subject: [PATCH 38/80] don't load asterisk regex --- .../SpiceBot_CommandsQuery/CommandsQuery.py | 47 +++++++++++-------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py index 548d746..31ac4ed 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py +++ b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py @@ -97,9 +97,9 @@ def setup(bot): detected_lines.append(line) if len(detected_lines): - bot.memory['SpiceBot_CommandsQuery']['counts'] += 1 filelinelist = [] + currentsuccesslines = 0 for detected_line in detected_lines: # Commands @@ -117,31 +117,40 @@ def setup(bot): validcoms = list(validcoms) else: validcoms = [validcoms] + if "(.*)" in validcoms: + while "(.*)" in validcoms: + validcoms.remove("(.*)") - validcomdict = {"comtype": comtype, "validcoms": validcoms} - filelinelist.append(validcomdict) + if len(validcoms): + validcomdict = {"comtype": comtype, "validcoms": validcoms} + filelinelist.append(validcomdict) + currentsuccesslines += 1 - for atlinefound in filelinelist: + if currentsuccesslines: + bot.memory['SpiceBot_CommandsQuery']['counts'] += 1 - dict_from_file = dict() + if len(filelinelist): + for atlinefound in filelinelist: - comtype = atlinefound["comtype"] - validcoms = atlinefound["validcoms"] + dict_from_file = dict() - # default command to filename - if "validcoms" not in dict_from_file.keys(): - dict_from_file["validcoms"] = validcoms + comtype = atlinefound["comtype"] + validcoms = atlinefound["validcoms"] - maincom = dict_from_file["validcoms"][0] - if len(dict_from_file["validcoms"]) > 1: - comaliases = spicemanip.main(dict_from_file["validcoms"], '2+', 'list') - else: - comaliases = [] + # default command to filename + if "validcoms" not in dict_from_file.keys(): + dict_from_file["validcoms"] = validcoms - bot.memory['SpiceBot_CommandsQuery']['commands'][comtype][maincom] = dict_from_file - for comalias in comaliases: - if comalias not in bot.memory['SpiceBot_CommandsQuery']['commands'][comtype].keys(): - bot.memory['SpiceBot_CommandsQuery']['commands'][comtype][comalias] = {"aliasfor": maincom} + maincom = dict_from_file["validcoms"][0] + if len(dict_from_file["validcoms"]) > 1: + comaliases = spicemanip.main(dict_from_file["validcoms"], '2+', 'list') + else: + comaliases = [] + + bot.memory['SpiceBot_CommandsQuery']['commands'][comtype][maincom] = dict_from_file + for comalias in comaliases: + if comalias not in bot.memory['SpiceBot_CommandsQuery']['commands'][comtype].keys(): + bot.memory['SpiceBot_CommandsQuery']['commands'][comtype][comalias] = {"aliasfor": maincom} for comtype in ['module', 'nickname', 'rule']: bot_logging(bot, 'SpiceBot_CommandsQuery', "Found " + str(len(bot.memory['SpiceBot_CommandsQuery']['commands'][comtype].keys())) + " " + comtype + " commands.", True) From f2dbfc958965e72da287e099e6b76742724cea29 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 13 May 2019 14:56:57 -0400 Subject: [PATCH 39/80] better alias finding --- sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py b/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py index 5e05f93..de0c833 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py +++ b/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py @@ -25,6 +25,9 @@ def query_detection(bot, trigger): if com not in commands_list.keys(): if commandstype == 'nickname': commands_list[str(bot.nick) + " " + com] = bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype][com] + if "aliasfor" in commands_list[str(bot.nick) + " " + com].keys(): + aliasforcom = commands_list[str(bot.nick) + " " + com]["aliasfor"] + commands_list[str(bot.nick) + " " + com]["aliasfor"] = str(bot.nick) + " " + aliasforcom else: commands_list[com] = bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype][com] From b894ee93c54e20fb321fdfca81038f7af9f953c3 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 13 May 2019 15:22:47 -0400 Subject: [PATCH 40/80] nickname commands --- .../SpiceBot_CommandsQuery/QueryCommand.py | 66 +++++++++++-------- 1 file changed, 38 insertions(+), 28 deletions(-) diff --git a/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py b/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py index de0c833..521f2e7 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py +++ b/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py @@ -18,6 +18,15 @@ def query_detection(bot, trigger): while not bot_events_check(bot, '2002'): pass + triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'query_command') + + # command issued, check if valid + if not triggercommand or not len(triggercommand): + return + + if not letters_in_string(triggercommand): + return + commands_list = dict() for commandstype in bot.memory['SpiceBot_CommandsQuery']['commands'].keys(): if commandstype != 'rule': @@ -31,55 +40,56 @@ def query_detection(bot, trigger): else: commands_list[com] = bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype][com] - triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'query_command') + botnick_coms = list(bot.memory['SpiceBot_CommandsQuery']['commands']['nickname'].keys()) + # botnick_coms.extend(bot.memory['SpiceBot_CommandsQuery']['nickrules']) - # command issued, check if valid - if not triggercommand or not len(triggercommand): - return + if triggercommand.lower().startswith(str(bot.nick).lower()): + searchlist = botnick_coms + searchitem = spicemanip.main([triggercommand].extend(triggerargs), 0) + else: + searchlist = list(commands_list.keys()) + searchitem = triggercommand - if not letters_in_string(triggercommand): - return + if searchitem.endswith("+"): - if triggercommand.endswith("+"): - - triggercommand = triggercommand[:-1] - if not triggercommand or not len(triggercommand): + searchitem = searchitem[:-1] + if not searchitem or not len(searchitem): return - if triggercommand not in commands_list.keys(): - dispmsg = ["Cannot find any alias commands: No valid commands match " + str(triggercommand) + "."] - closestmatches = similar_list(bot, triggercommand, commands_list.keys(), 10, 'reverse') + if searchitem.lower() not in searchlist: + dispmsg = ["Cannot find any alias commands: No valid commands match " + str(searchitem) + "."] + closestmatches = similar_list(bot, searchitem, searchlist, 10, 'reverse') if len(closestmatches): - dispmsg.append("The following commands match " + str(triggercommand) + ": " + spicemanip.main(closestmatches, 'andlist') + ".") + dispmsg.append("The following commands match " + str(searchitem) + ": " + spicemanip.main(closestmatches, 'andlist') + ".") bot.notice(dispmsg, trigger.nick) return - realcom = triggercommand - if "aliasfor" in commands_list[triggercommand].keys(): - realcom = commands_list[triggercommand]["aliasfor"] + realcom = searchitem + if "aliasfor" in commands_list[searchitem].keys(): + realcom = commands_list[searchitem]["aliasfor"] validcomlist = commands_list[realcom]["validcoms"] - bot.notice("The following commands match " + str(triggercommand) + ": " + spicemanip.main(validcomlist, 'andlist') + ".", trigger.nick) + bot.notice("The following commands match " + str(searchitem) + ": " + spicemanip.main(validcomlist, 'andlist') + ".", trigger.nick) return - if triggercommand.endswith("?"): + if searchitem.endswith("?"): - triggercommand = triggercommand[:-1] - if not triggercommand or not len(triggercommand): + searchitem = searchitem[:-1] + if not searchitem or not len(searchitem): return - closestmatches = similar_list(bot, triggercommand, commands_list.keys(), 10, 'reverse') + closestmatches = similar_list(bot, searchitem, searchlist, 10, 'reverse') if not len(closestmatches): - bot.notice("Cannot find any similar commands for " + str(triggercommand) + ".", trigger.nick) + bot.notice("Cannot find any similar commands for " + str(searchitem) + ".", trigger.nick) else: - bot.notice("The following commands may match " + str(triggercommand) + ": " + spicemanip.main(closestmatches, 'andlist') + ".", trigger.nick) + bot.notice("The following commands may match " + str(searchitem) + ": " + spicemanip.main(closestmatches, 'andlist') + ".", trigger.nick) return commandlist = [] - for command in commands_list.keys(): - if command.lower().startswith(str(triggercommand).lower()): + for command in searchlist: + if command.lower().startswith(str(searchitem).lower()): commandlist.append(command) if not len(commandlist): - bot.notice("No commands start with " + str(triggercommand) + ".", trigger.nick) + bot.notice("No commands start with " + str(searchitem) + ".", trigger.nick) else: - bot.notice("The following commands start with " + str(triggercommand) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick) + bot.notice("The following commands start with " + str(searchitem) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick) From ff03cc903ae9747fc2655b896854be166ff068c6 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 13 May 2019 15:33:44 -0400 Subject: [PATCH 41/80] readd database functions --- .../Databaseaddons.py | 123 ++++++++++++------ .../SpiceBot_Database_Tools/DatabaseTools.py | 7 - 2 files changed, 82 insertions(+), 48 deletions(-) diff --git a/sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py b/sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py index 7977fe7..26fc511 100644 --- a/sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py +++ b/sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py @@ -6,7 +6,8 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi import sopel.module from sopel.tools import Identifier from sopel_modules.SpiceBot_SBTools import bot_logging -from sopel.db import _deserialize, SopelDB +from sopel.db import SopelDB, NickValues, ChannelValues +from sqlalchemy.exc import SQLAlchemyError import json @@ -15,64 +16,104 @@ def setup(bot): pass # Inject Database Functions bot_logging(bot, 'SpiceBot_Databaseaddons', "Implanting Database functions into bot") - SopelDB.reset_nick_value = SopelDBCache.reset_nick_value - SopelDB.adjust_nick_value = SopelDBCache.adjust_nick_value - SopelDB.reset_channel_value = SopelDBCache.reset_channel_value - SopelDB.adjust_channel_value = SopelDBCache.adjust_channel_value - SopelDB._create_table = SopelDBCache._create_table + SopelDB.delete_nick_value = SopelDBCache.delete_nick_value + # SopelDB.adjust_nick_value = SopelDBCache.adjust_nick_value + SopelDB.delete_channel_value = SopelDBCache.delete_channel_value + # SopelDB.adjust_channel_value = SopelDBCache.adjust_channel_value class SopelDBCache: - """Dynamic Table Creation""" - - def _create_table(self, tablename): - self.execute('CREATE TABLE IF NOT EXISTS ? (mainid STRING, key STRING, value STRING, PRIMARY KEY (mainid, key))', tablename) - """Nicks""" - def reset_nick_value(self, nick, key): - """Resets the value for a given key to be associated with the nick.""" + def delete_nick_value(self, nick, key): + """Deletes the value for a given key to be associated with the nick.""" nick = Identifier(nick) nick_id = self.get_nick_id(nick) - self.execute('DELETE FROM nick_values WHERE nick_id = ? AND key = ?', [nick_id, key]) + session = self.ssession() + try: + result = session.query(NickValues) \ + .filter(NickValues.nick_id == nick_id) \ + .filter(NickValues.key == key) \ + .one_or_none() + # NickValue exists, delete + if result: + session.delete(result.value) + session.commit() + except SQLAlchemyError: + session.rollback() + raise + finally: + session.close() def adjust_nick_value(self, nick, key, value): - """Adjusts the value for a given key to be associated with the nick.""" + """Sets the value for a given key to be associated with the nick.""" nick = Identifier(nick) - result = self.execute( - 'SELECT value FROM nicknames JOIN nick_values ' - 'ON nicknames.nick_id = nick_values.nick_id ' - 'WHERE slug = ? AND key = ?', - [nick.lower(), key] - ).fetchone() - if result is not None: - result = result[0] - current_value = _deserialize(result) - value = current_value + value value = json.dumps(value, ensure_ascii=False) nick_id = self.get_nick_id(nick) - self.execute('INSERT OR REPLACE INTO nick_values VALUES (?, ?, ?)', - [nick_id, key, value]) + session = self.ssession() + try: + result = session.query(NickValues) \ + .filter(NickValues.nick_id == nick_id) \ + .filter(NickValues.key == key) \ + .one_or_none() + # NickValue exists, update + if result: + result.value = result.value + value + session.commit() + # DNE - Insert + else: + new_nickvalue = NickValues(nick_id=nick_id, key=key, value=value) + session.add(new_nickvalue) + session.commit() + except SQLAlchemyError: + session.rollback() + raise + finally: + session.close() """Channels""" - def reset_channel_value(self, channel, key): - """Resets the value for a given key to be associated with a channel.""" + def delete_channel_value(self, channel, key): + """Sets the value for a given key to be associated with the channel.""" channel = Identifier(channel).lower() - self.execute('DELETE FROM channel_values WHERE channel = ? AND key = ?', [channel, key]) + session = self.ssession() + try: + result = session.query(ChannelValues) \ + .filter(ChannelValues.channel == channel)\ + .filter(ChannelValues.key == key) \ + .one_or_none() + # ChannelValue exists, update + if result: + session.delete(result.value) + session.commit() + except SQLAlchemyError: + session.rollback() + raise + finally: + session.close() def adjust_channel_value(self, channel, key, value): - """Adjusts the value for a given key to be associated with the channel.""" + """Sets the value for a given key to be associated with the channel.""" channel = Identifier(channel).lower() - result = self.execute( - 'SELECT value FROM channel_values WHERE channel = ? AND key = ?', - [channel, key] - ).fetchone() - if result is not None: - result = result[0] - current_value = _deserialize(result) - value = current_value + value value = json.dumps(value, ensure_ascii=False) - self.execute('INSERT OR REPLACE INTO channel_values VALUES (?, ?, ?)', - [channel, key, value]) + session = self.ssession() + try: + result = session.query(ChannelValues) \ + .filter(ChannelValues.channel == channel)\ + .filter(ChannelValues.key == key) \ + .one_or_none() + # ChannelValue exists, update + if result: + result.value = result.value + value + session.commit() + # DNE - Insert + else: + new_channelvalue = ChannelValues(channel=channel, key=key, value=value) + session.add(new_channelvalue) + session.commit() + except SQLAlchemyError: + session.rollback() + raise + finally: + session.close() diff --git a/sopel_modules/SpiceBot_Database_Tools/DatabaseTools.py b/sopel_modules/SpiceBot_Database_Tools/DatabaseTools.py index c598857..e074941 100644 --- a/sopel_modules/SpiceBot_Database_Tools/DatabaseTools.py +++ b/sopel_modules/SpiceBot_Database_Tools/DatabaseTools.py @@ -6,13 +6,6 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi import sopel.module -"""Dyanmic Table Creation""" - - -def db_create_table(bot, tablename): - bot.db._create_table(tablename) - - """Database Direct""" From c8a576baf2ec1d45a0729007e3efa2565d0708a0 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 13 May 2019 16:14:14 -0400 Subject: [PATCH 42/80] nickname commands handled externally --- sopel_modules/SpiceBot_AI/AI.py | 4 + .../NickQueryCommand.py | 77 +++++++++++++++++++ .../SpiceBot_CommandsQuery/QueryCommand.py | 64 ++++++--------- .../SpiceBot_CommandsQuery/__init__.py | 1 + 4 files changed, 106 insertions(+), 40 deletions(-) create mode 100644 sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py diff --git a/sopel_modules/SpiceBot_AI/AI.py b/sopel_modules/SpiceBot_AI/AI.py index 97adc03..b2fc9c7 100644 --- a/sopel_modules/SpiceBot_AI/AI.py +++ b/sopel_modules/SpiceBot_AI/AI.py @@ -13,6 +13,10 @@ from sopel_modules.SpiceBot_Events.System import bot_events_check @sopel.module.nickname_commands('(.*)') def bot_command_nick(bot, trigger): + # command must not start with + if str(trigger).startswith(tuple(['?'])): + return + while not bot_events_check(bot, ['1004', '2002']): pass diff --git a/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py b/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py new file mode 100644 index 0000000..e7d3066 --- /dev/null +++ b/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py @@ -0,0 +1,77 @@ +# coding=utf-8 + +from __future__ import unicode_literals, absolute_import, division, print_function + +import sopel +import sopel.module + +from sopel_modules.SpiceBot_Events.System import bot_events_check +from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, similar_list, letters_in_string + + +import spicemanip + + +@sopel.module.nickname_commands('^\?(.*)') +def query_detection_nick(bot, trigger): + + while not bot_events_check(bot, '2002'): + pass + + triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'nickname_command') + + # command issued, check if valid + if not triggercommand or not len(triggercommand): + return + + if not letters_in_string(triggercommand): + return + + commands_list = dict() + for com in bot.memory['SpiceBot_CommandsQuery']['commands']['nickname'].keys(): + if com not in commands_list.keys(): + commands_list[com] = bot.memory['SpiceBot_CommandsQuery']['commands']['nickname'][com] + + if triggercommand.endswith("+"): + + triggercommand = triggercommand[:-1] + if not triggercommand or not len(triggercommand): + return + + if triggercommand.lower() not in list(commands_list.keys()): + dispmsg = ["Cannot find any alias commands: No valid commands match " + str(triggercommand) + "."] + closestmatches = similar_list(bot, triggercommand, list(commands_list.keys()), 10, 'reverse') + if len(closestmatches): + dispmsg.append("The following commands match " + str(triggercommand) + ": " + spicemanip.main(closestmatches, 'andlist') + ".") + bot.notice(dispmsg, trigger.nick) + return + + realcom = triggercommand + if "aliasfor" in commands_list[triggercommand].keys(): + realcom = commands_list[triggercommand]["aliasfor"] + validcomlist = commands_list[realcom]["validcoms"] + bot.notice("The following commands match " + str(triggercommand) + ": " + spicemanip.main(validcomlist, 'andlist') + ".", trigger.nick) + return + + if triggercommand.endswith("?"): + + triggercommand = triggercommand[:-1] + if not triggercommand or not len(triggercommand): + return + + closestmatches = similar_list(bot, triggercommand, list(commands_list.keys()), 10, 'reverse') + if not len(closestmatches): + bot.notice("Cannot find any similar commands for " + str(triggercommand) + ".", trigger.nick) + else: + bot.notice("The following commands may match " + str(triggercommand) + ": " + spicemanip.main(closestmatches, 'andlist') + ".", trigger.nick) + return + + commandlist = [] + for command in list(commands_list.keys()): + if command.lower().startswith(str(triggercommand).lower()): + commandlist.append(command) + + if not len(commandlist): + bot.notice("No commands start with " + str(triggercommand) + ".", trigger.nick) + else: + bot.notice("The following commands start with " + str(triggercommand) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick) diff --git a/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py b/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py index 521f2e7..5846ba4 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py +++ b/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py @@ -28,68 +28,52 @@ def query_detection(bot, trigger): return commands_list = dict() - for commandstype in bot.memory['SpiceBot_CommandsQuery']['commands'].keys(): - if commandstype != 'rule': + for commandstype in bot.memory['SpiceBot_CommandsQuery']['commands']["commandstype"].keys(): + if commandstype not in ['rule', 'nickname']: for com in bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype].keys(): if com not in commands_list.keys(): - if commandstype == 'nickname': - commands_list[str(bot.nick) + " " + com] = bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype][com] - if "aliasfor" in commands_list[str(bot.nick) + " " + com].keys(): - aliasforcom = commands_list[str(bot.nick) + " " + com]["aliasfor"] - commands_list[str(bot.nick) + " " + com]["aliasfor"] = str(bot.nick) + " " + aliasforcom - else: - commands_list[com] = bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype][com] + commands_list[com] = bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype][com] - botnick_coms = list(bot.memory['SpiceBot_CommandsQuery']['commands']['nickname'].keys()) - # botnick_coms.extend(bot.memory['SpiceBot_CommandsQuery']['nickrules']) + if triggercommand.endswith("+"): - if triggercommand.lower().startswith(str(bot.nick).lower()): - searchlist = botnick_coms - searchitem = spicemanip.main([triggercommand].extend(triggerargs), 0) - else: - searchlist = list(commands_list.keys()) - searchitem = triggercommand - - if searchitem.endswith("+"): - - searchitem = searchitem[:-1] - if not searchitem or not len(searchitem): + triggercommand = triggercommand[:-1] + if not triggercommand or not len(triggercommand): return - if searchitem.lower() not in searchlist: - dispmsg = ["Cannot find any alias commands: No valid commands match " + str(searchitem) + "."] - closestmatches = similar_list(bot, searchitem, searchlist, 10, 'reverse') + if triggercommand.lower() not in list(commands_list.keys()): + dispmsg = ["Cannot find any alias commands: No valid commands match " + str(triggercommand) + "."] + closestmatches = similar_list(bot, triggercommand, list(commands_list.keys()), 10, 'reverse') if len(closestmatches): - dispmsg.append("The following commands match " + str(searchitem) + ": " + spicemanip.main(closestmatches, 'andlist') + ".") + dispmsg.append("The following commands match " + str(triggercommand) + ": " + spicemanip.main(closestmatches, 'andlist') + ".") bot.notice(dispmsg, trigger.nick) return - realcom = searchitem - if "aliasfor" in commands_list[searchitem].keys(): - realcom = commands_list[searchitem]["aliasfor"] + realcom = triggercommand + if "aliasfor" in commands_list[triggercommand].keys(): + realcom = commands_list[triggercommand]["aliasfor"] validcomlist = commands_list[realcom]["validcoms"] - bot.notice("The following commands match " + str(searchitem) + ": " + spicemanip.main(validcomlist, 'andlist') + ".", trigger.nick) + bot.notice("The following commands match " + str(triggercommand) + ": " + spicemanip.main(validcomlist, 'andlist') + ".", trigger.nick) return - if searchitem.endswith("?"): + if triggercommand.endswith("?"): - searchitem = searchitem[:-1] - if not searchitem or not len(searchitem): + triggercommand = triggercommand[:-1] + if not triggercommand or not len(triggercommand): return - closestmatches = similar_list(bot, searchitem, searchlist, 10, 'reverse') + closestmatches = similar_list(bot, triggercommand, list(commands_list.keys()), 10, 'reverse') if not len(closestmatches): - bot.notice("Cannot find any similar commands for " + str(searchitem) + ".", trigger.nick) + bot.notice("Cannot find any similar commands for " + str(triggercommand) + ".", trigger.nick) else: - bot.notice("The following commands may match " + str(searchitem) + ": " + spicemanip.main(closestmatches, 'andlist') + ".", trigger.nick) + bot.notice("The following commands may match " + str(triggercommand) + ": " + spicemanip.main(closestmatches, 'andlist') + ".", trigger.nick) return commandlist = [] - for command in searchlist: - if command.lower().startswith(str(searchitem).lower()): + for command in list(commands_list.keys()): + if command.lower().startswith(str(triggercommand).lower()): commandlist.append(command) if not len(commandlist): - bot.notice("No commands start with " + str(searchitem) + ".", trigger.nick) + bot.notice("No commands start with " + str(triggercommand) + ".", trigger.nick) else: - bot.notice("The following commands start with " + str(searchitem) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick) + bot.notice("The following commands start with " + str(triggercommand) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick) diff --git a/sopel_modules/SpiceBot_CommandsQuery/__init__.py b/sopel_modules/SpiceBot_CommandsQuery/__init__.py index 55dadea..fcad5b8 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/__init__.py +++ b/sopel_modules/SpiceBot_CommandsQuery/__init__.py @@ -7,6 +7,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi from .CommandsQuery import * from .QueryCommand import * +from .NickQueryCommand import * __author__ = 'Sam Zick' __email__ = 'sam@deathbybandaid.net' From fc9d4d1772fe734bbf8c2329404e278fab6b1a1b Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 13 May 2019 16:19:58 -0400 Subject: [PATCH 43/80] cleaner presentation --- .../SpiceBot_CommandsQuery/NickQueryCommand.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py b/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py index e7d3066..407b045 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py +++ b/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py @@ -39,10 +39,10 @@ def query_detection_nick(bot, trigger): return if triggercommand.lower() not in list(commands_list.keys()): - dispmsg = ["Cannot find any alias commands: No valid commands match " + str(triggercommand) + "."] + dispmsg = ["Cannot find any alias " + bot.nick + " commands: No valid commands match " + str(triggercommand) + "."] closestmatches = similar_list(bot, triggercommand, list(commands_list.keys()), 10, 'reverse') if len(closestmatches): - dispmsg.append("The following commands match " + str(triggercommand) + ": " + spicemanip.main(closestmatches, 'andlist') + ".") + dispmsg.append("The following " + bot.nick + " commands match " + str(triggercommand) + ": " + spicemanip.main(closestmatches, 'andlist') + ".") bot.notice(dispmsg, trigger.nick) return @@ -50,7 +50,7 @@ def query_detection_nick(bot, trigger): if "aliasfor" in commands_list[triggercommand].keys(): realcom = commands_list[triggercommand]["aliasfor"] validcomlist = commands_list[realcom]["validcoms"] - bot.notice("The following commands match " + str(triggercommand) + ": " + spicemanip.main(validcomlist, 'andlist') + ".", trigger.nick) + bot.notice("The following " + bot.nick + "commands match " + str(triggercommand) + ": " + spicemanip.main(validcomlist, 'andlist') + ".", trigger.nick) return if triggercommand.endswith("?"): @@ -61,9 +61,9 @@ def query_detection_nick(bot, trigger): closestmatches = similar_list(bot, triggercommand, list(commands_list.keys()), 10, 'reverse') if not len(closestmatches): - bot.notice("Cannot find any similar commands for " + str(triggercommand) + ".", trigger.nick) + bot.notice("Cannot find any similar " + bot.nick + "commands for " + str(triggercommand) + ".", trigger.nick) else: - bot.notice("The following commands may match " + str(triggercommand) + ": " + spicemanip.main(closestmatches, 'andlist') + ".", trigger.nick) + bot.notice("The following " + bot.nick + "commands may match " + str(triggercommand) + ": " + spicemanip.main(closestmatches, 'andlist') + ".", trigger.nick) return commandlist = [] @@ -72,6 +72,6 @@ def query_detection_nick(bot, trigger): commandlist.append(command) if not len(commandlist): - bot.notice("No commands start with " + str(triggercommand) + ".", trigger.nick) + bot.notice("No " + bot.nick + "commands start with " + str(triggercommand) + ".", trigger.nick) else: - bot.notice("The following commands start with " + str(triggercommand) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick) + bot.notice("The following " + bot.nick + "commands start with " + str(triggercommand) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick) From 4ba356918fdad3d51e46d9c372839c04f32fcab0 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 13 May 2019 16:23:14 -0400 Subject: [PATCH 44/80] better ? detection --- sopel_modules/SpiceBot_AI/AI.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_AI/AI.py b/sopel_modules/SpiceBot_AI/AI.py index b2fc9c7..1c75b56 100644 --- a/sopel_modules/SpiceBot_AI/AI.py +++ b/sopel_modules/SpiceBot_AI/AI.py @@ -14,7 +14,7 @@ from sopel_modules.SpiceBot_Events.System import bot_events_check def bot_command_nick(bot, trigger): # command must not start with - if str(trigger).startswith(tuple(['?'])): + if str(trigger.args[1])[0] == "?": return while not bot_events_check(bot, ['1004', '2002']): From 6772fbc53bb80fa1311b2d0ee7809f686e527af5 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 13 May 2019 16:26:49 -0400 Subject: [PATCH 45/80] better sifting --- sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py index 31ac4ed..9651618 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py +++ b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py @@ -117,9 +117,10 @@ def setup(bot): validcoms = list(validcoms) else: validcoms = [validcoms] - if "(.*)" in validcoms: - while "(.*)" in validcoms: - validcoms.remove("(.*)") + for regexcom in ["(.*)", '^\?(.*)']: + if regexcom in validcoms: + while regexcom in validcoms: + validcoms.remove(regexcom) if len(validcoms): validcomdict = {"comtype": comtype, "validcoms": validcoms} From b6f095b8b20fc1a50aaba27b961a2db48e1d332c Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 13 May 2019 16:28:45 -0400 Subject: [PATCH 46/80] better than endswith for a single char --- sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py b/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py index 5846ba4..939d823 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py +++ b/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py @@ -34,7 +34,7 @@ def query_detection(bot, trigger): if com not in commands_list.keys(): commands_list[com] = bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype][com] - if triggercommand.endswith("+"): + if triggercommand[:-1] == "+": triggercommand = triggercommand[:-1] if not triggercommand or not len(triggercommand): @@ -55,7 +55,7 @@ def query_detection(bot, trigger): bot.notice("The following commands match " + str(triggercommand) + ": " + spicemanip.main(validcomlist, 'andlist') + ".", trigger.nick) return - if triggercommand.endswith("?"): + if triggercommand[:-1] == "?": triggercommand = triggercommand[:-1] if not triggercommand or not len(triggercommand): From a48d3df44401dd55011d1795e3425f93424f44c0 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 14 May 2019 11:27:56 -0400 Subject: [PATCH 47/80] Attempt hardcoded values for events --- sopel_modules/SpiceBot_AI/AI.py | 4 +-- sopel_modules/SpiceBot_Channels/Channels.py | 4 +-- .../SpiceBot_Channels/Channels_Command.py | 4 +-- .../SpiceBot_CommandsQuery/CommandsQuery.py | 4 +-- sopel_modules/SpiceBot_Events/Events.py | 18 ++++++------- sopel_modules/SpiceBot_Events/System.py | 26 +++++++++++++++++-- .../SpiceBot_InvalidCommand/InvalidCommand.py | 6 ++--- sopel_modules/SpiceBot_Logs/Logs.py | 4 +-- .../StartupMonologue_Display.py | 6 ++--- 9 files changed, 49 insertions(+), 27 deletions(-) diff --git a/sopel_modules/SpiceBot_AI/AI.py b/sopel_modules/SpiceBot_AI/AI.py index 1c75b56..8fd489a 100644 --- a/sopel_modules/SpiceBot_AI/AI.py +++ b/sopel_modules/SpiceBot_AI/AI.py @@ -7,7 +7,7 @@ import sopel.module import spicemanip from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, googlesearch, bot_privs, inlist, inlist_match, similar_list -from sopel_modules.SpiceBot_Events.System import bot_events_check +from sopel_modules.SpiceBot_Events.System import bot_events_check, botevents @sopel.module.nickname_commands('(.*)') @@ -17,7 +17,7 @@ def bot_command_nick(bot, trigger): if str(trigger.args[1])[0] == "?": return - while not bot_events_check(bot, ['1004', '2002']): + while not bot_events_check(bot, [botevents.BOT_LOADED, '2002']): pass triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'nickname_command') diff --git a/sopel_modules/SpiceBot_Channels/Channels.py b/sopel_modules/SpiceBot_Channels/Channels.py index 1aec6aa..19ba598 100644 --- a/sopel_modules/SpiceBot_Channels/Channels.py +++ b/sopel_modules/SpiceBot_Channels/Channels.py @@ -6,7 +6,7 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi import sopel.module from sopel.config.types import StaticSection, ValidatedAttribute, ListAttribute -from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger +from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger, botevents from sopel_modules.SpiceBot_SBTools import ( join_all_channels, chanadmin_all_channels, channel_list_current, @@ -48,7 +48,7 @@ def shutdown(bot): del bot.memory["SpiceBot_Channels"] -@sopel.module.event('1003') +@sopel.module.event(botevents.BOT_CONNECTED) @sopel.module.rule('.*') def trigger_channel_list_initial(bot, trigger): bot_events_recieved(bot, trigger.event) diff --git a/sopel_modules/SpiceBot_Channels/Channels_Command.py b/sopel_modules/SpiceBot_Channels/Channels_Command.py index 65858f9..c7e69bc 100644 --- a/sopel_modules/SpiceBot_Channels/Channels_Command.py +++ b/sopel_modules/SpiceBot_Channels/Channels_Command.py @@ -6,7 +6,7 @@ import sopel.module import spicemanip -from sopel_modules.SpiceBot_Events.System import bot_events_check +from sopel_modules.SpiceBot_Events.System import bot_events_check, botevents from sopel_modules.SpiceBot_SBTools import ( sopel_triggerargs, inlist, channel_privs, join_all_channels, channel_list_current, @@ -17,7 +17,7 @@ from .Channels import bot_part_empty @sopel.module.nickname_commands('channels', 'channel') def nickname_comand_channels(bot, trigger): - while not bot_events_check(bot, '1004'): + while not bot_events_check(bot, botevents.BOT_LOADED): pass triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'nickname_command') diff --git a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py index 9651618..2d9e2ce 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py +++ b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py @@ -7,7 +7,7 @@ import sopel.module import os -from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger +from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger, botevents from sopel_modules.SpiceBot_SBTools import bot_logging import spicemanip @@ -170,7 +170,7 @@ def shutdown(bot): del bot.memory["SpiceBot_CommandsQuery"] -@sopel.module.event('1004') +@sopel.module.event(botevents.BOT_LOADED) @sopel.module.rule('.*') def bot_events_complete(bot, trigger): bot_events_recieved(bot, trigger.event) diff --git a/sopel_modules/SpiceBot_Events/Events.py b/sopel_modules/SpiceBot_Events/Events.py index 9613516..730cb4f 100644 --- a/sopel_modules/SpiceBot_Events/Events.py +++ b/sopel_modules/SpiceBot_Events/Events.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel.module from sopel.trigger import PreTrigger -from .System import bot_events_trigger, bot_events_recieved, bot_events_startup_check, bot_events_setup_check +from .System import bot_events_trigger, bot_events_recieved, bot_events_startup_check, bot_events_setup_check, botevents from sopel_modules.SpiceBot_SBTools import bot_logging import time @@ -14,35 +14,35 @@ import time @sopel.module.event('001') @sopel.module.rule('.*') def bot_startup_connection(bot, trigger): - bot_events_trigger(bot, 1001, "Welcome to the SpiceBot Events System") + bot_events_trigger(bot, botevents.BOT_WELCOME, "Welcome to the SpiceBot Events System") while not len(bot.channels.keys()) > 0: pass time.sleep(1) - bot_events_trigger(bot, 1003, "Bot Connected to IRC") + bot_events_trigger(bot, botevents.BOT_CONNECTED, "Bot Connected to IRC") -@sopel.module.event('1001') +@sopel.module.event(botevents.BOT_WELCOME) @sopel.module.rule('.*') def bot_events_start(bot, trigger): bot_logging(bot, 'SpiceBot_Events', trigger.args[1], True) bot_events_recieved(bot, trigger.event) - bot_events_trigger(bot, 1002, "Ready To Process module setup procedures") + bot_events_trigger(bot, botevents.BOT_READY, "Ready To Process module setup procedures") while not bot_events_startup_check(bot): pass - bot_events_trigger(bot, 1004, "All registered modules setup procedures have completed") + bot_events_trigger(bot, botevents.BOT_LOADED, "All registered modules setup procedures have completed") -@sopel.module.event('1002') +@sopel.module.event(botevents.BOT_READY) @sopel.module.rule('.*') def bot_events_ready(bot, trigger): bot_logging(bot, 'SpiceBot_Events', trigger.args[1], True) bot_events_recieved(bot, trigger.event) -@sopel.module.event('1003') +@sopel.module.event(botevents.BOT_CONNECTED) @sopel.module.rule('.*') def bot_events_connected(bot, trigger): bot_logging(bot, 'SpiceBot_Events', trigger.args[1], True) @@ -65,7 +65,7 @@ def bot_events_connected(bot, trigger): return -@sopel.module.event('1004') +@sopel.module.event(botevents.BOT_LOADED) @sopel.module.rule('.*') def bot_events_complete(bot, trigger): bot_logging(bot, 'SpiceBot_Events', trigger.args[1], True) diff --git a/sopel_modules/SpiceBot_Events/System.py b/sopel_modules/SpiceBot_Events/System.py index b4e0dce..4ba3dd2 100644 --- a/sopel_modules/SpiceBot_Events/System.py +++ b/sopel_modules/SpiceBot_Events/System.py @@ -12,7 +12,7 @@ from sopel_modules.SpiceBot_SBTools import bot_logging def setup(bot): bot_logging(bot, 'SpiceBot_Events', "Starting setup procedure") bot_events_setup_check(bot) - bot_events_startup_register(bot, ['1001', '1002', '1003']) + bot_events_startup_register(bot, [botevents.BOT_WELCOME, botevents.BOT_READY, botevents.BOT_CONNECTED]) def shutdown(bot): @@ -25,7 +25,7 @@ def bot_events_trigger(bot, number, message): bot_events_setup_check(bot) bot.memory["SpiceBot_Events"]["triggers"][str(number)] = message - if str(number) in ['1001', '1002', '1003']: + if str(number) in [botevents.BOT_WELCOME, botevents.BOT_READY, botevents.BOT_CONNECTED]: pretrigger = PreTrigger( bot.nick, ":SpiceBot_Events " + str(number) + " " + str(bot.nick) + " :" + message @@ -88,3 +88,25 @@ def bot_events_startup_check(bot): return False else: return True + + +def assign_event_number(): + return 5 + + +class botevents(object): + """An dynamic listing of all the notable Bot numeric events. + + Events contained in this module will utilize the 1000-range + + All Other events will be tagged with a randomly generated + 4-digit number above 2000. + + This allows you to do, for example, ``@module.event(botevents.BOT_WELCOME)`` + rather than ``@module.event('1000')`` + """ + + BOT_WELCOME = '1001' + BOT_READY = '1002' + BOT_CONNECTED = '1003' + BOT_LOADED = '1004' diff --git a/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py b/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py index 23c8231..41c5f69 100644 --- a/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py +++ b/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel.module from sopel_modules.SpiceBot_SBTools import sopel_triggerargs -from sopel_modules.SpiceBot_Events.System import bot_events_check, bot_events_recieved +from sopel_modules.SpiceBot_Events.System import bot_events_check, bot_events_recieved, botevents def setup(bot): @@ -18,7 +18,7 @@ def shutdown(bot): del bot.memory["SpiceBot_InvalidCommand"] -@sopel.module.event('1004') +@sopel.module.event(botevents.BOT_LOADED) @sopel.module.rule('.*') def bot_events_complete(bot, trigger): bot_events_recieved(bot, trigger.event) @@ -31,7 +31,7 @@ def bot_events_complete(bot, trigger): def InvalidCommand_triggers(bot, trigger): return - while not bot_events_check(bot, ['1004', '2002']): + while not bot_events_check(bot, [botevents.BOT_LOADED, '2002']): pass triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'prefix_command') diff --git a/sopel_modules/SpiceBot_Logs/Logs.py b/sopel_modules/SpiceBot_Logs/Logs.py index b376bd2..3a9884c 100644 --- a/sopel_modules/SpiceBot_Logs/Logs.py +++ b/sopel_modules/SpiceBot_Logs/Logs.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel.module from sopel.config.types import StaticSection, ValidatedAttribute -from sopel_modules.SpiceBot_SBTools import bot_logging +from sopel_modules.SpiceBot_SBTools import bot_logging, botevents from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger import os @@ -43,7 +43,7 @@ def shutdown(bot): del bot.memory["SpiceBot_Logs"] -@sopel.module.event('1003') +@sopel.module.event(botevents.BOT_CONNECTED) @sopel.module.rule('.*') def join_log_channel(bot, trigger): bot_events_recieved(bot, trigger.event) diff --git a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py index 68836c5..a964f87 100644 --- a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py +++ b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py @@ -4,12 +4,12 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel.module -from sopel_modules.SpiceBot_Events.System import bot_events_recieved, bot_events_trigger +from sopel_modules.SpiceBot_Events.System import bot_events_recieved, bot_events_trigger, botevents from sopel_modules.SpiceBot_SBTools import humanized_time, bot_logging import time -@sopel.module.event('1003') +@sopel.module.event(botevents.BOT_CONNECTED) @sopel.module.rule('.*') def bot_startup_monologue_start(bot, trigger): bot_events_recieved(bot, trigger.event) @@ -49,7 +49,7 @@ def bot_startup_monologue_channels(bot, trigger): bot_events_trigger(bot, 2010, "SpiceBot_StartupMonologue") -@sopel.module.event('1004') +@sopel.module.event(botevents.BOT_LOADED) @sopel.module.rule('.*') def bot_startup_monologue_display(bot, trigger): bot_events_recieved(bot, trigger.event) From df68433d410346500fa6953a5b2d062c272081b6 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 14 May 2019 11:29:22 -0400 Subject: [PATCH 48/80] remove old debug line --- sopel_modules/SpiceBot_Events/System.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot_Events/System.py b/sopel_modules/SpiceBot_Events/System.py index 4ba3dd2..4f85621 100644 --- a/sopel_modules/SpiceBot_Events/System.py +++ b/sopel_modules/SpiceBot_Events/System.py @@ -84,7 +84,6 @@ def bot_events_startup_check(bot): notcomplete.append(str(startupitem)) if len(notcomplete): - # bot_logging(bot, 'SpiceBot_Events', str(notcomplete)) return False else: return True @@ -103,7 +102,7 @@ class botevents(object): 4-digit number above 2000. This allows you to do, for example, ``@module.event(botevents.BOT_WELCOME)`` - rather than ``@module.event('1000')`` + rather than ``@module.event('1001')`` """ BOT_WELCOME = '1001' From 902604d5083e42bf14851943628727bdaf909e12 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 14 May 2019 11:42:32 -0400 Subject: [PATCH 49/80] Attempt dynamic class numbers --- sopel_modules/SpiceBot_Channels/Channels.py | 9 +++++---- sopel_modules/SpiceBot_Events/System.py | 13 ++++++++++--- .../StartupMonologue_Display.py | 2 +- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/sopel_modules/SpiceBot_Channels/Channels.py b/sopel_modules/SpiceBot_Channels/Channels.py index 19ba598..359c637 100644 --- a/sopel_modules/SpiceBot_Channels/Channels.py +++ b/sopel_modules/SpiceBot_Channels/Channels.py @@ -6,7 +6,7 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi import sopel.module from sopel.config.types import StaticSection, ValidatedAttribute, ListAttribute -from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger, botevents +from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger, botevents, assign_event_number from sopel_modules.SpiceBot_SBTools import ( join_all_channels, chanadmin_all_channels, channel_list_current, @@ -35,7 +35,8 @@ def configure(config): def setup(bot): bot_logging(bot, 'SpiceBot_Channels', "Starting setup procedure") - bot_events_startup_register(bot, ['2001']) + assign_event_number(bot, "BOT_CHANNELS") + bot_events_startup_register(bot, [botevents.BOT_CHANNELS]) bot.config.define_section("SpiceBot_Channels", SpiceBot_Channels_MainSection, validate=False) @@ -75,7 +76,7 @@ def trigger_channel_list_initial(bot, trigger): channel_list_current(bot) foundchannelcount = len(bot.memory['SpiceBot_Channels']['channels'].keys()) bot_logging(bot, 'SpiceBot_Channels', "Channel listing finished! " + str(foundchannelcount) + " channel(s) found.") - bot_events_trigger(bot, 2001, "SpiceBot_Channels") + bot_events_trigger(bot, botevents.BOT_CHANNELS, "SpiceBot_Channels") join_all_channels(bot) chanadmin_all_channels(bot) @@ -124,7 +125,7 @@ def bot_part_empty(bot): del bot.memory['SpiceBot_Channels']['channels'][channel.lower()] -@sopel.module.event('2001') +@sopel.module.event(botevents.BOT_CHANNELS) @sopel.module.rule('.*') def bot_events_setup(bot, trigger): bot_events_recieved(bot, trigger.event) diff --git a/sopel_modules/SpiceBot_Events/System.py b/sopel_modules/SpiceBot_Events/System.py index 4f85621..50adf3d 100644 --- a/sopel_modules/SpiceBot_Events/System.py +++ b/sopel_modules/SpiceBot_Events/System.py @@ -8,6 +8,8 @@ from sopel.trigger import PreTrigger from sopel_modules.SpiceBot_SBTools import bot_logging +from random import randint + def setup(bot): bot_logging(bot, 'SpiceBot_Events', "Starting setup procedure") @@ -38,7 +40,8 @@ def bot_events_trigger(bot, number, message): def bot_events_setup_check(bot): if "SpiceBot_Events" not in bot.memory: - bot.memory["SpiceBot_Events"] = {"triggers": {}, "startup": [], "loaded": [], "queue": []} + bot.memory["SpiceBot_Events"] = {"triggers": {}, "startup": [], "loaded": [], "queue": [], + "usednumbers": [botevents.BOT_WELCOME, botevents.BOT_READY, botevents.BOT_CONNECTED, botevents.BOT_LOADED]} def bot_events_check(bot, listreq): @@ -89,8 +92,12 @@ def bot_events_startup_check(bot): return True -def assign_event_number(): - return 5 +def assign_event_number(bot, eventname): + eventnumber = 0 + while not eventnumber and eventnumber not in bot.memory["SpiceBot_Events"]["usednumbers"]: + eventnumber = randint(2000, 9999) + exec("botevents." + str(eventname).upper() + " = " + str(eventnumber)) + return eventnumber class botevents(object): diff --git a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py index a964f87..810f667 100644 --- a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py +++ b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py @@ -37,7 +37,7 @@ def bot_startup_monologue_commands(bot, trigger): bot_events_trigger(bot, 2011, "SpiceBot_StartupMonologue") -@sopel.module.event('2001') +@sopel.module.event(botevents.BOT_CHANNELS) @sopel.module.rule('.*') def bot_startup_monologue_channels(bot, trigger): bot_events_recieved(bot, trigger.event) From 6fafa9714b18eb799eed3461b20938484c1ac2b8 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 14 May 2019 12:01:17 -0400 Subject: [PATCH 50/80] repair errors --- sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py b/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py index 939d823..1d549a5 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py +++ b/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py @@ -28,7 +28,7 @@ def query_detection(bot, trigger): return commands_list = dict() - for commandstype in bot.memory['SpiceBot_CommandsQuery']['commands']["commandstype"].keys(): + for commandstype in bot.memory['SpiceBot_CommandsQuery']['commands'].keys(): if commandstype not in ['rule', 'nickname']: for com in bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype].keys(): if com not in commands_list.keys(): From 74bf4d763af4f412db8f9a45876ebd2f5108e31d Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 14 May 2019 12:57:31 -0400 Subject: [PATCH 51/80] Better dynamic creation of event numbers --- sopel_modules/SpiceBot_Channels/Channels.py | 3 +-- sopel_modules/SpiceBot_Events/System.py | 23 ++++++++++++--------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/sopel_modules/SpiceBot_Channels/Channels.py b/sopel_modules/SpiceBot_Channels/Channels.py index 359c637..34db283 100644 --- a/sopel_modules/SpiceBot_Channels/Channels.py +++ b/sopel_modules/SpiceBot_Channels/Channels.py @@ -6,7 +6,7 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi import sopel.module from sopel.config.types import StaticSection, ValidatedAttribute, ListAttribute -from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger, botevents, assign_event_number +from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger, botevents from sopel_modules.SpiceBot_SBTools import ( join_all_channels, chanadmin_all_channels, channel_list_current, @@ -35,7 +35,6 @@ def configure(config): def setup(bot): bot_logging(bot, 'SpiceBot_Channels', "Starting setup procedure") - assign_event_number(bot, "BOT_CHANNELS") bot_events_startup_register(bot, [botevents.BOT_CHANNELS]) bot.config.define_section("SpiceBot_Channels", SpiceBot_Channels_MainSection, validate=False) diff --git a/sopel_modules/SpiceBot_Events/System.py b/sopel_modules/SpiceBot_Events/System.py index 50adf3d..a3ea46c 100644 --- a/sopel_modules/SpiceBot_Events/System.py +++ b/sopel_modules/SpiceBot_Events/System.py @@ -40,8 +40,7 @@ def bot_events_trigger(bot, number, message): def bot_events_setup_check(bot): if "SpiceBot_Events" not in bot.memory: - bot.memory["SpiceBot_Events"] = {"triggers": {}, "startup": [], "loaded": [], "queue": [], - "usednumbers": [botevents.BOT_WELCOME, botevents.BOT_READY, botevents.BOT_CONNECTED, botevents.BOT_LOADED]} + bot.memory["SpiceBot_Events"] = {"triggers": {}, "startup": [], "loaded": [], "queue": []} def bot_events_check(bot, listreq): @@ -92,14 +91,6 @@ def bot_events_startup_check(bot): return True -def assign_event_number(bot, eventname): - eventnumber = 0 - while not eventnumber and eventnumber not in bot.memory["SpiceBot_Events"]["usednumbers"]: - eventnumber = randint(2000, 9999) - exec("botevents." + str(eventname).upper() + " = " + str(eventnumber)) - return eventnumber - - class botevents(object): """An dynamic listing of all the notable Bot numeric events. @@ -112,7 +103,19 @@ class botevents(object): rather than ``@module.event('1001')`` """ + usednumbers = [] + BOT_WELCOME = '1001' BOT_READY = '1002' BOT_CONNECTED = '1003' BOT_LOADED = '1004' + + def __getattr__(self, name): + if hasattr(self, name): + return self.__getattribute__(name) + else: + eventnumber = 0 + while not eventnumber and eventnumber not in self.usednumbers: + eventnumber = randint(2000, 9999) + exec("self." + str(name).upper() + " = " + str(eventnumber)) + return eventnumber From 37cdefacf1391f8d3304894f0ed59a21ba4de840 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 14 May 2019 13:05:36 -0400 Subject: [PATCH 52/80] Fix bad import --- sopel_modules/SpiceBot_Logs/Logs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot_Logs/Logs.py b/sopel_modules/SpiceBot_Logs/Logs.py index 3a9884c..4be59f0 100644 --- a/sopel_modules/SpiceBot_Logs/Logs.py +++ b/sopel_modules/SpiceBot_Logs/Logs.py @@ -5,8 +5,8 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel.module from sopel.config.types import StaticSection, ValidatedAttribute -from sopel_modules.SpiceBot_SBTools import bot_logging, botevents -from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger +from sopel_modules.SpiceBot_SBTools import bot_logging +from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger, botevents import os From b8a1ff2301d268d34e13e50d5545eae84e98f27e Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 14 May 2019 14:41:27 -0400 Subject: [PATCH 53/80] try this instead --- sopel_modules/SpiceBot_Events/System.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/sopel_modules/SpiceBot_Events/System.py b/sopel_modules/SpiceBot_Events/System.py index a3ea46c..795ba58 100644 --- a/sopel_modules/SpiceBot_Events/System.py +++ b/sopel_modules/SpiceBot_Events/System.py @@ -103,19 +103,21 @@ class botevents(object): rather than ``@module.event('1001')`` """ - usednumbers = [] + def __init__(self): - BOT_WELCOME = '1001' - BOT_READY = '1002' - BOT_CONNECTED = '1003' - BOT_LOADED = '1004' + self.usednumbers = ['0', '1001', '1002', '1003', '1004'] + self.BOT_WELCOME = '1001' + self.BOT_READY = '1002' + self.BOT_CONNECTED = '1003' + self.BOT_LOADED = '1004' def __getattr__(self, name): if hasattr(self, name): return self.__getattribute__(name) else: eventnumber = 0 - while not eventnumber and eventnumber not in self.usednumbers: + while str(eventnumber) not in self.usednumbers: eventnumber = randint(2000, 9999) exec("self." + str(name).upper() + " = " + str(eventnumber)) + self.usednumbers.append(str(eventnumber)) return eventnumber From 867f33e01d401c92de0fb906fb4f1e5b0cf71852 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 14 May 2019 14:55:55 -0400 Subject: [PATCH 54/80] test --- sopel_modules/SpiceBot_Events/System.py | 31 ++++++++++--------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/sopel_modules/SpiceBot_Events/System.py b/sopel_modules/SpiceBot_Events/System.py index 795ba58..106fa37 100644 --- a/sopel_modules/SpiceBot_Events/System.py +++ b/sopel_modules/SpiceBot_Events/System.py @@ -102,22 +102,15 @@ class botevents(object): This allows you to do, for example, ``@module.event(botevents.BOT_WELCOME)`` rather than ``@module.event('1001')`` """ - - def __init__(self): - - self.usednumbers = ['0', '1001', '1002', '1003', '1004'] - self.BOT_WELCOME = '1001' - self.BOT_READY = '1002' - self.BOT_CONNECTED = '1003' - self.BOT_LOADED = '1004' - - def __getattr__(self, name): - if hasattr(self, name): - return self.__getattribute__(name) - else: - eventnumber = 0 - while str(eventnumber) not in self.usednumbers: - eventnumber = randint(2000, 9999) - exec("self." + str(name).upper() + " = " + str(eventnumber)) - self.usednumbers.append(str(eventnumber)) - return eventnumber + usednumbers = ['0', '1001', '1002', '1003', '1004'] + try: + BOT_WELCOME = '1001' + BOT_READY = '1002' + BOT_CONNECTED = '1003' + BOT_LOADED = '1004' + except AttributeError: + eventnumber = 0 + while str(eventnumber) not in usednumbers: + eventnumber = randint(2000, 9999) + exec(str(object).upper() + " = " + str(eventnumber)) + usednumbers.append(str(eventnumber)) From 92ecaa526a662f3f8712e2956a3cc4b3d5a79f0e Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 14 May 2019 15:07:16 -0400 Subject: [PATCH 55/80] test --- sopel_modules/SpiceBot_Events/System.py | 36 +++++++++++++++++-------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/sopel_modules/SpiceBot_Events/System.py b/sopel_modules/SpiceBot_Events/System.py index 106fa37..edca0ec 100644 --- a/sopel_modules/SpiceBot_Events/System.py +++ b/sopel_modules/SpiceBot_Events/System.py @@ -91,26 +91,40 @@ def bot_events_startup_check(bot): return True -class botevents(object): +def botevents(name): + if hasattr(boteventsclass, name): + return boteventsclass.__getattribute__(name) + else: + eventnumber = 0 + while eventnumber not in boteventsclass.usednumbers: + eventnumber = randint(2000, 9999) + exec("self." + str(name).upper() + " = " + str(eventnumber)) + boteventsclass.usednumbers.append(str(eventnumber)) + return eventnumber + + +class boteventsclass(object): """An dynamic listing of all the notable Bot numeric events. Events contained in this module will utilize the 1000-range All Other events will be tagged with a randomly generated - 4-digit number above 2000. + 4-digit number above 2000 via the function. This allows you to do, for example, ``@module.event(botevents.BOT_WELCOME)`` rather than ``@module.event('1001')`` """ usednumbers = ['0', '1001', '1002', '1003', '1004'] - try: - BOT_WELCOME = '1001' - BOT_READY = '1002' - BOT_CONNECTED = '1003' - BOT_LOADED = '1004' - except AttributeError: + + BOT_WELCOME = '1001' + BOT_READY = '1002' + BOT_CONNECTED = '1003' + BOT_LOADED = '1004' + + def __getattr__(self, attr): eventnumber = 0 - while str(eventnumber) not in usednumbers: + while eventnumber not in self.usednumbers: eventnumber = randint(2000, 9999) - exec(str(object).upper() + " = " + str(eventnumber)) - usednumbers.append(str(eventnumber)) + setattr(self, str(attr).upper(), str(eventnumber)) + self.usednumbers.append(str(eventnumber)) + return eventnumber From 64618ac96069d23a78cc70e672961f0f5b6e70e1 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 14 May 2019 15:07:30 -0400 Subject: [PATCH 56/80] class --- sopel_modules/SpiceBot_Events/System.py | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/sopel_modules/SpiceBot_Events/System.py b/sopel_modules/SpiceBot_Events/System.py index edca0ec..3cd232a 100644 --- a/sopel_modules/SpiceBot_Events/System.py +++ b/sopel_modules/SpiceBot_Events/System.py @@ -91,19 +91,7 @@ def bot_events_startup_check(bot): return True -def botevents(name): - if hasattr(boteventsclass, name): - return boteventsclass.__getattribute__(name) - else: - eventnumber = 0 - while eventnumber not in boteventsclass.usednumbers: - eventnumber = randint(2000, 9999) - exec("self." + str(name).upper() + " = " + str(eventnumber)) - boteventsclass.usednumbers.append(str(eventnumber)) - return eventnumber - - -class boteventsclass(object): +class botevents(object): """An dynamic listing of all the notable Bot numeric events. Events contained in this module will utilize the 1000-range From cb961399cd54828622e23bf1d95f6e187c68ce46 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 14 May 2019 15:14:42 -0400 Subject: [PATCH 57/80] init test --- sopel_modules/SpiceBot_Events/System.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/sopel_modules/SpiceBot_Events/System.py b/sopel_modules/SpiceBot_Events/System.py index 3cd232a..d802602 100644 --- a/sopel_modules/SpiceBot_Events/System.py +++ b/sopel_modules/SpiceBot_Events/System.py @@ -102,12 +102,13 @@ class botevents(object): This allows you to do, for example, ``@module.event(botevents.BOT_WELCOME)`` rather than ``@module.event('1001')`` """ - usednumbers = ['0', '1001', '1002', '1003', '1004'] + def __init__(self): + self.usednumbers = ['0', '1001', '1002', '1003', '1004'] - BOT_WELCOME = '1001' - BOT_READY = '1002' - BOT_CONNECTED = '1003' - BOT_LOADED = '1004' + self.BOT_WELCOME = '1001' + self.BOT_READY = '1002' + self.BOT_CONNECTED = '1003' + self.BOT_LOADED = '1004' def __getattr__(self, attr): eventnumber = 0 From 2347f4c5406a70e5e8c9ff43deb78770a4c8327a Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 14 May 2019 15:31:33 -0400 Subject: [PATCH 58/80] test --- sopel_modules/SpiceBot_Events/System.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/sopel_modules/SpiceBot_Events/System.py b/sopel_modules/SpiceBot_Events/System.py index d802602..2d3eb28 100644 --- a/sopel_modules/SpiceBot_Events/System.py +++ b/sopel_modules/SpiceBot_Events/System.py @@ -97,18 +97,17 @@ class botevents(object): Events contained in this module will utilize the 1000-range All Other events will be tagged with a randomly generated - 4-digit number above 2000 via the function. + 4-digit number above 2000. This allows you to do, for example, ``@module.event(botevents.BOT_WELCOME)`` rather than ``@module.event('1001')`` """ - def __init__(self): - self.usednumbers = ['0', '1001', '1002', '1003', '1004'] + usednumbers = ['0', '1001', '1002', '1003', '1004'] - self.BOT_WELCOME = '1001' - self.BOT_READY = '1002' - self.BOT_CONNECTED = '1003' - self.BOT_LOADED = '1004' + BOT_WELCOME = '1001' + BOT_READY = '1002' + BOT_CONNECTED = '1003' + BOT_LOADED = '1004' def __getattr__(self, attr): eventnumber = 0 @@ -116,4 +115,3 @@ class botevents(object): eventnumber = randint(2000, 9999) setattr(self, str(attr).upper(), str(eventnumber)) self.usednumbers.append(str(eventnumber)) - return eventnumber From 2cf80a320fe21cc4e9a2c847d46ab30ffe0be127 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 14 May 2019 16:10:54 -0400 Subject: [PATCH 59/80] botevents instance --- sopel_modules/SpiceBot_AI/AI.py | 3 +- sopel_modules/SpiceBot_Channels/Channels.py | 3 +- .../SpiceBot_Channels/Channels_Command.py | 3 +- .../SpiceBot_CommandsQuery/CommandsQuery.py | 3 +- sopel_modules/SpiceBot_Events/Events.py | 3 +- sopel_modules/SpiceBot_Events/System.py | 55 ++++++++++--------- .../SpiceBot_InvalidCommand/InvalidCommand.py | 3 +- sopel_modules/SpiceBot_Logs/Logs.py | 3 +- .../StartupMonologue_Display.py | 3 +- 9 files changed, 45 insertions(+), 34 deletions(-) diff --git a/sopel_modules/SpiceBot_AI/AI.py b/sopel_modules/SpiceBot_AI/AI.py index 8fd489a..70b1e9a 100644 --- a/sopel_modules/SpiceBot_AI/AI.py +++ b/sopel_modules/SpiceBot_AI/AI.py @@ -7,7 +7,8 @@ import sopel.module import spicemanip from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, googlesearch, bot_privs, inlist, inlist_match, similar_list -from sopel_modules.SpiceBot_Events.System import bot_events_check, botevents +from sopel_modules.SpiceBot_Events.System import bot_events_check, BotEvents +botevents = BotEvents() @sopel.module.nickname_commands('(.*)') diff --git a/sopel_modules/SpiceBot_Channels/Channels.py b/sopel_modules/SpiceBot_Channels/Channels.py index 34db283..d4edebb 100644 --- a/sopel_modules/SpiceBot_Channels/Channels.py +++ b/sopel_modules/SpiceBot_Channels/Channels.py @@ -6,12 +6,13 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi import sopel.module from sopel.config.types import StaticSection, ValidatedAttribute, ListAttribute -from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger, botevents +from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger, BotEvents from sopel_modules.SpiceBot_SBTools import ( join_all_channels, chanadmin_all_channels, channel_list_current, bot_logging ) +botevents = BotEvents() import spicemanip diff --git a/sopel_modules/SpiceBot_Channels/Channels_Command.py b/sopel_modules/SpiceBot_Channels/Channels_Command.py index c7e69bc..1a48435 100644 --- a/sopel_modules/SpiceBot_Channels/Channels_Command.py +++ b/sopel_modules/SpiceBot_Channels/Channels_Command.py @@ -6,12 +6,13 @@ import sopel.module import spicemanip -from sopel_modules.SpiceBot_Events.System import bot_events_check, botevents +from sopel_modules.SpiceBot_Events.System import bot_events_check, BotEvents from sopel_modules.SpiceBot_SBTools import ( sopel_triggerargs, inlist, channel_privs, join_all_channels, channel_list_current, ) from .Channels import bot_part_empty +botevents = BotEvents() @sopel.module.nickname_commands('channels', 'channel') diff --git a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py index 2d9e2ce..01bf797 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py +++ b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py @@ -7,8 +7,9 @@ import sopel.module import os -from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger, botevents +from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger, BotEvents from sopel_modules.SpiceBot_SBTools import bot_logging +botevents = BotEvents() import spicemanip diff --git a/sopel_modules/SpiceBot_Events/Events.py b/sopel_modules/SpiceBot_Events/Events.py index 730cb4f..46986c3 100644 --- a/sopel_modules/SpiceBot_Events/Events.py +++ b/sopel_modules/SpiceBot_Events/Events.py @@ -5,8 +5,9 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel.module from sopel.trigger import PreTrigger -from .System import bot_events_trigger, bot_events_recieved, bot_events_startup_check, bot_events_setup_check, botevents +from .System import bot_events_trigger, bot_events_recieved, bot_events_startup_check, bot_events_setup_check, BotEvents from sopel_modules.SpiceBot_SBTools import bot_logging +botevents = BotEvents() import time diff --git a/sopel_modules/SpiceBot_Events/System.py b/sopel_modules/SpiceBot_Events/System.py index 2d3eb28..455b49e 100644 --- a/sopel_modules/SpiceBot_Events/System.py +++ b/sopel_modules/SpiceBot_Events/System.py @@ -11,6 +11,35 @@ from sopel_modules.SpiceBot_SBTools import bot_logging from random import randint +class BotEvents(object): + """An dynamic listing of all the notable Bot numeric events. + + Events contained in this module will utilize the 1000-range + + All Other events will be tagged with a randomly generated + 4-digit number above 2000. + + This allows you to do, for example, ``@module.event(botevents.BOT_WELCOME)`` + rather than ``@module.event('1001')`` + """ + usednumbers = ['0', '1001', '1002', '1003', '1004'] + + BOT_WELCOME = '1001' + BOT_READY = '1002' + BOT_CONNECTED = '1003' + BOT_LOADED = '1004' + + def __getattr__(self, attr): + eventnumber = 0 + while eventnumber not in self.usednumbers: + eventnumber = randint(2000, 9999) + setattr(self, str(attr).upper(), str(eventnumber)) + self.usednumbers.append(str(eventnumber)) + + +botevents = BotEvents() + + def setup(bot): bot_logging(bot, 'SpiceBot_Events', "Starting setup procedure") bot_events_setup_check(bot) @@ -89,29 +118,3 @@ def bot_events_startup_check(bot): return False else: return True - - -class botevents(object): - """An dynamic listing of all the notable Bot numeric events. - - Events contained in this module will utilize the 1000-range - - All Other events will be tagged with a randomly generated - 4-digit number above 2000. - - This allows you to do, for example, ``@module.event(botevents.BOT_WELCOME)`` - rather than ``@module.event('1001')`` - """ - usednumbers = ['0', '1001', '1002', '1003', '1004'] - - BOT_WELCOME = '1001' - BOT_READY = '1002' - BOT_CONNECTED = '1003' - BOT_LOADED = '1004' - - def __getattr__(self, attr): - eventnumber = 0 - while eventnumber not in self.usednumbers: - eventnumber = randint(2000, 9999) - setattr(self, str(attr).upper(), str(eventnumber)) - self.usednumbers.append(str(eventnumber)) diff --git a/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py b/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py index 41c5f69..71dc9ae 100644 --- a/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py +++ b/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py @@ -5,7 +5,8 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel.module from sopel_modules.SpiceBot_SBTools import sopel_triggerargs -from sopel_modules.SpiceBot_Events.System import bot_events_check, bot_events_recieved, botevents +from sopel_modules.SpiceBot_Events.System import bot_events_check, bot_events_recieved, BotEvents +botevents = BotEvents() def setup(bot): diff --git a/sopel_modules/SpiceBot_Logs/Logs.py b/sopel_modules/SpiceBot_Logs/Logs.py index 4be59f0..dc4584b 100644 --- a/sopel_modules/SpiceBot_Logs/Logs.py +++ b/sopel_modules/SpiceBot_Logs/Logs.py @@ -6,7 +6,8 @@ import sopel.module from sopel.config.types import StaticSection, ValidatedAttribute from sopel_modules.SpiceBot_SBTools import bot_logging -from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger, botevents +from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger, BotEvents +botevents = BotEvents() import os diff --git a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py index 810f667..6fad94c 100644 --- a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py +++ b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py @@ -4,8 +4,9 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel.module -from sopel_modules.SpiceBot_Events.System import bot_events_recieved, bot_events_trigger, botevents +from sopel_modules.SpiceBot_Events.System import bot_events_recieved, bot_events_trigger, BotEvents from sopel_modules.SpiceBot_SBTools import humanized_time, bot_logging +botevents = BotEvents() import time From ce5ed8e536be23ea64e0732e873729aa6c14c45d Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 14 May 2019 16:14:59 -0400 Subject: [PATCH 60/80] beter instance handling --- sopel_modules/SpiceBot_AI/AI.py | 3 +-- sopel_modules/SpiceBot_Channels/Channels.py | 3 +-- .../SpiceBot_Channels/Channels_Command.py | 3 +-- .../SpiceBot_CommandsQuery/CommandsQuery.py | 3 +-- sopel_modules/SpiceBot_Events/Events.py | 3 +-- sopel_modules/SpiceBot_Events/System.py | 22 +++++++++---------- .../SpiceBot_InvalidCommand/InvalidCommand.py | 3 +-- sopel_modules/SpiceBot_Logs/Logs.py | 3 +-- .../StartupMonologue_Display.py | 4 ++-- 9 files changed, 20 insertions(+), 27 deletions(-) diff --git a/sopel_modules/SpiceBot_AI/AI.py b/sopel_modules/SpiceBot_AI/AI.py index 70b1e9a..8fd489a 100644 --- a/sopel_modules/SpiceBot_AI/AI.py +++ b/sopel_modules/SpiceBot_AI/AI.py @@ -7,8 +7,7 @@ import sopel.module import spicemanip from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, googlesearch, bot_privs, inlist, inlist_match, similar_list -from sopel_modules.SpiceBot_Events.System import bot_events_check, BotEvents -botevents = BotEvents() +from sopel_modules.SpiceBot_Events.System import bot_events_check, botevents @sopel.module.nickname_commands('(.*)') diff --git a/sopel_modules/SpiceBot_Channels/Channels.py b/sopel_modules/SpiceBot_Channels/Channels.py index d4edebb..34db283 100644 --- a/sopel_modules/SpiceBot_Channels/Channels.py +++ b/sopel_modules/SpiceBot_Channels/Channels.py @@ -6,13 +6,12 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi import sopel.module from sopel.config.types import StaticSection, ValidatedAttribute, ListAttribute -from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger, BotEvents +from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger, botevents from sopel_modules.SpiceBot_SBTools import ( join_all_channels, chanadmin_all_channels, channel_list_current, bot_logging ) -botevents = BotEvents() import spicemanip diff --git a/sopel_modules/SpiceBot_Channels/Channels_Command.py b/sopel_modules/SpiceBot_Channels/Channels_Command.py index 1a48435..c7e69bc 100644 --- a/sopel_modules/SpiceBot_Channels/Channels_Command.py +++ b/sopel_modules/SpiceBot_Channels/Channels_Command.py @@ -6,13 +6,12 @@ import sopel.module import spicemanip -from sopel_modules.SpiceBot_Events.System import bot_events_check, BotEvents +from sopel_modules.SpiceBot_Events.System import bot_events_check, botevents from sopel_modules.SpiceBot_SBTools import ( sopel_triggerargs, inlist, channel_privs, join_all_channels, channel_list_current, ) from .Channels import bot_part_empty -botevents = BotEvents() @sopel.module.nickname_commands('channels', 'channel') diff --git a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py index 01bf797..2d9e2ce 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py +++ b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py @@ -7,9 +7,8 @@ import sopel.module import os -from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger, BotEvents +from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger, botevents from sopel_modules.SpiceBot_SBTools import bot_logging -botevents = BotEvents() import spicemanip diff --git a/sopel_modules/SpiceBot_Events/Events.py b/sopel_modules/SpiceBot_Events/Events.py index 46986c3..730cb4f 100644 --- a/sopel_modules/SpiceBot_Events/Events.py +++ b/sopel_modules/SpiceBot_Events/Events.py @@ -5,9 +5,8 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel.module from sopel.trigger import PreTrigger -from .System import bot_events_trigger, bot_events_recieved, bot_events_startup_check, bot_events_setup_check, BotEvents +from .System import bot_events_trigger, bot_events_recieved, bot_events_startup_check, bot_events_setup_check, botevents from sopel_modules.SpiceBot_SBTools import bot_logging -botevents = BotEvents() import time diff --git a/sopel_modules/SpiceBot_Events/System.py b/sopel_modules/SpiceBot_Events/System.py index 455b49e..1be32f8 100644 --- a/sopel_modules/SpiceBot_Events/System.py +++ b/sopel_modules/SpiceBot_Events/System.py @@ -11,6 +11,17 @@ from sopel_modules.SpiceBot_SBTools import bot_logging from random import randint +def setup(bot): + bot_logging(bot, 'SpiceBot_Events', "Starting setup procedure") + bot_events_setup_check(bot) + bot_events_startup_register(bot, [botevents.BOT_WELCOME, botevents.BOT_READY, botevents.BOT_CONNECTED]) + + +def shutdown(bot): + if "SpiceBot_Events" in bot.memory: + del bot.memory["SpiceBot_Events"] + + class BotEvents(object): """An dynamic listing of all the notable Bot numeric events. @@ -40,17 +51,6 @@ class BotEvents(object): botevents = BotEvents() -def setup(bot): - bot_logging(bot, 'SpiceBot_Events', "Starting setup procedure") - bot_events_setup_check(bot) - bot_events_startup_register(bot, [botevents.BOT_WELCOME, botevents.BOT_READY, botevents.BOT_CONNECTED]) - - -def shutdown(bot): - if "SpiceBot_Events" in bot.memory: - del bot.memory["SpiceBot_Events"] - - def bot_events_trigger(bot, number, message): bot_events_setup_check(bot) diff --git a/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py b/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py index 71dc9ae..41c5f69 100644 --- a/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py +++ b/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py @@ -5,8 +5,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel.module from sopel_modules.SpiceBot_SBTools import sopel_triggerargs -from sopel_modules.SpiceBot_Events.System import bot_events_check, bot_events_recieved, BotEvents -botevents = BotEvents() +from sopel_modules.SpiceBot_Events.System import bot_events_check, bot_events_recieved, botevents def setup(bot): diff --git a/sopel_modules/SpiceBot_Logs/Logs.py b/sopel_modules/SpiceBot_Logs/Logs.py index dc4584b..4be59f0 100644 --- a/sopel_modules/SpiceBot_Logs/Logs.py +++ b/sopel_modules/SpiceBot_Logs/Logs.py @@ -6,8 +6,7 @@ import sopel.module from sopel.config.types import StaticSection, ValidatedAttribute from sopel_modules.SpiceBot_SBTools import bot_logging -from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger, BotEvents -botevents = BotEvents() +from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger, botevents import os diff --git a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py index 6fad94c..3761c5d 100644 --- a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py +++ b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py @@ -4,9 +4,9 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel.module -from sopel_modules.SpiceBot_Events.System import bot_events_recieved, bot_events_trigger, BotEvents +from sopel_modules.SpiceBot_Events.System import bot_events_recieved, bot_events_trigger, botevents from sopel_modules.SpiceBot_SBTools import humanized_time, bot_logging -botevents = BotEvents() + import time From ee0b071cd804108adcc331a7626bbfccc63b521b Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 14 May 2019 16:17:27 -0400 Subject: [PATCH 61/80] verify return --- sopel_modules/SpiceBot_Events/System.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sopel_modules/SpiceBot_Events/System.py b/sopel_modules/SpiceBot_Events/System.py index 1be32f8..c0cd567 100644 --- a/sopel_modules/SpiceBot_Events/System.py +++ b/sopel_modules/SpiceBot_Events/System.py @@ -46,6 +46,7 @@ class BotEvents(object): eventnumber = randint(2000, 9999) setattr(self, str(attr).upper(), str(eventnumber)) self.usednumbers.append(str(eventnumber)) + return eventnumber botevents = BotEvents() From bfbdd457f4b25d703d27090e325d7925dff785d2 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 14 May 2019 16:21:47 -0400 Subject: [PATCH 62/80] try this --- sopel_modules/SpiceBot_Events/System.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/sopel_modules/SpiceBot_Events/System.py b/sopel_modules/SpiceBot_Events/System.py index c0cd567..4b1fdd6 100644 --- a/sopel_modules/SpiceBot_Events/System.py +++ b/sopel_modules/SpiceBot_Events/System.py @@ -33,12 +33,14 @@ class BotEvents(object): This allows you to do, for example, ``@module.event(botevents.BOT_WELCOME)`` rather than ``@module.event('1001')`` """ - usednumbers = ['0', '1001', '1002', '1003', '1004'] - BOT_WELCOME = '1001' - BOT_READY = '1002' - BOT_CONNECTED = '1003' - BOT_LOADED = '1004' + def __init__(self): + self.usednumbers = ['0', '1001', '1002', '1003', '1004'] + + self.BOT_WELCOME = '1001' + self.BOT_READY = '1002' + self.BOT_CONNECTED = '1003' + self.BOT_LOADED = '1004' def __getattr__(self, attr): eventnumber = 0 From 539374e9ce7d6a727f9726020eeb74c833c7f98a Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 14 May 2019 16:28:35 -0400 Subject: [PATCH 63/80] BotEvents --- sopel_modules/SpiceBot_AI/AI.py | 3 ++- sopel_modules/SpiceBot_Channels/Channels.py | 4 ++-- .../SpiceBot_Channels/Channels_Command.py | 3 ++- .../SpiceBot_CommandsQuery/CommandsQuery.py | 3 ++- sopel_modules/SpiceBot_Events/Events.py | 3 ++- sopel_modules/SpiceBot_Events/System.py | 22 +++++++++---------- .../SpiceBot_InvalidCommand/InvalidCommand.py | 3 ++- sopel_modules/SpiceBot_Logs/Logs.py | 3 ++- .../StartupMonologue_Display.py | 3 ++- 9 files changed, 27 insertions(+), 20 deletions(-) diff --git a/sopel_modules/SpiceBot_AI/AI.py b/sopel_modules/SpiceBot_AI/AI.py index 8fd489a..70b1e9a 100644 --- a/sopel_modules/SpiceBot_AI/AI.py +++ b/sopel_modules/SpiceBot_AI/AI.py @@ -7,7 +7,8 @@ import sopel.module import spicemanip from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, googlesearch, bot_privs, inlist, inlist_match, similar_list -from sopel_modules.SpiceBot_Events.System import bot_events_check, botevents +from sopel_modules.SpiceBot_Events.System import bot_events_check, BotEvents +botevents = BotEvents() @sopel.module.nickname_commands('(.*)') diff --git a/sopel_modules/SpiceBot_Channels/Channels.py b/sopel_modules/SpiceBot_Channels/Channels.py index 34db283..efe0332 100644 --- a/sopel_modules/SpiceBot_Channels/Channels.py +++ b/sopel_modules/SpiceBot_Channels/Channels.py @@ -6,8 +6,8 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi import sopel.module from sopel.config.types import StaticSection, ValidatedAttribute, ListAttribute -from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger, botevents - +from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger, BotEvents +botevents = BotEvents() from sopel_modules.SpiceBot_SBTools import ( join_all_channels, chanadmin_all_channels, channel_list_current, bot_logging diff --git a/sopel_modules/SpiceBot_Channels/Channels_Command.py b/sopel_modules/SpiceBot_Channels/Channels_Command.py index c7e69bc..906f5ea 100644 --- a/sopel_modules/SpiceBot_Channels/Channels_Command.py +++ b/sopel_modules/SpiceBot_Channels/Channels_Command.py @@ -6,7 +6,8 @@ import sopel.module import spicemanip -from sopel_modules.SpiceBot_Events.System import bot_events_check, botevents +from sopel_modules.SpiceBot_Events.System import bot_events_check, BotEvents +botevents = BotEvents() from sopel_modules.SpiceBot_SBTools import ( sopel_triggerargs, inlist, channel_privs, join_all_channels, channel_list_current, diff --git a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py index 2d9e2ce..9079215 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py +++ b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py @@ -7,7 +7,8 @@ import sopel.module import os -from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger, botevents +from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger, BotEvents +botevents = BotEvents() from sopel_modules.SpiceBot_SBTools import bot_logging import spicemanip diff --git a/sopel_modules/SpiceBot_Events/Events.py b/sopel_modules/SpiceBot_Events/Events.py index 730cb4f..736f595 100644 --- a/sopel_modules/SpiceBot_Events/Events.py +++ b/sopel_modules/SpiceBot_Events/Events.py @@ -5,7 +5,8 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel.module from sopel.trigger import PreTrigger -from .System import bot_events_trigger, bot_events_recieved, bot_events_startup_check, bot_events_setup_check, botevents +from .System import bot_events_trigger, bot_events_recieved, bot_events_startup_check, bot_events_setup_check, BotEvents +botevents = BotEvents() from sopel_modules.SpiceBot_SBTools import bot_logging import time diff --git a/sopel_modules/SpiceBot_Events/System.py b/sopel_modules/SpiceBot_Events/System.py index 4b1fdd6..6058a5c 100644 --- a/sopel_modules/SpiceBot_Events/System.py +++ b/sopel_modules/SpiceBot_Events/System.py @@ -11,17 +11,6 @@ from sopel_modules.SpiceBot_SBTools import bot_logging from random import randint -def setup(bot): - bot_logging(bot, 'SpiceBot_Events', "Starting setup procedure") - bot_events_setup_check(bot) - bot_events_startup_register(bot, [botevents.BOT_WELCOME, botevents.BOT_READY, botevents.BOT_CONNECTED]) - - -def shutdown(bot): - if "SpiceBot_Events" in bot.memory: - del bot.memory["SpiceBot_Events"] - - class BotEvents(object): """An dynamic listing of all the notable Bot numeric events. @@ -54,6 +43,17 @@ class BotEvents(object): botevents = BotEvents() +def setup(bot): + bot_logging(bot, 'SpiceBot_Events', "Starting setup procedure") + bot_events_setup_check(bot) + bot_events_startup_register(bot, [botevents.BOT_WELCOME, botevents.BOT_READY, botevents.BOT_CONNECTED]) + + +def shutdown(bot): + if "SpiceBot_Events" in bot.memory: + del bot.memory["SpiceBot_Events"] + + def bot_events_trigger(bot, number, message): bot_events_setup_check(bot) diff --git a/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py b/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py index 41c5f69..71dc9ae 100644 --- a/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py +++ b/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py @@ -5,7 +5,8 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel.module from sopel_modules.SpiceBot_SBTools import sopel_triggerargs -from sopel_modules.SpiceBot_Events.System import bot_events_check, bot_events_recieved, botevents +from sopel_modules.SpiceBot_Events.System import bot_events_check, bot_events_recieved, BotEvents +botevents = BotEvents() def setup(bot): diff --git a/sopel_modules/SpiceBot_Logs/Logs.py b/sopel_modules/SpiceBot_Logs/Logs.py index 4be59f0..dc4584b 100644 --- a/sopel_modules/SpiceBot_Logs/Logs.py +++ b/sopel_modules/SpiceBot_Logs/Logs.py @@ -6,7 +6,8 @@ import sopel.module from sopel.config.types import StaticSection, ValidatedAttribute from sopel_modules.SpiceBot_SBTools import bot_logging -from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger, botevents +from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger, BotEvents +botevents = BotEvents() import os diff --git a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py index 3761c5d..5ff6a7b 100644 --- a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py +++ b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py @@ -4,7 +4,8 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel.module -from sopel_modules.SpiceBot_Events.System import bot_events_recieved, bot_events_trigger, botevents +from sopel_modules.SpiceBot_Events.System import bot_events_recieved, bot_events_trigger, BotEvents +botevents = BotEvents() from sopel_modules.SpiceBot_SBTools import humanized_time, bot_logging import time From e418f7ce7baf82688204dc33319fbf8f023258a3 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 14 May 2019 17:10:57 -0400 Subject: [PATCH 64/80] revert changes --- sopel_modules/SpiceBot_AI/AI.py | 3 +-- sopel_modules/SpiceBot_Channels/Channels.py | 9 ++++----- .../SpiceBot_Channels/Channels_Command.py | 3 +-- .../SpiceBot_CommandsQuery/CommandsQuery.py | 3 +-- sopel_modules/SpiceBot_Events/Events.py | 3 +-- sopel_modules/SpiceBot_Events/System.py | 16 ++++++---------- .../SpiceBot_InvalidCommand/InvalidCommand.py | 3 +-- sopel_modules/SpiceBot_Logs/Logs.py | 3 +-- .../StartupMonologue_Display.py | 5 ++--- 9 files changed, 18 insertions(+), 30 deletions(-) diff --git a/sopel_modules/SpiceBot_AI/AI.py b/sopel_modules/SpiceBot_AI/AI.py index 70b1e9a..8fd489a 100644 --- a/sopel_modules/SpiceBot_AI/AI.py +++ b/sopel_modules/SpiceBot_AI/AI.py @@ -7,8 +7,7 @@ import sopel.module import spicemanip from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, googlesearch, bot_privs, inlist, inlist_match, similar_list -from sopel_modules.SpiceBot_Events.System import bot_events_check, BotEvents -botevents = BotEvents() +from sopel_modules.SpiceBot_Events.System import bot_events_check, botevents @sopel.module.nickname_commands('(.*)') diff --git a/sopel_modules/SpiceBot_Channels/Channels.py b/sopel_modules/SpiceBot_Channels/Channels.py index efe0332..2ca8c89 100644 --- a/sopel_modules/SpiceBot_Channels/Channels.py +++ b/sopel_modules/SpiceBot_Channels/Channels.py @@ -6,8 +6,7 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi import sopel.module from sopel.config.types import StaticSection, ValidatedAttribute, ListAttribute -from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger, BotEvents -botevents = BotEvents() +from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger, botevents from sopel_modules.SpiceBot_SBTools import ( join_all_channels, chanadmin_all_channels, channel_list_current, bot_logging @@ -35,7 +34,7 @@ def configure(config): def setup(bot): bot_logging(bot, 'SpiceBot_Channels', "Starting setup procedure") - bot_events_startup_register(bot, [botevents.BOT_CHANNELS]) + bot_events_startup_register(bot, ['2001']) bot.config.define_section("SpiceBot_Channels", SpiceBot_Channels_MainSection, validate=False) @@ -75,7 +74,7 @@ def trigger_channel_list_initial(bot, trigger): channel_list_current(bot) foundchannelcount = len(bot.memory['SpiceBot_Channels']['channels'].keys()) bot_logging(bot, 'SpiceBot_Channels', "Channel listing finished! " + str(foundchannelcount) + " channel(s) found.") - bot_events_trigger(bot, botevents.BOT_CHANNELS, "SpiceBot_Channels") + bot_events_trigger(bot, '2001', "SpiceBot_Channels") join_all_channels(bot) chanadmin_all_channels(bot) @@ -124,7 +123,7 @@ def bot_part_empty(bot): del bot.memory['SpiceBot_Channels']['channels'][channel.lower()] -@sopel.module.event(botevents.BOT_CHANNELS) +@sopel.module.event('2001') @sopel.module.rule('.*') def bot_events_setup(bot, trigger): bot_events_recieved(bot, trigger.event) diff --git a/sopel_modules/SpiceBot_Channels/Channels_Command.py b/sopel_modules/SpiceBot_Channels/Channels_Command.py index 906f5ea..c7e69bc 100644 --- a/sopel_modules/SpiceBot_Channels/Channels_Command.py +++ b/sopel_modules/SpiceBot_Channels/Channels_Command.py @@ -6,8 +6,7 @@ import sopel.module import spicemanip -from sopel_modules.SpiceBot_Events.System import bot_events_check, BotEvents -botevents = BotEvents() +from sopel_modules.SpiceBot_Events.System import bot_events_check, botevents from sopel_modules.SpiceBot_SBTools import ( sopel_triggerargs, inlist, channel_privs, join_all_channels, channel_list_current, diff --git a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py index 9079215..2d9e2ce 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py +++ b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py @@ -7,8 +7,7 @@ import sopel.module import os -from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger, BotEvents -botevents = BotEvents() +from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger, botevents from sopel_modules.SpiceBot_SBTools import bot_logging import spicemanip diff --git a/sopel_modules/SpiceBot_Events/Events.py b/sopel_modules/SpiceBot_Events/Events.py index 736f595..730cb4f 100644 --- a/sopel_modules/SpiceBot_Events/Events.py +++ b/sopel_modules/SpiceBot_Events/Events.py @@ -5,8 +5,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel.module from sopel.trigger import PreTrigger -from .System import bot_events_trigger, bot_events_recieved, bot_events_startup_check, bot_events_setup_check, BotEvents -botevents = BotEvents() +from .System import bot_events_trigger, bot_events_recieved, bot_events_startup_check, bot_events_setup_check, botevents from sopel_modules.SpiceBot_SBTools import bot_logging import time diff --git a/sopel_modules/SpiceBot_Events/System.py b/sopel_modules/SpiceBot_Events/System.py index 6058a5c..d6bdfd4 100644 --- a/sopel_modules/SpiceBot_Events/System.py +++ b/sopel_modules/SpiceBot_Events/System.py @@ -11,7 +11,7 @@ from sopel_modules.SpiceBot_SBTools import bot_logging from random import randint -class BotEvents(object): +class botevents(object): """An dynamic listing of all the notable Bot numeric events. Events contained in this module will utilize the 1000-range @@ -23,13 +23,12 @@ class BotEvents(object): rather than ``@module.event('1001')`` """ - def __init__(self): - self.usednumbers = ['0', '1001', '1002', '1003', '1004'] + usednumbers = ['0', '1001', '1002', '1003', '1004'] - self.BOT_WELCOME = '1001' - self.BOT_READY = '1002' - self.BOT_CONNECTED = '1003' - self.BOT_LOADED = '1004' + BOT_WELCOME = '1001' + BOT_READY = '1002' + BOT_CONNECTED = '1003' + BOT_LOADED = '1004' def __getattr__(self, attr): eventnumber = 0 @@ -40,9 +39,6 @@ class BotEvents(object): return eventnumber -botevents = BotEvents() - - def setup(bot): bot_logging(bot, 'SpiceBot_Events', "Starting setup procedure") bot_events_setup_check(bot) diff --git a/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py b/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py index 71dc9ae..41c5f69 100644 --- a/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py +++ b/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py @@ -5,8 +5,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel.module from sopel_modules.SpiceBot_SBTools import sopel_triggerargs -from sopel_modules.SpiceBot_Events.System import bot_events_check, bot_events_recieved, BotEvents -botevents = BotEvents() +from sopel_modules.SpiceBot_Events.System import bot_events_check, bot_events_recieved, botevents def setup(bot): diff --git a/sopel_modules/SpiceBot_Logs/Logs.py b/sopel_modules/SpiceBot_Logs/Logs.py index dc4584b..4be59f0 100644 --- a/sopel_modules/SpiceBot_Logs/Logs.py +++ b/sopel_modules/SpiceBot_Logs/Logs.py @@ -6,8 +6,7 @@ import sopel.module from sopel.config.types import StaticSection, ValidatedAttribute from sopel_modules.SpiceBot_SBTools import bot_logging -from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger, BotEvents -botevents = BotEvents() +from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger, botevents import os diff --git a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py index 5ff6a7b..e638bfb 100644 --- a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py +++ b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py @@ -4,8 +4,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel.module -from sopel_modules.SpiceBot_Events.System import bot_events_recieved, bot_events_trigger, BotEvents -botevents = BotEvents() +from sopel_modules.SpiceBot_Events.System import bot_events_recieved, bot_events_trigger, botevents from sopel_modules.SpiceBot_SBTools import humanized_time, bot_logging import time @@ -39,7 +38,7 @@ def bot_startup_monologue_commands(bot, trigger): bot_events_trigger(bot, 2011, "SpiceBot_StartupMonologue") -@sopel.module.event(botevents.BOT_CHANNELS) +@sopel.module.event('2001') @sopel.module.rule('.*') def bot_startup_monologue_channels(bot, trigger): bot_events_recieved(bot, trigger.event) From c0e85eb828449e473b4af19dab8943fadfaf9db8 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 14 May 2019 19:51:34 -0400 Subject: [PATCH 65/80] Test Prior --- sopel_modules/SpiceBot_Events/System.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/sopel_modules/SpiceBot_Events/System.py b/sopel_modules/SpiceBot_Events/System.py index d6bdfd4..57edf0a 100644 --- a/sopel_modules/SpiceBot_Events/System.py +++ b/sopel_modules/SpiceBot_Events/System.py @@ -23,7 +23,7 @@ class botevents(object): rather than ``@module.event('1001')`` """ - usednumbers = ['0', '1001', '1002', '1003', '1004'] + usednumbers = [0, 1001, 1002, 1003, 1004, 2000] BOT_WELCOME = '1001' BOT_READY = '1002' @@ -31,12 +31,10 @@ class botevents(object): BOT_LOADED = '1004' def __getattr__(self, attr): - eventnumber = 0 - while eventnumber not in self.usednumbers: - eventnumber = randint(2000, 9999) - setattr(self, str(attr).upper(), str(eventnumber)) - self.usednumbers.append(str(eventnumber)) - return eventnumber + ''' will only get called for undefined attributes ''' + eventnumber = max(self.usednumbers) + 1 + self.usednumbers.append(eventnumber) + setattr(self, str(attr).upper()) = str(eventnumber) def setup(bot): From 44dcac93d5229c4937b33c9d7b3ce451095213ac Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 14 May 2019 19:57:20 -0400 Subject: [PATCH 66/80] remove randint --- sopel_modules/SpiceBot_Events/System.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sopel_modules/SpiceBot_Events/System.py b/sopel_modules/SpiceBot_Events/System.py index 57edf0a..5ea3969 100644 --- a/sopel_modules/SpiceBot_Events/System.py +++ b/sopel_modules/SpiceBot_Events/System.py @@ -8,8 +8,6 @@ from sopel.trigger import PreTrigger from sopel_modules.SpiceBot_SBTools import bot_logging -from random import randint - class botevents(object): """An dynamic listing of all the notable Bot numeric events. @@ -34,7 +32,7 @@ class botevents(object): ''' will only get called for undefined attributes ''' eventnumber = max(self.usednumbers) + 1 self.usednumbers.append(eventnumber) - setattr(self, str(attr).upper()) = str(eventnumber) + setattr(self, str(attr).upper(), str(eventnumber)) def setup(bot): From 3a0ef8ae9d057a5a305ee16d854f16c2a677880f Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 14 May 2019 20:11:56 -0400 Subject: [PATCH 67/80] test without hardcoded values --- sopel_modules/SpiceBot_Events/System.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/sopel_modules/SpiceBot_Events/System.py b/sopel_modules/SpiceBot_Events/System.py index 5ea3969..c452fd4 100644 --- a/sopel_modules/SpiceBot_Events/System.py +++ b/sopel_modules/SpiceBot_Events/System.py @@ -21,12 +21,14 @@ class botevents(object): rather than ``@module.event('1001')`` """ - usednumbers = [0, 1001, 1002, 1003, 1004, 2000] + def __init__(self, usednumbers): + self.usednumbers = [0, 1001, 1002, 1003, 1004, 2000] - BOT_WELCOME = '1001' - BOT_READY = '1002' - BOT_CONNECTED = '1003' - BOT_LOADED = '1004' + # usednumbers = [0, 1001, 1002, 1003, 1004, 2000] + # BOT_WELCOME = '1001' + # BOT_READY = '1002' + # BOT_CONNECTED = '1003' + # BOT_LOADED = '1004' def __getattr__(self, attr): ''' will only get called for undefined attributes ''' From a1a44584e6be2faa6e894f31a6fdae6e0455cea3 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 14 May 2019 20:17:11 -0400 Subject: [PATCH 68/80] Test --- sopel_modules/SpiceBot_Events/System.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_Events/System.py b/sopel_modules/SpiceBot_Events/System.py index c452fd4..ec2c61f 100644 --- a/sopel_modules/SpiceBot_Events/System.py +++ b/sopel_modules/SpiceBot_Events/System.py @@ -9,7 +9,7 @@ from sopel.trigger import PreTrigger from sopel_modules.SpiceBot_SBTools import bot_logging -class botevents(object): +class BotEvents(object): """An dynamic listing of all the notable Bot numeric events. Events contained in this module will utilize the 1000-range @@ -23,6 +23,10 @@ class botevents(object): def __init__(self, usednumbers): self.usednumbers = [0, 1001, 1002, 1003, 1004, 2000] + self.BOT_WELCOME = '1001' + self.BOT_READY = '1002' + self.BOT_CONNECTED = '1003' + self.BOT_LOADED = '1004' # usednumbers = [0, 1001, 1002, 1003, 1004, 2000] # BOT_WELCOME = '1001' @@ -37,6 +41,9 @@ class botevents(object): setattr(self, str(attr).upper(), str(eventnumber)) +botevents = BotEvents() + + def setup(bot): bot_logging(bot, 'SpiceBot_Events', "Starting setup procedure") bot_events_setup_check(bot) From 16eeebf22fc9e0a9001bc1836ed4020c3c30f2e7 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 14 May 2019 20:21:01 -0400 Subject: [PATCH 69/80] adjust init --- sopel_modules/SpiceBot_Events/System.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_Events/System.py b/sopel_modules/SpiceBot_Events/System.py index ec2c61f..4ea69fd 100644 --- a/sopel_modules/SpiceBot_Events/System.py +++ b/sopel_modules/SpiceBot_Events/System.py @@ -21,7 +21,7 @@ class BotEvents(object): rather than ``@module.event('1001')`` """ - def __init__(self, usednumbers): + def __init__(self): self.usednumbers = [0, 1001, 1002, 1003, 1004, 2000] self.BOT_WELCOME = '1001' self.BOT_READY = '1002' From b0fab05f0ec233d7795c5cccc91f22318159720c Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 14 May 2019 20:29:50 -0400 Subject: [PATCH 70/80] name --- sopel_modules/SpiceBot_Events/System.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot_Events/System.py b/sopel_modules/SpiceBot_Events/System.py index 4ea69fd..58027a7 100644 --- a/sopel_modules/SpiceBot_Events/System.py +++ b/sopel_modules/SpiceBot_Events/System.py @@ -34,11 +34,11 @@ class BotEvents(object): # BOT_CONNECTED = '1003' # BOT_LOADED = '1004' - def __getattr__(self, attr): + def __getattr__(self, name): ''' will only get called for undefined attributes ''' eventnumber = max(self.usednumbers) + 1 self.usednumbers.append(eventnumber) - setattr(self, str(attr).upper(), str(eventnumber)) + setattr(self, str(name).upper(), str(eventnumber)) botevents = BotEvents() From e3bf9bbf4cf91b75563f66a1d647c905a18cc415 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 14 May 2019 20:33:13 -0400 Subject: [PATCH 71/80] dont handle upper here --- sopel_modules/SpiceBot_Events/System.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_Events/System.py b/sopel_modules/SpiceBot_Events/System.py index 58027a7..9201414 100644 --- a/sopel_modules/SpiceBot_Events/System.py +++ b/sopel_modules/SpiceBot_Events/System.py @@ -38,7 +38,7 @@ class BotEvents(object): ''' will only get called for undefined attributes ''' eventnumber = max(self.usednumbers) + 1 self.usednumbers.append(eventnumber) - setattr(self, str(name).upper(), str(eventnumber)) + setattr(self, name, str(eventnumber)) botevents = BotEvents() From f7548435fca8b74ea1c4a182a94685df32e5c608 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 14 May 2019 20:43:39 -0400 Subject: [PATCH 72/80] tst return --- sopel_modules/SpiceBot_Events/System.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sopel_modules/SpiceBot_Events/System.py b/sopel_modules/SpiceBot_Events/System.py index 9201414..3c17387 100644 --- a/sopel_modules/SpiceBot_Events/System.py +++ b/sopel_modules/SpiceBot_Events/System.py @@ -39,6 +39,7 @@ class BotEvents(object): eventnumber = max(self.usednumbers) + 1 self.usednumbers.append(eventnumber) setattr(self, name, str(eventnumber)) + return str(eventnumber) botevents = BotEvents() From 9538c1e82588fe5c30f2d0c1b5578254d5943c09 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 14 May 2019 20:50:02 -0400 Subject: [PATCH 73/80] hardcore mode engaged --- sopel_modules/SpiceBot_Events/System.py | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/sopel_modules/SpiceBot_Events/System.py b/sopel_modules/SpiceBot_Events/System.py index 3c17387..cd7a874 100644 --- a/sopel_modules/SpiceBot_Events/System.py +++ b/sopel_modules/SpiceBot_Events/System.py @@ -10,29 +10,15 @@ from sopel_modules.SpiceBot_SBTools import bot_logging class BotEvents(object): - """An dynamic listing of all the notable Bot numeric events. + """A dynamic listing of all the notable Bot numeric events. - Events contained in this module will utilize the 1000-range + Events will be assigned a 4-digit number above 1000. - All Other events will be tagged with a randomly generated - 4-digit number above 2000. - - This allows you to do, for example, ``@module.event(botevents.BOT_WELCOME)`` - rather than ``@module.event('1001')`` + This allows you to do, ``@module.event(botevents.BOT_WELCOME)```` """ def __init__(self): - self.usednumbers = [0, 1001, 1002, 1003, 1004, 2000] - self.BOT_WELCOME = '1001' - self.BOT_READY = '1002' - self.BOT_CONNECTED = '1003' - self.BOT_LOADED = '1004' - - # usednumbers = [0, 1001, 1002, 1003, 1004, 2000] - # BOT_WELCOME = '1001' - # BOT_READY = '1002' - # BOT_CONNECTED = '1003' - # BOT_LOADED = '1004' + self.usednumbers = [1000] def __getattr__(self, name): ''' will only get called for undefined attributes ''' From 53c77f9388d60ecf2630df011cd55511475441d1 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 14 May 2019 21:06:02 -0400 Subject: [PATCH 74/80] Real test now --- sopel_modules/SpiceBot_AI/AI.py | 2 +- sopel_modules/SpiceBot_Channels/Channels.py | 6 +++--- .../SpiceBot_CommandsQuery/CommandsQuery.py | 6 +++--- .../SpiceBot_CommandsQuery/NickQueryCommand.py | 4 ++-- sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py | 4 ++-- sopel_modules/SpiceBot_GifSearch/gif.py | 4 ++-- sopel_modules/SpiceBot_GifSearch/gifapi.py | 4 ++-- sopel_modules/SpiceBot_GifSearch/gifsearch.py | 8 ++++---- .../SpiceBot_InvalidCommand/InvalidCommand.py | 2 +- sopel_modules/SpiceBot_Logs/ErrorDisplay.py | 4 ++-- sopel_modules/SpiceBot_Logs/Logs.py | 6 +++--- sopel_modules/SpiceBot_Logs/Logs_Command.py | 4 ++-- .../SpiceBot_StartupMonologue/StartupMonologue.py | 6 +++--- .../StartupMonologue_Display.py | 12 ++++++------ 14 files changed, 36 insertions(+), 36 deletions(-) diff --git a/sopel_modules/SpiceBot_AI/AI.py b/sopel_modules/SpiceBot_AI/AI.py index 8fd489a..d1fe128 100644 --- a/sopel_modules/SpiceBot_AI/AI.py +++ b/sopel_modules/SpiceBot_AI/AI.py @@ -17,7 +17,7 @@ def bot_command_nick(bot, trigger): if str(trigger.args[1])[0] == "?": return - while not bot_events_check(bot, [botevents.BOT_LOADED, '2002']): + while not bot_events_check(bot, [botevents.BOT_LOADED, botevents.BOT_COMMANDSQUERY]): pass triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'nickname_command') diff --git a/sopel_modules/SpiceBot_Channels/Channels.py b/sopel_modules/SpiceBot_Channels/Channels.py index 2ca8c89..5bb11d6 100644 --- a/sopel_modules/SpiceBot_Channels/Channels.py +++ b/sopel_modules/SpiceBot_Channels/Channels.py @@ -34,7 +34,7 @@ def configure(config): def setup(bot): bot_logging(bot, 'SpiceBot_Channels', "Starting setup procedure") - bot_events_startup_register(bot, ['2001']) + bot_events_startup_register(bot, [botevents.BOT_CHANNELS]) bot.config.define_section("SpiceBot_Channels", SpiceBot_Channels_MainSection, validate=False) @@ -74,7 +74,7 @@ def trigger_channel_list_initial(bot, trigger): channel_list_current(bot) foundchannelcount = len(bot.memory['SpiceBot_Channels']['channels'].keys()) bot_logging(bot, 'SpiceBot_Channels', "Channel listing finished! " + str(foundchannelcount) + " channel(s) found.") - bot_events_trigger(bot, '2001', "SpiceBot_Channels") + bot_events_trigger(bot, botevents.BOT_CHANNELS, "SpiceBot_Channels") join_all_channels(bot) chanadmin_all_channels(bot) @@ -123,7 +123,7 @@ def bot_part_empty(bot): del bot.memory['SpiceBot_Channels']['channels'][channel.lower()] -@sopel.module.event('2001') +@sopel.module.event(botevents.BOT_CHANNELS) @sopel.module.rule('.*') def bot_events_setup(bot, trigger): bot_events_recieved(bot, trigger.event) diff --git a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py index 2d9e2ce..434630e 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py +++ b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py @@ -15,7 +15,7 @@ import spicemanip def setup(bot): bot_logging(bot, 'SpiceBot_CommandsQuery', "Starting setup procedure") - bot_events_startup_register(bot, ['2002']) + bot_events_startup_register(bot, [botevents.BOT_COMMANDSQUERY]) if 'SpiceBot_CommandsQuery' not in bot.memory: bot.memory['SpiceBot_CommandsQuery'] = {"counts": 0, "commands": {}, "nickrules": []} @@ -162,7 +162,7 @@ def setup(bot): if command not in bot.memory['SpiceBot_CommandsQuery']['nickrules']: bot.memory['SpiceBot_CommandsQuery']['nickrules'].append(command) - bot_events_trigger(bot, 2002, "SpiceBot_CommandsQuery") + bot_events_trigger(bot, botevents.BOT_COMMANDSQUERY, "SpiceBot_CommandsQuery") def shutdown(bot): @@ -214,7 +214,7 @@ def commandsquery_register(bot, command_type, validcoms, aliasfor=None): bot.memory['SpiceBot_CommandsQuery']['commands'][command_type][comalias] = {"aliasfor": aliasfor} -@sopel.module.event('2002') +@sopel.module.event(botevents.BOT_COMMANDSQUERY) @sopel.module.rule('.*') def bot_events_setup(bot, trigger): bot_events_recieved(bot, trigger.event) diff --git a/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py b/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py index 407b045..a934b8d 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py +++ b/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel import sopel.module -from sopel_modules.SpiceBot_Events.System import bot_events_check +from sopel_modules.SpiceBot_Events.System import bot_events_check, botevents from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, similar_list, letters_in_string @@ -15,7 +15,7 @@ import spicemanip @sopel.module.nickname_commands('^\?(.*)') def query_detection_nick(bot, trigger): - while not bot_events_check(bot, '2002'): + while not bot_events_check(bot, botevents.BOT_COMMANDSQUERY): pass triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'nickname_command') diff --git a/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py b/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py index 1d549a5..8f8011b 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py +++ b/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel import sopel.module -from sopel_modules.SpiceBot_Events.System import bot_events_check +from sopel_modules.SpiceBot_Events.System import bot_events_check, botevents from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, similar_list, letters_in_string @@ -15,7 +15,7 @@ import spicemanip @sopel.module.rule('^\?(.*)') def query_detection(bot, trigger): - while not bot_events_check(bot, '2002'): + while not bot_events_check(bot, botevents.BOT_COMMANDSQUERY): pass triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'query_command') diff --git a/sopel_modules/SpiceBot_GifSearch/gif.py b/sopel_modules/SpiceBot_GifSearch/gif.py index 52d272f..6c344a9 100644 --- a/sopel_modules/SpiceBot_GifSearch/gif.py +++ b/sopel_modules/SpiceBot_GifSearch/gif.py @@ -7,7 +7,7 @@ from sopel import module from .gifsearch import getGif from sopel_modules.SpiceBot_SBTools import sopel_triggerargs -from sopel_modules.SpiceBot_Events.System import bot_events_check +from sopel_modules.SpiceBot_Events.System import bot_events_check, botevents import spicemanip @@ -15,7 +15,7 @@ import spicemanip @module.commands('gif') def gif_trigger(bot, trigger): - while not bot_events_check(bot, '2003'): + while not bot_events_check(bot, botevents.BOT_GIFSEARCH): pass triggerargs, triggercommand = sopel_triggerargs(bot, trigger) diff --git a/sopel_modules/SpiceBot_GifSearch/gifapi.py b/sopel_modules/SpiceBot_GifSearch/gifapi.py index 05a7b0e..fa500b9 100644 --- a/sopel_modules/SpiceBot_GifSearch/gifapi.py +++ b/sopel_modules/SpiceBot_GifSearch/gifapi.py @@ -9,13 +9,13 @@ import sopel.module import spicemanip from sopel_modules.SpiceBot_SBTools import sopel_triggerargs -from sopel_modules.SpiceBot_Events.System import bot_events_check +from sopel_modules.SpiceBot_Events.System import bot_events_check, botevents @sopel.module.commands('(.*)') def gifapi_triggers(bot, trigger): - while not bot_events_check(bot, '2003'): + while not bot_events_check(bot, botevents.BOT_GIFSEARCH): pass triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'prefix_command') diff --git a/sopel_modules/SpiceBot_GifSearch/gifsearch.py b/sopel_modules/SpiceBot_GifSearch/gifsearch.py index fb9581d..884bd11 100644 --- a/sopel_modules/SpiceBot_GifSearch/gifsearch.py +++ b/sopel_modules/SpiceBot_GifSearch/gifsearch.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel.module from sopel.config.types import StaticSection, ValidatedAttribute -from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger +from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger, botevents from sopel_modules.SpiceBot_CommandsQuery.CommandsQuery import commandsquery_register @@ -47,7 +47,7 @@ def configure(config): def setup(bot): bot_logging(bot, 'SpiceBot_GifSearch', "Starting Setup Procedure") - bot_events_startup_register(bot, ['2003']) + bot_events_startup_register(bot, [botevents.BOT_GIFSEARCH]) if 'SpiceBot_GifSearch' not in bot.memory: bot.memory["SpiceBot_GifSearch"] = {"cache": {}, "badgiflinks": [], 'valid_gif_api_dict': {}} @@ -79,7 +79,7 @@ def setup(bot): if validgifapi not in bot.memory["SpiceBot_GifSearch"]['cache'].keys(): bot.memory["SpiceBot_GifSearch"]['cache'][validgifapi] = dict() - bot_events_trigger(bot, 2003, "SpiceBot_GifSearch") + bot_events_trigger(bot, botevents.BOT_GIFSEARCH, "SpiceBot_GifSearch") def shutdown(bot): @@ -251,7 +251,7 @@ def getGif(bot, searchdict): return gifdict -@sopel.module.event('2003') +@sopel.module.event(botevents.BOT_GIFSEARCH) @sopel.module.rule('.*') def bot_events_setup(bot, trigger): bot_events_recieved(bot, trigger.event) diff --git a/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py b/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py index 41c5f69..73250cb 100644 --- a/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py +++ b/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py @@ -31,7 +31,7 @@ def bot_events_complete(bot, trigger): def InvalidCommand_triggers(bot, trigger): return - while not bot_events_check(bot, [botevents.BOT_LOADED, '2002']): + while not bot_events_check(bot, [botevents.BOT_LOADED, botevents.BOT_COMMANDSQUERY]): pass triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'prefix_command') diff --git a/sopel_modules/SpiceBot_Logs/ErrorDisplay.py b/sopel_modules/SpiceBot_Logs/ErrorDisplay.py index db978ab..1a18456 100644 --- a/sopel_modules/SpiceBot_Logs/ErrorDisplay.py +++ b/sopel_modules/SpiceBot_Logs/ErrorDisplay.py @@ -4,12 +4,12 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel.module -from sopel_modules.SpiceBot_Events.System import bot_events_recieved +from sopel_modules.SpiceBot_Events.System import bot_events_recieved, botevents from sopel_modules.SpiceBot_SBTools import bot_logging from .Logs import stdio_logs_fetch -@sopel.module.event('2005') +@sopel.module.event(botevents.BOT_STARTUPMONOLOGUE) @sopel.module.rule('.*') def bot_startup_monologue_start(bot, trigger): bot_events_recieved(bot, trigger.event) diff --git a/sopel_modules/SpiceBot_Logs/Logs.py b/sopel_modules/SpiceBot_Logs/Logs.py index 4be59f0..151928a 100644 --- a/sopel_modules/SpiceBot_Logs/Logs.py +++ b/sopel_modules/SpiceBot_Logs/Logs.py @@ -26,11 +26,11 @@ def setup(bot): bot_logging(bot, 'SpiceBot_Logs', "Starting Setup Procedure") bot.config.define_section("SpiceBot_Logs", SpiceBot_Logs_MainSection, validate=False) - bot_events_startup_register(bot, ['2004']) + bot_events_startup_register(bot, [botevents.BOT_LOGS]) bot_logs_setup_check(bot) - bot_events_trigger(bot, 2004, "SpiceBot_Logs") + bot_events_trigger(bot, botevents.BOT_LOGS, "SpiceBot_Logs") def bot_logs_setup_check(bot): @@ -131,7 +131,7 @@ def get_running_pid(bot): return pidnum -@sopel.module.event('2004') +@sopel.module.event(botevents.BOT_LOGS) @sopel.module.rule('.*') def bot_events_setup(bot, trigger): bot_events_recieved(bot, trigger.event) diff --git a/sopel_modules/SpiceBot_Logs/Logs_Command.py b/sopel_modules/SpiceBot_Logs/Logs_Command.py index de9da49..a095e39 100644 --- a/sopel_modules/SpiceBot_Logs/Logs_Command.py +++ b/sopel_modules/SpiceBot_Logs/Logs_Command.py @@ -7,14 +7,14 @@ import sopel.module import spicemanip from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, command_permissions_check, inlist, inlist_match, similar_list -from sopel_modules.SpiceBot_Events.System import bot_events_check +from sopel_modules.SpiceBot_Events.System import bot_events_check, botevents from .Logs import systemd_logs_fetch, stdio_logs_fetch @sopel.module.nickname_commands('logs', 'debug') def bot_command_logs(bot, trigger): - while not bot_events_check(bot, '2004'): + while not bot_events_check(bot, botevents.BOT_LOGS): pass if not command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']): diff --git a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py index c036231..fd5b640 100644 --- a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py +++ b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py @@ -4,19 +4,19 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel.module -from sopel_modules.SpiceBot_Events.System import bot_events_recieved, bot_events_startup_register +from sopel_modules.SpiceBot_Events.System import bot_events_recieved, bot_events_startup_register, botevents from sopel_modules.SpiceBot_SBTools import bot_logging def setup(bot): bot_logging(bot, 'SpiceBot_StartupMonologue', "Starting setup procedure") - bot_events_startup_register(bot, ['2010', '2011', '2012']) + bot_events_startup_register(bot, [botevents.BOT_STARTUPMONOLOGUE_CHANNELS, botevents.BOT_STARTUPMONOLOGUE_COMMANDSQUERY, botevents.BOT_STARTUPMONOLOGUE_CONNECTED]) if 'SpiceBot_StartupMonologue' not in bot.memory: bot.memory['SpiceBot_StartupMonologue'] = [] -@sopel.module.event('2005', '2010', '2011', '2012') +@sopel.module.event(botevents.BOT_STARTUPMONOLOGUE, botevents.BOT_STARTUPMONOLOGUE_CHANNELS, botevents.BOT_STARTUPMONOLOGUE_COMMANDSQUERY, botevents.BOT_STARTUPMONOLOGUE_CONNECTED) @sopel.module.rule('.*') def bot_events_setup(bot, trigger): bot_events_recieved(bot, trigger.event) diff --git a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py index e638bfb..77e15f5 100644 --- a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py +++ b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py @@ -19,10 +19,10 @@ def bot_startup_monologue_start(bot, trigger): bot_logging(bot, 'SpiceBot_StartupMonologue', bot.nick + " is now starting. Please wait while I load my configuration") bot.osd(" is now starting. Please wait while I load my configuration.", bot.channels.keys(), 'ACTION') - bot_events_trigger(bot, 2012, "SpiceBot_StartupMonologue") + bot_events_trigger(bot, botevents.BOT_STARTUPMONOLOGUE_CONNECTED, "SpiceBot_StartupMonologue") -@sopel.module.event('2002') +@sopel.module.event(botevents.BOT_COMMANDSQUERY) @sopel.module.rule('.*') def bot_startup_monologue_commands(bot, trigger): bot_events_recieved(bot, trigger.event) @@ -35,10 +35,10 @@ def bot_startup_monologue_commands(bot, trigger): bot.memory['SpiceBot_StartupMonologue'].append("There are " + str(availablecomsnum) + " commands available in " + str(availablecomsfiles) + " files.") bot_logging(bot, 'SpiceBot_StartupMonologue', "There are " + str(availablecomsnum) + " commands available in " + str(availablecomsfiles) + " files.") - bot_events_trigger(bot, 2011, "SpiceBot_StartupMonologue") + bot_events_trigger(bot, botevents.BOT_STARTUPMONOLOGUE_COMMANDSQUERY, "SpiceBot_StartupMonologue") -@sopel.module.event('2001') +@sopel.module.event(botevents.BOT_CHANNELS) @sopel.module.rule('.*') def bot_startup_monologue_channels(bot, trigger): bot_events_recieved(bot, trigger.event) @@ -47,7 +47,7 @@ def bot_startup_monologue_channels(bot, trigger): servercount = len(bot.memory['SpiceBot_Channels']['channels'].keys()) bot.memory['SpiceBot_StartupMonologue'].append("I am in " + str(botcount) + " of " + str(servercount) + " channel(s) available on this server.") - bot_events_trigger(bot, 2010, "SpiceBot_StartupMonologue") + bot_events_trigger(bot, botevents.BOT_STARTUPMONOLOGUE_CHANNELS, "SpiceBot_StartupMonologue") @sopel.module.event(botevents.BOT_LOADED) @@ -64,5 +64,5 @@ def bot_startup_monologue_display(bot, trigger): bot.osd(bot.memory['SpiceBot_StartupMonologue'], bot.channels.keys(), 'ACTION') - bot_events_trigger(bot, 2005, "SpiceBot_StartupMonologue") + bot_events_trigger(bot, botevents.BOT_STARTUPMONOLOGUE, "SpiceBot_StartupMonologue") bot_logging(bot, 'SpiceBot_StartupMonologue', "Startup Monologue has been issued to all channels.", True) From 09b174843ed67dad904320210bde9ea18b9d4e73 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 14 May 2019 21:25:59 -0400 Subject: [PATCH 75/80] remove not --- sopel_modules/SpiceBot_Logs/Logs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_Logs/Logs.py b/sopel_modules/SpiceBot_Logs/Logs.py index 151928a..e764855 100644 --- a/sopel_modules/SpiceBot_Logs/Logs.py +++ b/sopel_modules/SpiceBot_Logs/Logs.py @@ -96,7 +96,7 @@ def stdio_logs_fetch(bot): debuglines = [] loadedmodules = [] for line in filelines: - if not line.startswith("Loaded:"): + if line.startswith("Loaded:"): loadedmodules.append(str(line).split("Loaded:")[-1]) else: if not line.startswith(tuple(stdio_ignore)) and not line.isspace(): From b283fa49121a790d9f185169fc90797a0845ee8f Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 14 May 2019 21:45:50 -0400 Subject: [PATCH 76/80] fix query command --- sopel_modules/SpiceBot_AI/AI.py | 3 +-- sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py | 5 ++++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/sopel_modules/SpiceBot_AI/AI.py b/sopel_modules/SpiceBot_AI/AI.py index d1fe128..266e686 100644 --- a/sopel_modules/SpiceBot_AI/AI.py +++ b/sopel_modules/SpiceBot_AI/AI.py @@ -13,8 +13,7 @@ from sopel_modules.SpiceBot_Events.System import bot_events_check, botevents @sopel.module.nickname_commands('(.*)') def bot_command_nick(bot, trigger): - # command must not start with - if str(trigger.args[1])[0] == "?": + if trigger.args[1].lower().startswith(bot.nick.lower() + " ?"): return while not bot_events_check(bot, [botevents.BOT_LOADED, botevents.BOT_COMMANDSQUERY]): diff --git a/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py b/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py index a934b8d..196a9e1 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py +++ b/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py @@ -12,9 +12,12 @@ from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, similar_list, lett import spicemanip -@sopel.module.nickname_commands('^\?(.*)') +@sopel.module.nickname_commands('(.*)') def query_detection_nick(bot, trigger): + if not trigger.args[0].lower().startswith(bot.nick.lower() + " ?"): + return + while not bot_events_check(bot, botevents.BOT_COMMANDSQUERY): pass From d04104efdaaf4b7c6fac50851981cb0d42a29247 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 14 May 2019 21:48:23 -0400 Subject: [PATCH 77/80] remove ? --- sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py b/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py index 196a9e1..d567352 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py +++ b/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py @@ -22,6 +22,7 @@ def query_detection_nick(bot, trigger): pass triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'nickname_command') + triggercommand = triggercommand[1:] # command issued, check if valid if not triggercommand or not len(triggercommand): @@ -53,7 +54,7 @@ def query_detection_nick(bot, trigger): if "aliasfor" in commands_list[triggercommand].keys(): realcom = commands_list[triggercommand]["aliasfor"] validcomlist = commands_list[realcom]["validcoms"] - bot.notice("The following " + bot.nick + "commands match " + str(triggercommand) + ": " + spicemanip.main(validcomlist, 'andlist') + ".", trigger.nick) + bot.notice("The following " + bot.nick + " commands match " + str(triggercommand) + ": " + spicemanip.main(validcomlist, 'andlist') + ".", trigger.nick) return if triggercommand.endswith("?"): From a31485c18624a201a18c40cfbfd0842cecc40166 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 14 May 2019 22:09:49 -0400 Subject: [PATCH 78/80] adjusts for logic --- sopel_modules/SpiceBot_AI/AI.py | 6 +++--- sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/sopel_modules/SpiceBot_AI/AI.py b/sopel_modules/SpiceBot_AI/AI.py index 266e686..7ae029b 100644 --- a/sopel_modules/SpiceBot_AI/AI.py +++ b/sopel_modules/SpiceBot_AI/AI.py @@ -13,9 +13,6 @@ from sopel_modules.SpiceBot_Events.System import bot_events_check, botevents @sopel.module.nickname_commands('(.*)') def bot_command_nick(bot, trigger): - if trigger.args[1].lower().startswith(bot.nick.lower() + " ?"): - return - while not bot_events_check(bot, [botevents.BOT_LOADED, botevents.BOT_COMMANDSQUERY]): pass @@ -24,6 +21,9 @@ def bot_command_nick(bot, trigger): if not triggercommand: return + if triggercommand[0] == "?": + return + if triggercommand in bot.memory['SpiceBot_CommandsQuery']['commands']["nickname"].keys(): return triggerargs.insert(0, triggercommand) diff --git a/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py b/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py index d567352..f590d24 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py +++ b/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py @@ -15,9 +15,6 @@ import spicemanip @sopel.module.nickname_commands('(.*)') def query_detection_nick(bot, trigger): - if not trigger.args[0].lower().startswith(bot.nick.lower() + " ?"): - return - while not bot_events_check(bot, botevents.BOT_COMMANDSQUERY): pass @@ -28,6 +25,9 @@ def query_detection_nick(bot, trigger): if not triggercommand or not len(triggercommand): return + if not triggercommand[0] == "?": + return + if not letters_in_string(triggercommand): return From f95a84c11f6b22f70fc3ece37c74f47a7c1fb5cc Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 14 May 2019 22:10:33 -0400 Subject: [PATCH 79/80] add spaces --- sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py b/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py index f590d24..7699955 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py +++ b/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py @@ -65,9 +65,9 @@ def query_detection_nick(bot, trigger): closestmatches = similar_list(bot, triggercommand, list(commands_list.keys()), 10, 'reverse') if not len(closestmatches): - bot.notice("Cannot find any similar " + bot.nick + "commands for " + str(triggercommand) + ".", trigger.nick) + bot.notice("Cannot find any similar " + bot.nick + " commands for " + str(triggercommand) + ".", trigger.nick) else: - bot.notice("The following " + bot.nick + "commands may match " + str(triggercommand) + ": " + spicemanip.main(closestmatches, 'andlist') + ".", trigger.nick) + bot.notice("The following " + bot.nick + " commands may match " + str(triggercommand) + ": " + spicemanip.main(closestmatches, 'andlist') + ".", trigger.nick) return commandlist = [] @@ -76,6 +76,6 @@ def query_detection_nick(bot, trigger): commandlist.append(command) if not len(commandlist): - bot.notice("No " + bot.nick + "commands start with " + str(triggercommand) + ".", trigger.nick) + bot.notice("No " + bot.nick + " commands start with " + str(triggercommand) + ".", trigger.nick) else: - bot.notice("The following " + bot.nick + "commands start with " + str(triggercommand) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick) + bot.notice("The following " + bot.nick + " commands start with " + str(triggercommand) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick) From b350b4d73df63f4f2a17b6a997d2176ecbe903a9 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 14 May 2019 22:17:40 -0400 Subject: [PATCH 80/80] logic --- sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py b/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py index 7699955..67782f3 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py +++ b/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py @@ -19,7 +19,6 @@ def query_detection_nick(bot, trigger): pass triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'nickname_command') - triggercommand = triggercommand[1:] # command issued, check if valid if not triggercommand or not len(triggercommand): @@ -27,6 +26,7 @@ def query_detection_nick(bot, trigger): if not triggercommand[0] == "?": return + triggercommand = triggercommand[1:] if not letters_in_string(triggercommand): return