From ba3bd5b3660de18407a872271bdefcd0eb2e637f Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 13 May 2019 07:48:27 -0400 Subject: [PATCH 01/70] 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 02/70] 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 03/70] 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 04/70] 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 05/70] 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 06/70] 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 07/70] 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 08/70] 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 09/70] 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 10/70] 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 11/70] 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 12/70] 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 13/70] 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 14/70] 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 15/70] 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 16/70] 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 17/70] 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 18/70] 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 19/70] 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 20/70] 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 21/70] 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 22/70] 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 23/70] 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 24/70] 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 25/70] 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 26/70] 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 27/70] 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 28/70] 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 29/70] 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 30/70] 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 31/70] 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 32/70] 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 33/70] 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 34/70] 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 35/70] 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 36/70] 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 37/70] 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 38/70] 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 39/70] 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 40/70] 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 41/70] 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 42/70] 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 43/70] 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 44/70] 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 45/70] 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 46/70] 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 47/70] 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 48/70] 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 49/70] 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 50/70] 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 51/70] 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 52/70] 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 53/70] 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 54/70] 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 55/70] 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 56/70] 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 57/70] 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 58/70] 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 59/70] 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 From ef39efd6ace883cd58b17898a5022ecde249dddc Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 15 May 2019 09:43:33 -0400 Subject: [PATCH 60/70] Update install file --- Installation Files/requirements-os.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Installation Files/requirements-os.sh b/Installation Files/requirements-os.sh index 0df25d2..0c980a2 100644 --- a/Installation Files/requirements-os.sh +++ b/Installation Files/requirements-os.sh @@ -20,7 +20,8 @@ rm dev-requirements.txt wget https://raw.githubusercontent.com/SpiceBot/SpiceBot/development/Installation%20Files/requirements.txt pip3 install -r requirements.txt rm requirements.txt -pip3 install sopel +# pip3 install sopel +pip3 install --upgrade --force-reinstall git+https://github.com/sopel-irc/sopel@master mkdir /usr/local/lib/python3.6/dist-packages/sopel/modules/stock mv /usr/local/lib/python3.6/dist-packages/sopel/modules/* /usr/local/lib/python3.6/dist-packages/sopel/modules/stock/ From 99b8fa45ed67006496b36d2f12ad7004fed6abd6 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 15 May 2019 10:11:20 -0400 Subject: [PATCH 61/70] update database deletion key --- sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py b/sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py index 26fc511..e6c4e29 100644 --- a/sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py +++ b/sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py @@ -38,7 +38,7 @@ class SopelDBCache: .one_or_none() # NickValue exists, delete if result: - session.delete(result.value) + session.delete(result) session.commit() except SQLAlchemyError: session.rollback() @@ -85,7 +85,7 @@ class SopelDBCache: .one_or_none() # ChannelValue exists, update if result: - session.delete(result.value) + session.delete(result) session.commit() except SQLAlchemyError: session.rollback() From d0c95e128ea41f36a97df5b6968926bbd42baa21 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 15 May 2019 10:15:22 -0400 Subject: [PATCH 62/70] readd adjusts --- sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py b/sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py index e6c4e29..bc74932 100644 --- a/sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py +++ b/sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py @@ -17,9 +17,9 @@ def setup(bot): # Inject Database Functions bot_logging(bot, 'SpiceBot_Databaseaddons', "Implanting Database functions into bot") SopelDB.delete_nick_value = SopelDBCache.delete_nick_value - # SopelDB.adjust_nick_value = SopelDBCache.adjust_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 + SopelDB.adjust_channel_value = SopelDBCache.adjust_channel_value class SopelDBCache: From 4637220fd5fa3aef44c299f5d4e33f0fdb0e26b8 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 15 May 2019 12:04:53 -0400 Subject: [PATCH 63/70] Adjust to dictionanry format --- sopel_modules/SpiceBot_Events/System.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/sopel_modules/SpiceBot_Events/System.py b/sopel_modules/SpiceBot_Events/System.py index cd7a874..de5492a 100644 --- a/sopel_modules/SpiceBot_Events/System.py +++ b/sopel_modules/SpiceBot_Events/System.py @@ -5,6 +5,7 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi # sopel imports import sopel from sopel.trigger import PreTrigger +# import functools from sopel_modules.SpiceBot_SBTools import bot_logging @@ -18,12 +19,12 @@ class BotEvents(object): """ def __init__(self): - self.usednumbers = [1000] + self.SpiceBot_Events = {"assigned_IDs": [1000]} def __getattr__(self, name): ''' will only get called for undefined attributes ''' - eventnumber = max(self.usednumbers) + 1 - self.usednumbers.append(eventnumber) + eventnumber = max(self.SpiceBot_Events["assigned_IDs"]) + 1 + self.SpiceBot_Events["assigned_IDs"].append(eventnumber) setattr(self, name, str(eventnumber)) return str(eventnumber) @@ -31,6 +32,18 @@ class BotEvents(object): botevents = BotEvents() +""" +def register_trigger(number, message): + def actual_decorator(function): + @functools.wraps(function) + def _nop(*args, **kwargs): + # Assign trigger and bot for easy access later + bot, trigger = args[0:2] + return function(*args, **kwargs) + return _nop +""" + + def setup(bot): bot_logging(bot, 'SpiceBot_Events', "Starting setup procedure") bot_events_setup_check(bot) From 0269ad567da530087d470f78f28da3507d7b52a5 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 15 May 2019 12:45:03 -0400 Subject: [PATCH 64/70] update configuration for flood control methods --- sopel_modules/SpiceBot_osd/__init__.py | 78 +++++++++++++++----------- 1 file changed, 44 insertions(+), 34 deletions(-) diff --git a/sopel_modules/SpiceBot_osd/__init__.py b/sopel_modules/SpiceBot_osd/__init__.py index 7bd3142..905fd71 100644 --- a/sopel_modules/SpiceBot_osd/__init__.py +++ b/sopel_modules/SpiceBot_osd/__init__.py @@ -27,9 +27,13 @@ __version__ = '0.1.2' def configure(config): - config.define_section("MAXTARGCONFIG", MAXTARGCONFIG, validate=False) - config.MAXTARGCONFIG.configure_setting('notice', 'MAXTARG limit for NOTICE') - config.MAXTARGCONFIG.configure_setting('privmsg', 'MAXTARG limit for PRIVMSG') + config.define_section("SpiceBot_OSD", SpiceBot_OSD, validate=False) + config.SpiceBot_OSD.configure_setting('notice', 'MAXTARG limit for NOTICE') + config.SpiceBot_OSD.configure_setting('privmsg', 'MAXTARG limit for PRIVMSG') + config.SpiceBot_OSD.configure_setting('flood_burst_lines', 'How many messages can be sent in burst mode.') + config.SpiceBot_OSD.configure_setting('flood_empty_wait', 'How long to wait between sending messages when not in burst mode, in seconds.') + config.SpiceBot_OSD.configure_setting('flood_refill_rate', 'How quickly burst mode recovers, in messages per second.') + config.SpiceBot_OSD.configure_setting('flood_dots', 'Display dots instead of spam.') def setup(bot): @@ -57,7 +61,7 @@ def setup(bot): # verify config settings for server bot_logging(bot, 'SpiceBot_OSD', "Checking for config settings") - bot.config.define_section("MAXTARGCONFIG", MAXTARGCONFIG, validate=False) + bot.config.define_section("SpiceBot_OSD", SpiceBot_OSD, validate=False) @module.event('005') @@ -80,15 +84,29 @@ def parse_event_005(bot, trigger): value = None if value: if settingname.upper() == 'NOTICE': - bot.config.MAXTARGCONFIG.notice = int(value) + bot.config.SpiceBot_OSD.notice = int(value) elif settingname.upper() == 'PRIVMSG': - bot.config.MAXTARGCONFIG.privmsg = int(value) + bot.config.SpiceBot_OSD.privmsg = int(value) -class MAXTARGCONFIG(StaticSection): +class SpiceBot_OSD(StaticSection): + + """MAXTARG""" notice = ValidatedAttribute('notice', default=1) privmsg = ValidatedAttribute('privmsg', default=1) + flood_burst_lines = ValidatedAttribute('flood_burst_lines', int, default=4) + """How many messages can be sent in burst mode.""" + + flood_empty_wait = ValidatedAttribute('flood_empty_wait', float, default=0.7) + """How long to wait between sending messages when not in burst mode, in seconds.""" + + flood_refill_rate = ValidatedAttribute('flood_refill_rate', int, default=1) + """How quickly burst mode recovers, in messages per second.""" + + flood_dots = ValidatedAttribute('flood_dots', default=True) + """Display dots instead of spam.""" + class ToolsOSD: @@ -117,9 +135,9 @@ class ToolsOSD: raise ValueError("Recipients list empty.") if text_method == 'NOTICE': - maxtargets = bot.config.MAXTARGCONFIG.notice + maxtargets = bot.config.SpiceBot_OSD.notice elif text_method in ['PRIVMSG', 'ACTION']: - maxtargets = bot.config.MAXTARGCONFIG.privmsg + maxtargets = bot.config.SpiceBot_OSD.privmsg maxtargets = int(maxtargets) recipientgroups = [] @@ -259,17 +277,12 @@ class SopelOSD: for recipientgroup in recipientgroups: text_method = text_method_orig - # No messages within the last 3 seconds? Go ahead! - # Otherwise, wait so it's been at least 0.8 seconds + penalty - recipient_id = Identifier(recipientgroup) recipient_stack = self.stack.setdefault(recipient_id, { 'messages': [], - 'flood_left': 4, + 'flood_left': self.config.SpiceBot_OSD.flood_burst_lines, 'dots': 0, - # TODO - # 'flood_left': self.config.core.flood_burst_lines, }) recipient_stack['dots'] = 0 @@ -281,32 +294,30 @@ class SopelOSD: if not recipient_stack['flood_left']: elapsed = time.time() - recipient_stack['messages'][-1][0] - # TODO - # recipient_stack['flood_left'] = min( - # self.config.core.flood_burst_lines, - # int(elapsed) * self.config.core.flood_refill_rate) - recipient_stack['flood_left'] = min(4, int(elapsed) * 1) + recipient_stack['flood_left'] = min( + self.config.SpiceBot_OSD.flood_burst_lines, + int(elapsed) * self.config.SpiceBot_OSD.flood_refill_rate) if not recipient_stack['flood_left']: elapsed = time.time() - recipient_stack['messages'][-1][0] penalty = float(max(0, len(text) - 50)) / 70 # Never wait more than 2 seconds - # wait = min(self.config.core.flood_empty_wait + penalty, 2) # TODO - wait = min(0.7 + penalty, 2) + wait = min(self.config.SpiceBot_OSD.flood_empty_wait + penalty, 2) if elapsed < wait: time.sleep(wait - elapsed) # Loop detection messages = [m[1] for m in recipient_stack['messages'][-8:]] - # If what we about to send repeated at least 5 times in the - # last 2 minutes, replace with '...' - if messages.count(text) >= 5 and elapsed < 120: - recipient_stack['dots'] += 1 - else: - recipient_stack['dots'] = 0 + if self.config.SpiceBot_OSD.flood_dots: + # If what we about to send repeated at least 5 times in the + # last 2 minutes, replace with '...' + if messages.count(text) >= 5 and elapsed < 120: + recipient_stack['dots'] += 1 + else: + recipient_stack['dots'] = 0 - if not recipient_stack['dots'] >= 3: + if recipient_stack['dots'] <= 3: recipient_stack['flood_left'] = max(0, recipient_stack['flood_left'] - 1) recipient_stack['messages'].append((time.time(), self.safe(text))) @@ -377,7 +388,10 @@ class SopelOSD: 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. + """ + .. deprecated:: 6.0 + Use :meth:`say` instead. Will be removed in Sopel 8. + """ self.osd(text, recipient, 'PRIVMSG', max_messages) @@ -392,19 +406,16 @@ class SopelWrapperOSD(object): 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: @@ -416,4 +427,3 @@ class SopelWrapperOSD(object): 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) From 805e075e6c613cad16bddd6992ffc33bcb8d7589 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 15 May 2019 14:44:44 -0400 Subject: [PATCH 65/70] Update KICK, and prepare for another overhault of the event system --- sopel_modules/SpiceBot_Events/System.py | 56 ++++++++++++++++++++++++- sopel_modules/SpiceBot_Kick/__init__.py | 18 ++++---- 2 files changed, 63 insertions(+), 11 deletions(-) diff --git a/sopel_modules/SpiceBot_Events/System.py b/sopel_modules/SpiceBot_Events/System.py index de5492a..b341965 100644 --- a/sopel_modules/SpiceBot_Events/System.py +++ b/sopel_modules/SpiceBot_Events/System.py @@ -16,10 +16,20 @@ class BotEvents(object): Events will be assigned a 4-digit number above 1000. This allows you to do, ``@module.event(botevents.BOT_WELCOME)```` + + Triggers handled by this module will be processed immediately. + Others will be placed into a queue. + + Triggers will be logged by ID and content """ def __init__(self): - self.SpiceBot_Events = {"assigned_IDs": [1000]} + self.SpiceBot_Events = { + "assigned_IDs": [1000], + "triggers_recieved": {}, + "trigger_queue": [], + "startup_required": [] + } def __getattr__(self, name): ''' will only get called for undefined attributes ''' @@ -28,6 +38,44 @@ class BotEvents(object): setattr(self, name, str(eventnumber)) return str(eventnumber) + def trigger(self, number, message="SpiceBot_Events"): + number = str(number) + if number in [self.BOT_WELCOME, self.BOT_READY, self.BOT_CONNECTED, self.BOT_LOADED]: + pretrigger = PreTrigger( + sopel.bot.nick, + ":SpiceBot_Events " + number + " " + str(sopel.bot.nick) + " :" + message + ) + sopel.bot.dispatch(pretrigger) + else: + pretriggerdict = {"number": number, "message": message} + self.SpiceBot_Events["trigger_queue"].append(pretriggerdict) + + def recieved(self, trigger): + eventnumber = str(trigger.event) + message_payload = trigger.args[1] + if eventnumber not in self.SpiceBot_Events["triggers_recieved"]: + self.SpiceBot_Events["triggers_recieved"][eventnumber] = [] + self.SpiceBot_Events["assigned_IDs"]["triggers_recieved"][eventnumber].append(message_payload) + + def check(self, checklist): + if not isinstance(checklist, list): + checklist = [str(checklist)] + for number in checklist: + if str(number) not in self.SpiceBot_Events["triggers_recieved"].keys(): + return False + return True + + def startup_add(self, startlist): + if not isinstance(startlist, list): + startlist = [str(startlist)] + self.SpiceBot_Events["startup_required"].extend(startlist) + + def startup_check(self): + for number in self.SpiceBot_Events["startup_required"]: + if str(number) not in self.SpiceBot_Events["triggers_recieved"].keys(): + return False + return True + botevents = BotEvents() @@ -41,6 +89,12 @@ def register_trigger(number, message): bot, trigger = args[0:2] return function(*args, **kwargs) return _nop + +ideas: + + while not bot_events_check(bot, [botevents.BOT_LOADED, botevents.BOT_COMMANDSQUERY]): + pass + """ diff --git a/sopel_modules/SpiceBot_Kick/__init__.py b/sopel_modules/SpiceBot_Kick/__init__.py index c752bd4..44b8ea5 100644 --- a/sopel_modules/SpiceBot_Kick/__init__.py +++ b/sopel_modules/SpiceBot_Kick/__init__.py @@ -12,7 +12,6 @@ from __future__ import unicode_literals, absolute_import, division, print_functi 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 @@ -28,8 +27,8 @@ __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') + config.define_section("SpiceBot_Kick", SpiceBot_Kick, validate=False) + config.SpiceBot_Kick.configure_setting('kick', 'MAXTARG limit for KICK') def setup(bot): @@ -41,7 +40,7 @@ def setup(bot): # verify config settings for server bot_logging(bot, 'SpiceBot_Kick', "Checking for config settings") - bot.config.define_section("MAXTARGCONFIG_KICK", MAXTARGCONFIG_KICK, validate=False) + bot.config.define_section("SpiceBot_Kick", SpiceBot_Kick, validate=False) @module.event('005') @@ -63,10 +62,10 @@ def parse_event_005(bot, trigger): except IndexError: value = None if value: - bot.config.MAXTARGCONFIG_KICK.kick = int(value) + bot.config.SpiceBot_Kick.kick = int(value) -class MAXTARGCONFIG_KICK(StaticSection): +class SpiceBot_Kick(StaticSection): kick = ValidatedAttribute('kick', default=1) @@ -80,8 +79,7 @@ class SopelKICK: 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) + self.write(['KICK', channel, nick], text) class SopelWrapperKICK(object): @@ -89,9 +87,9 @@ class SopelWrapperKICK(object): def kick(self, nick, channel=None, message=None): if channel is None: if self._trigger.is_privmsg: - return + raise RuntimeError('Error: KICK requires a channel.') else: channel = self._trigger.sender if nick is None: - return + raise RuntimeError('Error: KICK requires a nick.') self._bot.kick(nick, channel, message) From 39a246d9e7956f47f892f1e535d2907d5daa4c75 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 15 May 2019 15:37:19 -0400 Subject: [PATCH 66/70] First hardcore test of new class system --- sopel_modules/SpiceBot_AI/AI.py | 4 +- sopel_modules/SpiceBot_Channels/Channels.py | 10 +-- .../SpiceBot_Channels/Channels_Command.py | 4 +- .../SpiceBot_CommandsQuery/CommandsQuery.py | 10 +-- .../NickQueryCommand.py | 4 +- .../SpiceBot_CommandsQuery/QueryCommand.py | 4 +- sopel_modules/SpiceBot_Events/Events.py | 44 +++++------ sopel_modules/SpiceBot_Events/System.py | 79 +------------------ 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 | 6 +- sopel_modules/SpiceBot_Logs/ErrorDisplay.py | 4 +- sopel_modules/SpiceBot_Logs/Logs.py | 10 +-- sopel_modules/SpiceBot_Logs/Logs_Command.py | 4 +- .../StartupMonologue.py | 6 +- .../StartupMonologue_Display.py | 18 ++--- 17 files changed, 71 insertions(+), 152 deletions(-) diff --git a/sopel_modules/SpiceBot_AI/AI.py b/sopel_modules/SpiceBot_AI/AI.py index 7ae029b..6927abb 100644 --- a/sopel_modules/SpiceBot_AI/AI.py +++ b/sopel_modules/SpiceBot_AI/AI.py @@ -7,13 +7,13 @@ 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 botevents @sopel.module.nickname_commands('(.*)') def bot_command_nick(bot, trigger): - while not bot_events_check(bot, [botevents.BOT_LOADED, botevents.BOT_COMMANDSQUERY]): + while not botevents.check([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 5bb11d6..69aaa06 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 botevents from sopel_modules.SpiceBot_SBTools import ( join_all_channels, chanadmin_all_channels, channel_list_current, bot_logging @@ -34,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]) + botevents.startup_add([botevents.BOT_CHANNELS]) bot.config.define_section("SpiceBot_Channels", SpiceBot_Channels_MainSection, validate=False) @@ -50,7 +50,7 @@ def shutdown(bot): @sopel.module.event(botevents.BOT_CONNECTED) @sopel.module.rule('.*') def trigger_channel_list_initial(bot, trigger): - bot_events_recieved(bot, trigger.event) + botevents.recieved(trigger) # Unkickable bot.write(('SAMODE', bot.nick, '+q')) @@ -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, botevents.BOT_CHANNELS, "SpiceBot_Channels") + botevents.trigger(botevents.BOT_CHANNELS, "SpiceBot_Channels") join_all_channels(bot) chanadmin_all_channels(bot) @@ -126,4 +126,4 @@ def bot_part_empty(bot): @sopel.module.event(botevents.BOT_CHANNELS) @sopel.module.rule('.*') def bot_events_setup(bot, trigger): - bot_events_recieved(bot, trigger.event) + botevents.recieved(trigger) diff --git a/sopel_modules/SpiceBot_Channels/Channels_Command.py b/sopel_modules/SpiceBot_Channels/Channels_Command.py index c7e69bc..df4010d 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, botevents +from sopel_modules.SpiceBot_Events.System import 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, botevents.BOT_LOADED): + while not botevents.check(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 434630e..a9d115d 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, botevents +from sopel_modules.SpiceBot_Events.System import botevents from sopel_modules.SpiceBot_SBTools import bot_logging import spicemanip @@ -15,7 +15,7 @@ import spicemanip def setup(bot): bot_logging(bot, 'SpiceBot_CommandsQuery', "Starting setup procedure") - bot_events_startup_register(bot, [botevents.BOT_COMMANDSQUERY]) + botevents.startup_add([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, botevents.BOT_COMMANDSQUERY, "SpiceBot_CommandsQuery") + botevents.trigger(botevents.BOT_COMMANDSQUERY, "SpiceBot_CommandsQuery") def shutdown(bot): @@ -173,7 +173,7 @@ def shutdown(bot): @sopel.module.event(botevents.BOT_LOADED) @sopel.module.rule('.*') def bot_events_complete(bot, trigger): - bot_events_recieved(bot, trigger.event) + botevents.recieved(trigger) for comtype in bot.memory['SpiceBot_CommandsQuery']['commands'].keys(): if comtype not in ['module', 'nickname', 'rule']: @@ -217,4 +217,4 @@ def commandsquery_register(bot, command_type, validcoms, aliasfor=None): @sopel.module.event(botevents.BOT_COMMANDSQUERY) @sopel.module.rule('.*') def bot_events_setup(bot, trigger): - bot_events_recieved(bot, trigger.event) + botevents.recieved(trigger) diff --git a/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py b/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py index 67782f3..c618737 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, botevents +from sopel_modules.SpiceBot_Events.System import 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, botevents.BOT_COMMANDSQUERY): + while not botevents.check(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 8f8011b..81d60f2 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, botevents +from sopel_modules.SpiceBot_Events.System import 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, botevents.BOT_COMMANDSQUERY): + while not botevents.check(botevents.BOT_COMMANDSQUERY): pass triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'query_command') diff --git a/sopel_modules/SpiceBot_Events/Events.py b/sopel_modules/SpiceBot_Events/Events.py index 730cb4f..ebd095e 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, botevents +from .System import botevents from sopel_modules.SpiceBot_SBTools import bot_logging import time @@ -14,59 +14,53 @@ import time @sopel.module.event('001') @sopel.module.rule('.*') def bot_startup_connection(bot, trigger): - bot_events_trigger(bot, botevents.BOT_WELCOME, "Welcome to the SpiceBot Events System") + botevents.trigger(botevents.BOT_WELCOME, "Welcome to the SpiceBot Events System") while not len(bot.channels.keys()) > 0: pass time.sleep(1) - bot_events_trigger(bot, botevents.BOT_CONNECTED, "Bot Connected to IRC") + botevents.trigger(botevents.BOT_CONNECTED, "Bot Connected to IRC") @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) + botevents.recieved(trigger) - bot_events_trigger(bot, botevents.BOT_READY, "Ready To Process module setup procedures") + botevents.trigger(botevents.BOT_READY, "Ready To Process module setup procedures") - while not bot_events_startup_check(bot): + while not botevents.startup_check(): pass - bot_events_trigger(bot, botevents.BOT_LOADED, "All registered modules setup procedures have completed") + botevents.trigger(botevents.BOT_LOADED, "All registered modules setup procedures have completed") @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) + botevents.recieved(trigger) @sopel.module.event(botevents.BOT_CONNECTED) @sopel.module.rule('.*') def bot_events_connected(bot, trigger): bot_logging(bot, 'SpiceBot_Events', trigger.args[1], True) - bot_events_recieved(bot, trigger.event) - - bot_events_setup_check(bot) - + botevents.recieved(trigger) while True: - try: - if len(bot.memory['SpiceBot_Events']["queue"]): - number = bot.memory['SpiceBot_Events']["queue"][0]["number"] - message = bot.memory['SpiceBot_Events']["queue"][0]["message"] - pretrigger = PreTrigger( - bot.nick, - ":SpiceBot_Events " + str(number) + " " + str(bot.nick) + " :" + message - ) - bot.dispatch(pretrigger) - del bot.memory['SpiceBot_Events']["queue"][0] - except KeyError: - return + if len(botevents.SpiceBot_Events["trigger_queue"]): + number = botevents.SpiceBot_Events["trigger_queue"][0]["number"] + message = botevents.SpiceBot_Events["trigger_queue"][0]["message"] + pretrigger = PreTrigger( + bot.nick, + ":SpiceBot_Events " + str(number) + " " + str(bot.nick) + " :" + message + ) + bot.dispatch(pretrigger) + del botevents.SpiceBot_Events["trigger_queue"][0] @sopel.module.event(botevents.BOT_LOADED) @sopel.module.rule('.*') def bot_events_complete(bot, trigger): bot_logging(bot, 'SpiceBot_Events', trigger.args[1], True) - bot_events_recieved(bot, trigger.event) + botevents.recieved(trigger) diff --git a/sopel_modules/SpiceBot_Events/System.py b/sopel_modules/SpiceBot_Events/System.py index b341965..b5b9aed 100644 --- a/sopel_modules/SpiceBot_Events/System.py +++ b/sopel_modules/SpiceBot_Events/System.py @@ -92,7 +92,7 @@ def register_trigger(number, message): ideas: - while not bot_events_check(bot, [botevents.BOT_LOADED, botevents.BOT_COMMANDSQUERY]): + while not botevents.check([botevents.BOT_LOADED, botevents.BOT_COMMANDSQUERY]): pass """ @@ -100,79 +100,4 @@ ideas: 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) - - bot.memory["SpiceBot_Events"]["triggers"][str(number)] = message - 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 - ) - bot.dispatch(pretrigger) - else: - pretriggerdict = {"number": number, "message": message} - bot.memory['SpiceBot_Events']["queue"].append(pretriggerdict) - - -def bot_events_setup_check(bot): - if "SpiceBot_Events" not in bot.memory: - bot.memory["SpiceBot_Events"] = {"triggers": {}, "startup": [], "loaded": [], "queue": []} - - -def bot_events_check(bot, listreq): - - bot_events_setup_check(bot) - - if not isinstance(listreq, list): - listreq = [str(listreq)] - - for requirement in listreq: - if requirement not in bot.memory["SpiceBot_Events"]["loaded"]: - return False - - return True - - -def bot_events_startup_register(bot, addonreq): - - bot_events_setup_check(bot) - - if not isinstance(addonreq, list): - addonreq = [str(addonreq)] - - bot.memory["SpiceBot_Events"]["startup"].extend(addonreq) - - -def bot_events_recieved(bot, number): - - bot_events_setup_check(bot) - - if str(number) not in bot.memory["SpiceBot_Events"]["loaded"]: - bot.memory["SpiceBot_Events"]["loaded"].append(str(number)) - - -def bot_events_startup_check(bot): - - bot_events_setup_check(bot) - - notcomplete = [] - - for startupitem in bot.memory["SpiceBot_Events"]["startup"]: - if str(startupitem) not in bot.memory["SpiceBot_Events"]["loaded"]: - notcomplete.append(str(startupitem)) - - if len(notcomplete): - return False - else: - return True + botevents.startup_add([botevents.BOT_WELCOME, botevents.BOT_READY, botevents.BOT_CONNECTED]) diff --git a/sopel_modules/SpiceBot_GifSearch/gif.py b/sopel_modules/SpiceBot_GifSearch/gif.py index 6c344a9..eaa4ac8 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, botevents +from sopel_modules.SpiceBot_Events.System import botevents import spicemanip @@ -15,7 +15,7 @@ import spicemanip @module.commands('gif') def gif_trigger(bot, trigger): - while not bot_events_check(bot, botevents.BOT_GIFSEARCH): + while not botevents.check(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 fa500b9..cc7f9e3 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, botevents +from sopel_modules.SpiceBot_Events.System import botevents @sopel.module.commands('(.*)') def gifapi_triggers(bot, trigger): - while not bot_events_check(bot, botevents.BOT_GIFSEARCH): + while not botevents.check(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 884bd11..4050664 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, botevents +from sopel_modules.SpiceBot_Events.System import 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, [botevents.BOT_GIFSEARCH]) + botevents.startup_add([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, botevents.BOT_GIFSEARCH, "SpiceBot_GifSearch") + botevents.trigger(botevents.BOT_GIFSEARCH, "SpiceBot_GifSearch") def shutdown(bot): @@ -254,4 +254,4 @@ def getGif(bot, searchdict): @sopel.module.event(botevents.BOT_GIFSEARCH) @sopel.module.rule('.*') def bot_events_setup(bot, trigger): - bot_events_recieved(bot, trigger.event) + botevents.recieved(trigger) diff --git a/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py b/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py index 73250cb..abda513 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, botevents +from sopel_modules.SpiceBot_Events.System import botevents def setup(bot): @@ -21,7 +21,7 @@ def shutdown(bot): @sopel.module.event(botevents.BOT_LOADED) @sopel.module.rule('.*') def bot_events_complete(bot, trigger): - bot_events_recieved(bot, trigger.event) + botevents.recieved(trigger) for comtype in bot.memory['SpiceBot_CommandsQuery']['commands'].keys(): bot.memory["SpiceBot_InvalidCommand"]["valid"].extend(bot.memory['SpiceBot_CommandsQuery']['commands'][comtype].keys()) @@ -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, botevents.BOT_COMMANDSQUERY]): + while not botevents.check([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 1a18456..1deb454 100644 --- a/sopel_modules/SpiceBot_Logs/ErrorDisplay.py +++ b/sopel_modules/SpiceBot_Logs/ErrorDisplay.py @@ -4,7 +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, botevents +from sopel_modules.SpiceBot_Events.System import botevents from sopel_modules.SpiceBot_SBTools import bot_logging from .Logs import stdio_logs_fetch @@ -12,7 +12,7 @@ from .Logs import stdio_logs_fetch @sopel.module.event(botevents.BOT_STARTUPMONOLOGUE) @sopel.module.rule('.*') def bot_startup_monologue_start(bot, trigger): - bot_events_recieved(bot, trigger.event) + botevents.recieved(trigger) debuglines = stdio_logs_fetch(bot) diff --git a/sopel_modules/SpiceBot_Logs/Logs.py b/sopel_modules/SpiceBot_Logs/Logs.py index e764855..ed38629 100644 --- a/sopel_modules/SpiceBot_Logs/Logs.py +++ b/sopel_modules/SpiceBot_Logs/Logs.py @@ -6,7 +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 +from sopel_modules.SpiceBot_Events.System import botevents import os @@ -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, [botevents.BOT_LOGS]) + botevents.startup_add([botevents.BOT_LOGS]) bot_logs_setup_check(bot) - bot_events_trigger(bot, botevents.BOT_LOGS, "SpiceBot_Logs") + botevents.trigger(botevents.BOT_LOGS, "SpiceBot_Logs") def bot_logs_setup_check(bot): @@ -46,7 +46,7 @@ def shutdown(bot): @sopel.module.event(botevents.BOT_CONNECTED) @sopel.module.rule('.*') def join_log_channel(bot, trigger): - bot_events_recieved(bot, trigger.event) + botevents.recieved(trigger) if bot.config.SpiceBot_Logs.logging_channel: channel = bot.config.SpiceBot_Logs.logging_channel @@ -134,4 +134,4 @@ def get_running_pid(bot): @sopel.module.event(botevents.BOT_LOGS) @sopel.module.rule('.*') def bot_events_setup(bot, trigger): - bot_events_recieved(bot, trigger.event) + botevents.recieved(trigger) diff --git a/sopel_modules/SpiceBot_Logs/Logs_Command.py b/sopel_modules/SpiceBot_Logs/Logs_Command.py index a095e39..63b3b36 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, botevents +from sopel_modules.SpiceBot_Events.System import 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, botevents.BOT_LOGS): + while not botevents.check(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 fd5b640..032162a 100644 --- a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py +++ b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py @@ -4,13 +4,13 @@ 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, botevents +from sopel_modules.SpiceBot_Events.System import 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, [botevents.BOT_STARTUPMONOLOGUE_CHANNELS, botevents.BOT_STARTUPMONOLOGUE_COMMANDSQUERY, botevents.BOT_STARTUPMONOLOGUE_CONNECTED]) + botevents.startup_add([botevents.BOT_STARTUPMONOLOGUE_CHANNELS, botevents.BOT_STARTUPMONOLOGUE_COMMANDSQUERY, botevents.BOT_STARTUPMONOLOGUE_CONNECTED]) if 'SpiceBot_StartupMonologue' not in bot.memory: bot.memory['SpiceBot_StartupMonologue'] = [] @@ -19,4 +19,4 @@ def setup(bot): @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) + botevents.recieved(trigger) diff --git a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py index 77e15f5..d47dc76 100644 --- a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py +++ b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py @@ -4,7 +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 +from sopel_modules.SpiceBot_Events.System import botevents from sopel_modules.SpiceBot_SBTools import humanized_time, bot_logging import time @@ -13,19 +13,19 @@ import time @sopel.module.event(botevents.BOT_CONNECTED) @sopel.module.rule('.*') def bot_startup_monologue_start(bot, trigger): - bot_events_recieved(bot, trigger.event) + botevents.recieved(trigger) # Startup 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, botevents.BOT_STARTUPMONOLOGUE_CONNECTED, "SpiceBot_StartupMonologue") + botevents.trigger(botevents.BOT_STARTUPMONOLOGUE_CONNECTED, "SpiceBot_StartupMonologue") @sopel.module.event(botevents.BOT_COMMANDSQUERY) @sopel.module.rule('.*') def bot_startup_monologue_commands(bot, trigger): - bot_events_recieved(bot, trigger.event) + botevents.recieved(trigger) availablecomsnum, availablecomsfiles = 0, 0 for commandstype in bot.memory['SpiceBot_CommandsQuery']['commands'].keys(): @@ -35,25 +35,25 @@ 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, botevents.BOT_STARTUPMONOLOGUE_COMMANDSQUERY, "SpiceBot_StartupMonologue") + botevents.trigger(botevents.BOT_STARTUPMONOLOGUE_COMMANDSQUERY, "SpiceBot_StartupMonologue") @sopel.module.event(botevents.BOT_CHANNELS) @sopel.module.rule('.*') def bot_startup_monologue_channels(bot, trigger): - bot_events_recieved(bot, trigger.event) + botevents.recieved(trigger) botcount = len(bot.channels.keys()) 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, botevents.BOT_STARTUPMONOLOGUE_CHANNELS, "SpiceBot_StartupMonologue") + botevents.trigger(botevents.BOT_STARTUPMONOLOGUE_CHANNELS, "SpiceBot_StartupMonologue") @sopel.module.event(botevents.BOT_LOADED) @sopel.module.rule('.*') def bot_startup_monologue_display(bot, trigger): - bot_events_recieved(bot, trigger.event) + botevents.recieved(trigger) timesince = humanized_time(time.time() - bot.memory["SpiceBot_Uptime"]) bot.memory['SpiceBot_StartupMonologue'].append("Startup took " + timesince) @@ -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, botevents.BOT_STARTUPMONOLOGUE, "SpiceBot_StartupMonologue") + botevents.trigger(botevents.BOT_STARTUPMONOLOGUE, "SpiceBot_StartupMonologue") bot_logging(bot, 'SpiceBot_StartupMonologue', "Startup Monologue has been issued to all channels.", True) From 2d08f3befddecd044ea346c343c9cb530bb4321e Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 15 May 2019 15:41:44 -0400 Subject: [PATCH 67/70] bot --- sopel_modules/SpiceBot_Channels/Channels.py | 2 +- sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py | 2 +- sopel_modules/SpiceBot_Events/Events.py | 8 ++++---- sopel_modules/SpiceBot_Events/System.py | 8 ++++---- sopel_modules/SpiceBot_GifSearch/gifsearch.py | 2 +- sopel_modules/SpiceBot_Logs/Logs.py | 2 +- .../SpiceBot_StartupMonologue/StartupMonologue_Display.py | 8 ++++---- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/sopel_modules/SpiceBot_Channels/Channels.py b/sopel_modules/SpiceBot_Channels/Channels.py index 69aaa06..8e53d6c 100644 --- a/sopel_modules/SpiceBot_Channels/Channels.py +++ b/sopel_modules/SpiceBot_Channels/Channels.py @@ -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.") - botevents.trigger(botevents.BOT_CHANNELS, "SpiceBot_Channels") + botevents.trigger(bot, botevents.BOT_CHANNELS, "SpiceBot_Channels") join_all_channels(bot) chanadmin_all_channels(bot) diff --git a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py index a9d115d..dac3030 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py +++ b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py @@ -162,7 +162,7 @@ def setup(bot): if command not in bot.memory['SpiceBot_CommandsQuery']['nickrules']: bot.memory['SpiceBot_CommandsQuery']['nickrules'].append(command) - botevents.trigger(botevents.BOT_COMMANDSQUERY, "SpiceBot_CommandsQuery") + botevents.trigger(bot, botevents.BOT_COMMANDSQUERY, "SpiceBot_CommandsQuery") def shutdown(bot): diff --git a/sopel_modules/SpiceBot_Events/Events.py b/sopel_modules/SpiceBot_Events/Events.py index ebd095e..5933e42 100644 --- a/sopel_modules/SpiceBot_Events/Events.py +++ b/sopel_modules/SpiceBot_Events/Events.py @@ -14,12 +14,12 @@ import time @sopel.module.event('001') @sopel.module.rule('.*') def bot_startup_connection(bot, trigger): - botevents.trigger(botevents.BOT_WELCOME, "Welcome to the SpiceBot Events System") + botevents.trigger(bot, botevents.BOT_WELCOME, "Welcome to the SpiceBot Events System") while not len(bot.channels.keys()) > 0: pass time.sleep(1) - botevents.trigger(botevents.BOT_CONNECTED, "Bot Connected to IRC") + botevents.trigger(bot, botevents.BOT_CONNECTED, "Bot Connected to IRC") @sopel.module.event(botevents.BOT_WELCOME) @@ -28,11 +28,11 @@ def bot_events_start(bot, trigger): bot_logging(bot, 'SpiceBot_Events', trigger.args[1], True) botevents.recieved(trigger) - botevents.trigger(botevents.BOT_READY, "Ready To Process module setup procedures") + botevents.trigger(bot, botevents.BOT_READY, "Ready To Process module setup procedures") while not botevents.startup_check(): pass - botevents.trigger(botevents.BOT_LOADED, "All registered modules setup procedures have completed") + botevents.trigger(bot, botevents.BOT_LOADED, "All registered modules setup procedures have completed") @sopel.module.event(botevents.BOT_READY) diff --git a/sopel_modules/SpiceBot_Events/System.py b/sopel_modules/SpiceBot_Events/System.py index b5b9aed..2569ea5 100644 --- a/sopel_modules/SpiceBot_Events/System.py +++ b/sopel_modules/SpiceBot_Events/System.py @@ -38,14 +38,14 @@ class BotEvents(object): setattr(self, name, str(eventnumber)) return str(eventnumber) - def trigger(self, number, message="SpiceBot_Events"): + def trigger(self, bot, number, message="SpiceBot_Events"): number = str(number) if number in [self.BOT_WELCOME, self.BOT_READY, self.BOT_CONNECTED, self.BOT_LOADED]: pretrigger = PreTrigger( - sopel.bot.nick, - ":SpiceBot_Events " + number + " " + str(sopel.bot.nick) + " :" + message + bot.nick, + ":SpiceBot_Events " + number + " " + str(bot.nick) + " :" + message ) - sopel.bot.dispatch(pretrigger) + bot.dispatch(pretrigger) else: pretriggerdict = {"number": number, "message": message} self.SpiceBot_Events["trigger_queue"].append(pretriggerdict) diff --git a/sopel_modules/SpiceBot_GifSearch/gifsearch.py b/sopel_modules/SpiceBot_GifSearch/gifsearch.py index 4050664..0ef935e 100644 --- a/sopel_modules/SpiceBot_GifSearch/gifsearch.py +++ b/sopel_modules/SpiceBot_GifSearch/gifsearch.py @@ -79,7 +79,7 @@ def setup(bot): if validgifapi not in bot.memory["SpiceBot_GifSearch"]['cache'].keys(): bot.memory["SpiceBot_GifSearch"]['cache'][validgifapi] = dict() - botevents.trigger(botevents.BOT_GIFSEARCH, "SpiceBot_GifSearch") + botevents.trigger(bot, botevents.BOT_GIFSEARCH, "SpiceBot_GifSearch") def shutdown(bot): diff --git a/sopel_modules/SpiceBot_Logs/Logs.py b/sopel_modules/SpiceBot_Logs/Logs.py index ed38629..69cfc15 100644 --- a/sopel_modules/SpiceBot_Logs/Logs.py +++ b/sopel_modules/SpiceBot_Logs/Logs.py @@ -30,7 +30,7 @@ def setup(bot): bot_logs_setup_check(bot) - botevents.trigger(botevents.BOT_LOGS, "SpiceBot_Logs") + botevents.trigger(bot, botevents.BOT_LOGS, "SpiceBot_Logs") def bot_logs_setup_check(bot): diff --git a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py index d47dc76..43c687e 100644 --- a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py +++ b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue_Display.py @@ -19,7 +19,7 @@ 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') - botevents.trigger(botevents.BOT_STARTUPMONOLOGUE_CONNECTED, "SpiceBot_StartupMonologue") + botevents.trigger(bot, botevents.BOT_STARTUPMONOLOGUE_CONNECTED, "SpiceBot_StartupMonologue") @sopel.module.event(botevents.BOT_COMMANDSQUERY) @@ -35,7 +35,7 @@ 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.") - botevents.trigger(botevents.BOT_STARTUPMONOLOGUE_COMMANDSQUERY, "SpiceBot_StartupMonologue") + botevents.trigger(bot, botevents.BOT_STARTUPMONOLOGUE_COMMANDSQUERY, "SpiceBot_StartupMonologue") @sopel.module.event(botevents.BOT_CHANNELS) @@ -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.") - botevents.trigger(botevents.BOT_STARTUPMONOLOGUE_CHANNELS, "SpiceBot_StartupMonologue") + botevents.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') - botevents.trigger(botevents.BOT_STARTUPMONOLOGUE, "SpiceBot_StartupMonologue") + botevents.trigger(bot, botevents.BOT_STARTUPMONOLOGUE, "SpiceBot_StartupMonologue") bot_logging(bot, 'SpiceBot_StartupMonologue', "Startup Monologue has been issued to all channels.", True) From 33b086ac59214827bf576a45172b06d230e56336 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 15 May 2019 15:45:16 -0400 Subject: [PATCH 68/70] oops --- 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 2569ea5..b37bc3c 100644 --- a/sopel_modules/SpiceBot_Events/System.py +++ b/sopel_modules/SpiceBot_Events/System.py @@ -55,7 +55,7 @@ class BotEvents(object): message_payload = trigger.args[1] if eventnumber not in self.SpiceBot_Events["triggers_recieved"]: self.SpiceBot_Events["triggers_recieved"][eventnumber] = [] - self.SpiceBot_Events["assigned_IDs"]["triggers_recieved"][eventnumber].append(message_payload) + self.SpiceBot_Events["triggers_recieved"][eventnumber].append(message_payload) def check(self, checklist): if not isinstance(checklist, list): From f5464a8b8be72d46b27bb885729be60d3b750879 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 15 May 2019 16:11:17 -0400 Subject: [PATCH 69/70] attempt first usage of decorator --- sopel_modules/SpiceBot_AI/AI.py | 5 ++-- .../SpiceBot_Channels/Channels_Command.py | 5 ++-- .../NickQueryCommand.py | 5 ++-- .../SpiceBot_CommandsQuery/QueryCommand.py | 5 ++-- sopel_modules/SpiceBot_Events/System.py | 24 ++++++++++++++----- sopel_modules/SpiceBot_GifSearch/gif.py | 5 ++-- sopel_modules/SpiceBot_GifSearch/gifapi.py | 5 ++-- .../SpiceBot_InvalidCommand/InvalidCommand.py | 5 ++-- sopel_modules/SpiceBot_Logs/Logs_Command.py | 5 ++-- 9 files changed, 42 insertions(+), 22 deletions(-) diff --git a/sopel_modules/SpiceBot_AI/AI.py b/sopel_modules/SpiceBot_AI/AI.py index 6927abb..b28ed08 100644 --- a/sopel_modules/SpiceBot_AI/AI.py +++ b/sopel_modules/SpiceBot_AI/AI.py @@ -10,11 +10,12 @@ from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, googlesearch, bot_ from sopel_modules.SpiceBot_Events.System import botevents +@botevents.check_ready([botevents.BOT_LOADED, botevents.BOT_COMMANDSQUERY]) @sopel.module.nickname_commands('(.*)') def bot_command_nick(bot, trigger): - while not botevents.check([botevents.BOT_LOADED, botevents.BOT_COMMANDSQUERY]): - pass + # while not botevents.check([botevents.BOT_LOADED, botevents.BOT_COMMANDSQUERY]): + # pass triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'nickname_command') diff --git a/sopel_modules/SpiceBot_Channels/Channels_Command.py b/sopel_modules/SpiceBot_Channels/Channels_Command.py index df4010d..92ae05c 100644 --- a/sopel_modules/SpiceBot_Channels/Channels_Command.py +++ b/sopel_modules/SpiceBot_Channels/Channels_Command.py @@ -14,11 +14,12 @@ from sopel_modules.SpiceBot_SBTools import ( from .Channels import bot_part_empty +@botevents.check_ready([botevents.BOT_LOADED]) @sopel.module.nickname_commands('channels', 'channel') def nickname_comand_channels(bot, trigger): - while not botevents.check(botevents.BOT_LOADED): - pass + # while not botevents.check(botevents.BOT_LOADED): + # pass triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'nickname_command') diff --git a/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py b/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py index c618737..2e81930 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py +++ b/sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py @@ -12,11 +12,12 @@ from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, similar_list, lett import spicemanip +@botevents.check_ready([botevents.BOT_COMMANDSQUERY]) @sopel.module.nickname_commands('(.*)') def query_detection_nick(bot, trigger): - while not botevents.check(botevents.BOT_COMMANDSQUERY): - pass + # while not botevents.check(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 81d60f2..a4aec45 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py +++ b/sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py @@ -12,11 +12,12 @@ from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, similar_list, lett import spicemanip +@botevents.check_ready([botevents.BOT_COMMANDSQUERY]) @sopel.module.rule('^\?(.*)') def query_detection(bot, trigger): - while not botevents.check(botevents.BOT_COMMANDSQUERY): - pass + # while not botevents.check(botevents.BOT_COMMANDSQUERY): + # pass triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'query_command') diff --git a/sopel_modules/SpiceBot_Events/System.py b/sopel_modules/SpiceBot_Events/System.py index b37bc3c..88bc79e 100644 --- a/sopel_modules/SpiceBot_Events/System.py +++ b/sopel_modules/SpiceBot_Events/System.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi # sopel imports import sopel from sopel.trigger import PreTrigger -# import functools +import functools from sopel_modules.SpiceBot_SBTools import bot_logging @@ -76,10 +76,27 @@ class BotEvents(object): return False return True + def check_ready(self, checklist): + def actual_decorator(function): + @functools.wraps(function) + def _nop(*args, **kwargs): + # Assign trigger and bot for easy access later + bot, trigger = args[0:2] + while not self.check(checklist): + pass + return function(*args, **kwargs) + return _nop + return actual_decorator + botevents = BotEvents() +def setup(bot): + bot_logging(bot, 'SpiceBot_Events', "Starting setup procedure") + botevents.startup_add([botevents.BOT_WELCOME, botevents.BOT_READY, botevents.BOT_CONNECTED]) + + """ def register_trigger(number, message): def actual_decorator(function): @@ -96,8 +113,3 @@ ideas: pass """ - - -def setup(bot): - bot_logging(bot, 'SpiceBot_Events', "Starting setup procedure") - botevents.startup_add([botevents.BOT_WELCOME, botevents.BOT_READY, botevents.BOT_CONNECTED]) diff --git a/sopel_modules/SpiceBot_GifSearch/gif.py b/sopel_modules/SpiceBot_GifSearch/gif.py index eaa4ac8..a33f6f6 100644 --- a/sopel_modules/SpiceBot_GifSearch/gif.py +++ b/sopel_modules/SpiceBot_GifSearch/gif.py @@ -12,11 +12,12 @@ from sopel_modules.SpiceBot_Events.System import botevents import spicemanip +@botevents.check_ready([botevents.BOT_GIFSEARCH]) @module.commands('gif') def gif_trigger(bot, trigger): - while not botevents.check(botevents.BOT_GIFSEARCH): - pass + # while not botevents.check(botevents.BOT_GIFSEARCH): + # pass triggerargs, triggercommand = sopel_triggerargs(bot, trigger) if not len(triggerargs): diff --git a/sopel_modules/SpiceBot_GifSearch/gifapi.py b/sopel_modules/SpiceBot_GifSearch/gifapi.py index cc7f9e3..c47d7b8 100644 --- a/sopel_modules/SpiceBot_GifSearch/gifapi.py +++ b/sopel_modules/SpiceBot_GifSearch/gifapi.py @@ -12,11 +12,12 @@ from sopel_modules.SpiceBot_SBTools import sopel_triggerargs from sopel_modules.SpiceBot_Events.System import botevents +@botevents.check_ready([botevents.BOT_GIFSEARCH]) @sopel.module.commands('(.*)') def gifapi_triggers(bot, trigger): - while not botevents.check(botevents.BOT_GIFSEARCH): - pass + # while not botevents.check(botevents.BOT_GIFSEARCH): + # pass triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'prefix_command') diff --git a/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py b/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py index abda513..e694bcc 100644 --- a/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py +++ b/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py @@ -27,12 +27,13 @@ def bot_events_complete(bot, trigger): bot.memory["SpiceBot_InvalidCommand"]["valid"].extend(bot.memory['SpiceBot_CommandsQuery']['commands'][comtype].keys()) +@botevents.check_ready([botevents.BOT_LOADED, botevents.BOT_COMMANDSQUERY]) @sopel.module.commands('(.*)') def InvalidCommand_triggers(bot, trigger): return - while not botevents.check([botevents.BOT_LOADED, botevents.BOT_COMMANDSQUERY]): - pass + # while not botevents.check([botevents.BOT_LOADED, botevents.BOT_COMMANDSQUERY]): + # pass triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'prefix_command') diff --git a/sopel_modules/SpiceBot_Logs/Logs_Command.py b/sopel_modules/SpiceBot_Logs/Logs_Command.py index 63b3b36..fcf83a6 100644 --- a/sopel_modules/SpiceBot_Logs/Logs_Command.py +++ b/sopel_modules/SpiceBot_Logs/Logs_Command.py @@ -11,11 +11,12 @@ from sopel_modules.SpiceBot_Events.System import botevents from .Logs import systemd_logs_fetch, stdio_logs_fetch +@botevents.check_ready([botevents.BOT_LOGS]) @sopel.module.nickname_commands('logs', 'debug') def bot_command_logs(bot, trigger): - while not botevents.check(botevents.BOT_LOGS): - pass + # while not botevents.check(botevents.BOT_LOGS): + # pass if not command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']): bot.say("I was unable to process this Bot Nick command due to privilege issues.") From fbe22143fc5f9d7ca72ef2c6c30ae4d459b3e71e Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 15 May 2019 16:17:54 -0400 Subject: [PATCH 70/70] success is nice --- sopel_modules/SpiceBot_Events/System.py | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/sopel_modules/SpiceBot_Events/System.py b/sopel_modules/SpiceBot_Events/System.py index 88bc79e..98b73ac 100644 --- a/sopel_modules/SpiceBot_Events/System.py +++ b/sopel_modules/SpiceBot_Events/System.py @@ -95,21 +95,3 @@ botevents = BotEvents() def setup(bot): bot_logging(bot, 'SpiceBot_Events', "Starting setup procedure") botevents.startup_add([botevents.BOT_WELCOME, botevents.BOT_READY, botevents.BOT_CONNECTED]) - - -""" -def register_trigger(number, message): - def actual_decorator(function): - @functools.wraps(function) - def _nop(*args, **kwargs): - # Assign trigger and bot for easy access later - bot, trigger = args[0:2] - return function(*args, **kwargs) - return _nop - -ideas: - - while not botevents.check([botevents.BOT_LOADED, botevents.BOT_COMMANDSQUERY]): - pass - -"""