From 1c4e07d39caf090dd5156825b3aa904b88943f55 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 3 Jul 2019 09:32:53 -0400 Subject: [PATCH] insert bot loaded check into prerun --- sopel_modules/SpiceBot/Prerun.py | 5 +++++ sopel_modules/SpiceBot/setup.py | 22 +++++++++---------- sopel_modules/SpiceBot_Core_Commands/AI.py | 1 - .../SpiceBot_Core_Commands/BotPrivs.py | 2 -- .../SpiceBot_Core_Commands/Channels.py | 1 - .../SpiceBot_Core_Commands/Commands.py | 1 - .../SpiceBot_Core_Commands/CommandsQuery.py | 4 ---- .../SpiceBot_Core_Commands/Database.py | 2 +- .../SpiceBot_Core_Commands/DictComs.py | 1 - sopel_modules/SpiceBot_Core_Commands/Docs.py | 2 +- sopel_modules/SpiceBot_Core_Commands/Gif.py | 1 - sopel_modules/SpiceBot_Core_Commands/Logs.py | 1 - .../SpiceBot_Core_Commands/Messaging.py | 3 --- .../Runtime_Controls.py | 2 -- .../SpiceBot_Core_Commands/Search.py | 3 --- .../SpiceBot_Core_Commands/Sherlock.py | 1 - .../SpiceBot_Core_Commands/Uptime.py | 1 - sopel_modules/SpiceBot_Core_Commands/Users.py | 1 - 18 files changed, 18 insertions(+), 36 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 73f6704..59d9d82 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -19,6 +19,7 @@ from .Channels import channels as botchannels from .MessageLog import messagelog as botmessagelog from .Config import config as botconfig from .Users import users as botusers +from .Events import events as botevents def prerun(t_command_type='module', t_command_subtype=None): @@ -28,6 +29,10 @@ def prerun(t_command_type='module', t_command_subtype=None): @functools.wraps(function) def internal_prerun(bot, trigger, *args, **kwargs): + # verify the bot is at a loaded state + while not botevents.check(botevents.BOT_LOADED): + pass + # Verify channel and user exist verify_channel(trigger) verify_user(trigger) diff --git a/sopel_modules/SpiceBot/setup.py b/sopel_modules/SpiceBot/setup.py index 36a4c39..71c61ad 100644 --- a/sopel_modules/SpiceBot/setup.py +++ b/sopel_modules/SpiceBot/setup.py @@ -9,7 +9,7 @@ import os from .Config import config as botconfig from .Logs import logs -from .Events import events +from .Events import events as botevents from .Channels import SpiceBot_Channels_MainSection from .Commands import SpiceBot_Commands_MainSection @@ -73,19 +73,19 @@ def setup_config(bot): def setup_logs(bot): logs.log('SpiceBot_Logs', "Starting Setup Procedure") - events.startup_add([events.BOT_LOGS]) + botevents.startup_add([botevents.BOT_LOGS]) bot.config.core.logs_stdio = os.path.join(bot.config.core.logdir, 'stdio.log') # bot.config.core.logs_stdio = os.path.os.path.join(bot.config.core.logdir, bot.config.core.basename + '.stdio.log') bot.config.core.logs_exceptions = os.path.join(bot.config.core.logdir, 'exceptions.log') # bot.config.core.logs_exceptions = os.path.os.path.join(bot.config.core.logdir, bot.config.core.basename + '.exceptions.log') bot.config.core.logs_raw = os.path.join(bot.config.core.logdir, 'raw.log') # bot.config.core.logs_raw = os.path.os.path.join(bot.config.core.logdir, bot.config.core.basename + '.raw.log') - events.trigger(bot, events.BOT_LOGS, "SpiceBot_Logs") + botevents.trigger(bot, botevents.BOT_LOGS, "SpiceBot_Logs") def setup_commands(bot): logs.log('SpiceBot_Commands', "Setting Up Configuration") - events.startup_add([events.BOT_COMMANDS]) + botevents.startup_add([botevents.BOT_COMMANDS]) bot.config.define_section("SpiceBot_Commands", SpiceBot_Commands_MainSection, validate=False) bot.config.core.query_list = str(bot.config.SpiceBot_Commands.query_prefix).replace("\\", '').split("|") bot.config.core.prefix_list.extend(bot.config.SpiceBot_Commands.query_prefix) @@ -98,17 +98,17 @@ def setup_google(bot): def setup_startupmonologue(bot): logs.log('SpiceBot_StartupMonologue', "Initial Setup processing") - events.startup_add([ - events.BOT_STARTUPMONOLOGUE_CONNECTED, - events.BOT_STARTUPMONOLOGUE_CHANNELS, - events.BOT_STARTUPMONOLOGUE_COMMANDS, - events.BOT_STARTUPMONOLOGUE_AI, + botevents.startup_add([ + botevents.BOT_STARTUPMONOLOGUE_CONNECTED, + botevents.BOT_STARTUPMONOLOGUE_CHANNELS, + botevents.BOT_STARTUPMONOLOGUE_COMMANDS, + botevents.BOT_STARTUPMONOLOGUE_AI, ]) def setup_channels(bot): logs.log('SpiceBot_Channels', "Setting Up Configuration") - events.startup_add([events.BOT_CHANNELS]) + botevents.startup_add([botevents.BOT_CHANNELS]) bot.config.define_section("SpiceBot_Channels", SpiceBot_Channels_MainSection, validate=False) @@ -122,7 +122,7 @@ def setup_ai(bot): logs.log('SpiceBot_AI', "Setting Up Configuration") bot.config.define_section("SpiceBot_AI", SpiceBot_AI_MainSection, validate=False) bot.config.aibrain = os.path.join(bot.config.homedir, bot.config.core.basename + '.aibrain.brn') - events.startup_add([events.BOT_AI]) + botevents.startup_add([botevents.BOT_AI]) def setup_osd(bot): diff --git a/sopel_modules/SpiceBot_Core_Commands/AI.py b/sopel_modules/SpiceBot_Core_Commands/AI.py index 3ccbe20..a04f7b8 100644 --- a/sopel_modules/SpiceBot_Core_Commands/AI.py +++ b/sopel_modules/SpiceBot_Core_Commands/AI.py @@ -9,7 +9,6 @@ import sopel_modules.SpiceBot as SpiceBot import spicemanip -@SpiceBot.events.check_ready([SpiceBot.events.BOT_LOADED]) @SpiceBot.prerun('nickname') @sopel.module.nickname_commands('ai') def ai_trigger(bot, trigger, botcom): diff --git a/sopel_modules/SpiceBot_Core_Commands/BotPrivs.py b/sopel_modules/SpiceBot_Core_Commands/BotPrivs.py index 7633451..be1b25f 100644 --- a/sopel_modules/SpiceBot_Core_Commands/BotPrivs.py +++ b/sopel_modules/SpiceBot_Core_Commands/BotPrivs.py @@ -9,14 +9,12 @@ import spicemanip import sopel_modules.SpiceBot as SpiceBot -@SpiceBot.events.check_ready([SpiceBot.events.BOT_LOADED]) @SpiceBot.prerun('nickname') @sopel.module.nickname_commands('owners', 'owner') def bot_command_owners(bot, trigger, botcom): bot_command_process(bot, trigger) -@SpiceBot.events.check_ready([SpiceBot.events.BOT_LOADED]) @SpiceBot.prerun('nickname') @sopel.module.nickname_commands('admins', 'admin') def bot_command_admins(bot, trigger, botcom): diff --git a/sopel_modules/SpiceBot_Core_Commands/Channels.py b/sopel_modules/SpiceBot_Core_Commands/Channels.py index 585155b..e7c0814 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Channels.py +++ b/sopel_modules/SpiceBot_Core_Commands/Channels.py @@ -10,7 +10,6 @@ import spicemanip import sopel_modules.SpiceBot as SpiceBot -@SpiceBot.events.check_ready([SpiceBot.events.BOT_LOADED]) @SpiceBot.prerun('nickname') @sopel.module.nickname_commands('channels', 'channel') def nickname_comand_channels(bot, trigger, botcom): diff --git a/sopel_modules/SpiceBot_Core_Commands/Commands.py b/sopel_modules/SpiceBot_Core_Commands/Commands.py index ce7c5f9..195706c 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Commands.py +++ b/sopel_modules/SpiceBot_Core_Commands/Commands.py @@ -14,7 +14,6 @@ import sopel_modules.SpiceBot as SpiceBot # TODO commands sent in privmsg don't need bot.nick -@SpiceBot.events.check_ready([SpiceBot.events.BOT_COMMANDS]) @SpiceBot.prerun('nickname') @sopel.module.nickname_commands('commands', 'command') def nickname_comand_commands(bot, trigger, botcom): diff --git a/sopel_modules/SpiceBot_Core_Commands/CommandsQuery.py b/sopel_modules/SpiceBot_Core_Commands/CommandsQuery.py index 150d5e6..3091f31 100644 --- a/sopel_modules/SpiceBot_Core_Commands/CommandsQuery.py +++ b/sopel_modules/SpiceBot_Core_Commands/CommandsQuery.py @@ -12,15 +12,12 @@ import spicemanip import sopel_modules.SpiceBot as SpiceBot -@SpiceBot.events.check_ready([SpiceBot.events.BOT_LOADED]) @SpiceBot.prerun('nickname') @sopel.module.nickname_commands('query') def query_trigger(bot, trigger, botcom): bot.osd("I have been programmed to help find new commands by using `?`.") -@SpiceBot.events.check_ready([SpiceBot.events.BOT_LOADED]) -@SpiceBot.events.check_ready([SpiceBot.events.BOT_COMMANDS]) @SpiceBot.prerun_query('nickname', 'nickname') @sopel.module.nickname_commands('(.*)') def query_detection_nick(bot, trigger, botcom): @@ -86,7 +83,6 @@ def query_detection_nick(bot, trigger, botcom): bot.osd("The following " + bot.nick + " commands start with " + str(trigger.sb['com']) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick, 'notice') -@SpiceBot.events.check_ready([SpiceBot.events.BOT_COMMANDS]) @SpiceBot.prerun_query('module', 'module') @sopel.module.rule('^\?(.*)') def query_detection(bot, trigger, botcom): diff --git a/sopel_modules/SpiceBot_Core_Commands/Database.py b/sopel_modules/SpiceBot_Core_Commands/Database.py index 7b3f019..8a811e8 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Database.py +++ b/sopel_modules/SpiceBot_Core_Commands/Database.py @@ -10,7 +10,7 @@ import sopel.module import sopel_modules.SpiceBot as SpiceBot -@SpiceBot.events.check_ready([SpiceBot.events.BOT_LOADED]) +@SpiceBot.prerun('nickname') @sopel.module.nickname_commands('database') def bot_command_database(bot, trigger): bot.osd("Database is " + SpiceBot.config.db_type) diff --git a/sopel_modules/SpiceBot_Core_Commands/DictComs.py b/sopel_modules/SpiceBot_Core_Commands/DictComs.py index 98e3932..61a06b0 100644 --- a/sopel_modules/SpiceBot_Core_Commands/DictComs.py +++ b/sopel_modules/SpiceBot_Core_Commands/DictComs.py @@ -15,7 +15,6 @@ from word2number import w2n from random import randint -@SpiceBot.events.check_ready([SpiceBot.events.BOT_LOADED]) @SpiceBot.prerun('module', 'dictcom') @sopel.module.commands('(.*)') def command_dictcom(bot, trigger, botcom): diff --git a/sopel_modules/SpiceBot_Core_Commands/Docs.py b/sopel_modules/SpiceBot_Core_Commands/Docs.py index f1d74b4..9e9090f 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Docs.py +++ b/sopel_modules/SpiceBot_Core_Commands/Docs.py @@ -7,7 +7,7 @@ import sopel.module import sopel_modules.SpiceBot as SpiceBot -@SpiceBot.events.check_ready([SpiceBot.events.BOT_LOADED]) +@SpiceBot.prerun('nickname') @sopel.module.nickname_commands('help', 'docs', 'wiki') def bot_command_docs(bot, trigger): sb_git_url = str( diff --git a/sopel_modules/SpiceBot_Core_Commands/Gif.py b/sopel_modules/SpiceBot_Core_Commands/Gif.py index 9abecb2..c2406c5 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Gif.py +++ b/sopel_modules/SpiceBot_Core_Commands/Gif.py @@ -11,7 +11,6 @@ import spicemanip # TODO custom gif shortcut commands -@SpiceBot.events.check_ready([SpiceBot.events.BOT_LOADED]) @SpiceBot.prerun('module') @sopel.module.commands('gif') def gif_trigger(bot, trigger, botcom): diff --git a/sopel_modules/SpiceBot_Core_Commands/Logs.py b/sopel_modules/SpiceBot_Core_Commands/Logs.py index 8a36396..2046ffb 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Logs.py +++ b/sopel_modules/SpiceBot_Core_Commands/Logs.py @@ -12,7 +12,6 @@ import spicemanip import sopel_modules.SpiceBot as SpiceBot -@SpiceBot.events.check_ready([SpiceBot.events.BOT_LOGS]) @SpiceBot.prerun('nickname') @sopel.module.nickname_commands('logs', 'debug') def bot_command_logs(bot, trigger, botcom): diff --git a/sopel_modules/SpiceBot_Core_Commands/Messaging.py b/sopel_modules/SpiceBot_Core_Commands/Messaging.py index f9b962f..ce1b295 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Messaging.py +++ b/sopel_modules/SpiceBot_Core_Commands/Messaging.py @@ -9,21 +9,18 @@ import spicemanip import sopel_modules.SpiceBot as SpiceBot -@SpiceBot.events.check_ready([SpiceBot.events.BOT_LOADED]) @SpiceBot.prerun('nickname') @sopel.module.nickname_commands('action') def bot_command_action(bot, trigger, botcom): bot_command_process(bot, trigger) -@SpiceBot.events.check_ready([SpiceBot.events.BOT_LOADED]) @SpiceBot.prerun('nickname') @sopel.module.nickname_commands('notice') def bot_command_notice(bot, trigger, botcom): bot_command_process(bot, trigger) -@SpiceBot.events.check_ready([SpiceBot.events.BOT_LOADED]) @SpiceBot.prerun('nickname') @sopel.module.nickname_commands('privmsg', 'say', 'msg') def bot_command_privmsg(bot, trigger, botcom): diff --git a/sopel_modules/SpiceBot_Core_Commands/Runtime_Controls.py b/sopel_modules/SpiceBot_Core_Commands/Runtime_Controls.py index f7883e4..84b96fe 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Runtime_Controls.py +++ b/sopel_modules/SpiceBot_Core_Commands/Runtime_Controls.py @@ -9,7 +9,6 @@ import spicemanip import sopel_modules.SpiceBot as SpiceBot -@SpiceBot.events.check_ready([SpiceBot.events.BOT_LOADED]) @SpiceBot.prerun('nickname') @sopel.module.nickname_commands('update') def nickname_comand_update(bot, trigger, botcom): @@ -42,7 +41,6 @@ def nickname_comand_update(bot, trigger, botcom): SpiceBot.spicebot_reload(bot, 'SpiceBot_Update', quitmessage) -@SpiceBot.events.check_ready([SpiceBot.events.BOT_LOADED]) @SpiceBot.prerun('nickname') @sopel.module.nickname_commands('restart') def nickname_comand_restart(bot, trigger, botcom): diff --git a/sopel_modules/SpiceBot_Core_Commands/Search.py b/sopel_modules/SpiceBot_Core_Commands/Search.py index efed214..d0375f6 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Search.py +++ b/sopel_modules/SpiceBot_Core_Commands/Search.py @@ -10,7 +10,6 @@ import spicemanip import sopel_modules.SpiceBot as SpiceBot -@SpiceBot.events.check_ready([SpiceBot.events.BOT_LOADED]) @SpiceBot.prerun('module') @sopel.module.commands('search', 'find', 'google', 'lookup') def search_main(bot, trigger, botcom): @@ -27,7 +26,6 @@ def search_main(bot, trigger, botcom): bot.osd(["[Information search for '" + str(searchterm) + "']", str(searchreturn)]) -@SpiceBot.events.check_ready([SpiceBot.events.BOT_LOADED]) @SpiceBot.prerun('module') @sopel.module.commands("where", "whereis") def search_where(bot, trigger, botcom): @@ -44,7 +42,6 @@ def search_where(bot, trigger, botcom): bot.osd(["[Location search for " + str(searchterm) + "]", str(searchreturn)]) -@SpiceBot.events.check_ready([SpiceBot.events.BOT_LOADED]) @SpiceBot.prerun('module') @sopel.module.commands("what", "whatis") def search_what(bot, trigger, botcom): diff --git a/sopel_modules/SpiceBot_Core_Commands/Sherlock.py b/sopel_modules/SpiceBot_Core_Commands/Sherlock.py index 9ce4305..49b22de 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Sherlock.py +++ b/sopel_modules/SpiceBot_Core_Commands/Sherlock.py @@ -9,7 +9,6 @@ import spicemanip import sopel_modules.SpiceBot as SpiceBot -@SpiceBot.events.check_ready([SpiceBot.events.BOT_LOADED]) @SpiceBot.prerun('module') @sopel.module.commands('sherlock', 'username') def bot_command_sherlock(bot, trigger, botcom): diff --git a/sopel_modules/SpiceBot_Core_Commands/Uptime.py b/sopel_modules/SpiceBot_Core_Commands/Uptime.py index 968866f..a644e37 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Uptime.py +++ b/sopel_modules/SpiceBot_Core_Commands/Uptime.py @@ -9,7 +9,6 @@ import time import sopel_modules.SpiceBot as SpiceBot -@SpiceBot.events.check_ready([SpiceBot.events.BOT_LOADED]) @SpiceBot.prerun('nickname') @sopel.module.nickname_commands('uptime') def bot_command_uptime(bot, trigger, botcom): diff --git a/sopel_modules/SpiceBot_Core_Commands/Users.py b/sopel_modules/SpiceBot_Core_Commands/Users.py index 73ad410..bb36e6c 100644 --- a/sopel_modules/SpiceBot_Core_Commands/Users.py +++ b/sopel_modules/SpiceBot_Core_Commands/Users.py @@ -8,7 +8,6 @@ import sopel import sopel_modules.SpiceBot as SpiceBot -@SpiceBot.events.check_ready([SpiceBot.events.BOT_LOADED]) @SpiceBot.prerun('nickname') @sopel.module.nickname_commands('users', 'user') def nickname_comand_users(bot, trigger, botcom):