From a628f495f23e2d16da4a8e98c8c39ec2aa503d06 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 4 May 2019 19:22:37 -0400 Subject: [PATCH] cleaner way to restart the bot --- sopel_modules/SpiceBot_BotPrivs/BotPrivs.py | 4 ++++ sopel_modules/SpiceBot_Botevents/BotEvents.py | 5 +++++ sopel_modules/SpiceBot_Channels/Channels.py | 5 +++++ .../SpiceBot_CommandsQuery/CommandsQuery.py | 5 +++++ .../SpiceBot_Database_Addons/Databaseaddons.py | 4 ++++ .../SpiceBot_Database_Cache/DatabaseCache.py | 5 +++++ .../SpiceBot_Database_Tools/DatabaseTools.py | 12 ++++++++++++ sopel_modules/SpiceBot_Docs/Docs.py | 4 ++++ sopel_modules/SpiceBot_FriendlyBot/FriendlyBot.py | 4 ++++ sopel_modules/SpiceBot_Gender/Gender.py | 4 ++++ sopel_modules/SpiceBot_GifSearch/gifsearch.py | 5 +++++ .../SpiceBot_InsultHandler/InsultHandler.py | 4 ++++ sopel_modules/SpiceBot_Logs/Logs.py | 7 +++++++ sopel_modules/SpiceBot_Messaging/Messaging.py | 4 ++++ sopel_modules/SpiceBot_Restart/Restart.py | 7 ++++++- sopel_modules/SpiceBot_SBTools/__init__.py | 4 ++++ .../SpiceBot_StartupMonologue/StartupMonologue.py | 4 ++++ sopel_modules/SpiceBot_Update/Update.py | 7 ++++++- sopel_modules/SpiceBot_Uptime/Uptime.py | 5 +++++ sopel_modules/SpiceBot_osd/__init__.py | 4 ++++ 20 files changed, 101 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot_BotPrivs/BotPrivs.py b/sopel_modules/SpiceBot_BotPrivs/BotPrivs.py index f6ae1b5..1954150 100644 --- a/sopel_modules/SpiceBot_BotPrivs/BotPrivs.py +++ b/sopel_modules/SpiceBot_BotPrivs/BotPrivs.py @@ -17,6 +17,10 @@ def setup(bot): pass +def shutdown(bot): + pass + + @sopel.module.nickname_commands('owners', 'owner') def bot_command_owners(bot, trigger): bot_command_process(bot, trigger) diff --git a/sopel_modules/SpiceBot_Botevents/BotEvents.py b/sopel_modules/SpiceBot_Botevents/BotEvents.py index 57db01d..b6f88dd 100644 --- a/sopel_modules/SpiceBot_Botevents/BotEvents.py +++ b/sopel_modules/SpiceBot_Botevents/BotEvents.py @@ -20,6 +20,11 @@ def setup(bot): threading.Thread(target=setup_thread, args=(bot,)).start() +def shutdown(bot): + if "Sopel_BotEvents" in bot.memory: + del bot.memory["Sopel_BotEvents"] + + def setup_thread(bot): if "Sopel_BotEvents" not in bot.memory: bot.memory["Sopel_BotEvents"] = {"loaded": [], "startup": []} diff --git a/sopel_modules/SpiceBot_Channels/Channels.py b/sopel_modules/SpiceBot_Channels/Channels.py index 54dca05..908a5f1 100644 --- a/sopel_modules/SpiceBot_Channels/Channels.py +++ b/sopel_modules/SpiceBot_Channels/Channels.py @@ -51,6 +51,11 @@ def setup(bot): bot.memory['SpiceBot_Channels']['ProcessLock'] = False +def shutdown(bot): + if "SpiceBot_Channels" in bot.memory: + del bot.memory["SpiceBot_Channels"] + + @sopel.module.event('001') @sopel.module.rule('.*') def trigger_channel_list_initial(bot, trigger): diff --git a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py index 0d3f6fc..0ed520c 100644 --- a/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py +++ b/sopel_modules/SpiceBot_CommandsQuery/CommandsQuery.py @@ -26,6 +26,11 @@ def setup(bot): threading.Thread(target=setup_thread, args=(bot,)).start() +def shutdown(bot): + if "SpiceBot_CommandsQuery" in bot.memory: + del bot.memory["SpiceBot_CommandsQuery"] + + def setup_thread(bot): if 'SpiceBot_CommandsQuery' not in bot.memory: diff --git a/sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py b/sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py index 7c07129..ad33a4e 100644 --- a/sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py +++ b/sopel_modules/SpiceBot_Database_Addons/Databaseaddons.py @@ -21,6 +21,10 @@ def setup(bot): SopelDB._create_table = SopelDBCache._create_table +def shutdown(bot): + pass + + class SopelDBCache: """Dynamic Table Creation""" diff --git a/sopel_modules/SpiceBot_Database_Cache/DatabaseCache.py b/sopel_modules/SpiceBot_Database_Cache/DatabaseCache.py index 754d0ed..1811877 100644 --- a/sopel_modules/SpiceBot_Database_Cache/DatabaseCache.py +++ b/sopel_modules/SpiceBot_Database_Cache/DatabaseCache.py @@ -11,3 +11,8 @@ def setup(bot): bot_logging(bot, 'SpiceBot_DatabaseCache', "Setting up Database Cache") if 'SpiceBot_DatabaseCache' not in bot.memory: bot.memory['SpiceBot_DatabaseCache'] = dict() + + +def shutdown(bot): + if "SpiceBot_DatabaseCache" in bot.memory: + del bot.memory["SpiceBot_DatabaseCache"] diff --git a/sopel_modules/SpiceBot_Database_Tools/DatabaseTools.py b/sopel_modules/SpiceBot_Database_Tools/DatabaseTools.py index 816c56f..53242da 100644 --- a/sopel_modules/SpiceBot_Database_Tools/DatabaseTools.py +++ b/sopel_modules/SpiceBot_Database_Tools/DatabaseTools.py @@ -6,6 +6,18 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi import sopel.module +def configure(config): + pass + + +def setup(bot): + pass + + +def shutdown(bot): + pass + + """Dyanmic Table Creation""" diff --git a/sopel_modules/SpiceBot_Docs/Docs.py b/sopel_modules/SpiceBot_Docs/Docs.py index 16b7116..bdda514 100644 --- a/sopel_modules/SpiceBot_Docs/Docs.py +++ b/sopel_modules/SpiceBot_Docs/Docs.py @@ -17,6 +17,10 @@ def setup(bot): pass +def shutdown(bot): + pass + + @sopel.module.nickname_commands('help', 'docs', 'wiki') def bot_command_owners(bot, trigger): bot.osd(["IRC Modules Repository", str(github_dict["url_main"] + github_dict["repo_owner"] + "/" + github_dict["repo_name"] + github_dict["url_path_wiki"])]) diff --git a/sopel_modules/SpiceBot_FriendlyBot/FriendlyBot.py b/sopel_modules/SpiceBot_FriendlyBot/FriendlyBot.py index 12b9431..c0c8086 100644 --- a/sopel_modules/SpiceBot_FriendlyBot/FriendlyBot.py +++ b/sopel_modules/SpiceBot_FriendlyBot/FriendlyBot.py @@ -15,6 +15,10 @@ def setup(bot): pass +def shutdown(bot): + pass + + @sopel.module.rule(r'(?i)(hi|hello|hey),? $nickname[ \t]*$') def bot_command_hello(bot, trigger): hello = spicemanip.main(['Hi', 'Hey', 'Hello'], "random") diff --git a/sopel_modules/SpiceBot_Gender/Gender.py b/sopel_modules/SpiceBot_Gender/Gender.py index 8069f0d..f74655d 100644 --- a/sopel_modules/SpiceBot_Gender/Gender.py +++ b/sopel_modules/SpiceBot_Gender/Gender.py @@ -13,6 +13,10 @@ def setup(bot): pass +def shutdown(bot): + pass + + @sopel.module.nickname_commands('gender') def bot_command_gender(bot, trigger): bot.osd("If societal genders are binary, my gender is female") diff --git a/sopel_modules/SpiceBot_GifSearch/gifsearch.py b/sopel_modules/SpiceBot_GifSearch/gifsearch.py index 28f9b69..b6cad11 100644 --- a/sopel_modules/SpiceBot_GifSearch/gifsearch.py +++ b/sopel_modules/SpiceBot_GifSearch/gifsearch.py @@ -57,6 +57,11 @@ def setup(bot): threading.Thread(target=setup_thread, args=(bot,)).start() +def shutdown(bot): + if "SpiceBot_GifSearch" in bot.memory: + del bot.memory["SpiceBot_GifSearch"] + + def setup_thread(bot): startup_bot_event(bot, "SpiceBot_GifSearch") diff --git a/sopel_modules/SpiceBot_InsultHandler/InsultHandler.py b/sopel_modules/SpiceBot_InsultHandler/InsultHandler.py index 724aae4..311ed8e 100644 --- a/sopel_modules/SpiceBot_InsultHandler/InsultHandler.py +++ b/sopel_modules/SpiceBot_InsultHandler/InsultHandler.py @@ -13,6 +13,10 @@ def setup(bot): pass +def shutdown(bot): + pass + + @sopel.module.rule(r'(?i)(Fuck|Screw) (you|off),? $nickname[ \t]*$') def bot_command_srewyou(bot, trigger): bot.osd("Watch your mouth, " + trigger.nick + ", or I'll tell your mother!") diff --git a/sopel_modules/SpiceBot_Logs/Logs.py b/sopel_modules/SpiceBot_Logs/Logs.py index b507710..ebbb12c 100644 --- a/sopel_modules/SpiceBot_Logs/Logs.py +++ b/sopel_modules/SpiceBot_Logs/Logs.py @@ -30,6 +30,13 @@ def setup(bot): bot.memory['SpiceBot_Logs_queue'] = [] +def shutdown(bot): + if "SpiceBot_Logs" in bot.memory: + del bot.memory["SpiceBot_Logs"] + if "SpiceBot_Logs_queue" in bot.memory: + del bot.memory["SpiceBot_Logs_queue"] + + @sopel.module.event('001') @sopel.module.rule('.*') def join_log_channel(bot, trigger): diff --git a/sopel_modules/SpiceBot_Messaging/Messaging.py b/sopel_modules/SpiceBot_Messaging/Messaging.py index 099d356..8b24a0b 100644 --- a/sopel_modules/SpiceBot_Messaging/Messaging.py +++ b/sopel_modules/SpiceBot_Messaging/Messaging.py @@ -17,6 +17,10 @@ def setup(bot): pass +def shutdown(bot): + pass + + @sopel.module.nickname_commands('action') def bot_command_action(bot, trigger): bot_command_process(bot, trigger) diff --git a/sopel_modules/SpiceBot_Restart/Restart.py b/sopel_modules/SpiceBot_Restart/Restart.py index 58baea5..28da9eb 100644 --- a/sopel_modules/SpiceBot_Restart/Restart.py +++ b/sopel_modules/SpiceBot_Restart/Restart.py @@ -9,6 +9,10 @@ from sopel.config.types import StaticSection, ValidatedAttribute from sopel_modules.SpiceBot_SBTools import service_manip, bot_logging +def shutdown(bot): + pass + + @sopel.module.nickname_commands('restart') def nickname_comand_chanstats(bot, trigger): @@ -18,4 +22,5 @@ def nickname_comand_chanstats(bot, trigger): bot_logging(bot, 'SpiceBot_Restart', "Received command from " + trigger.nick + " to restart") bot.osd("Received command from " + trigger.nick + " to restart. Be Back Soon!", bot.channels.keys()) - service_manip(bot, bot.nick, 'restart', 'SpiceBot_Restart') + # service_manip(bot, bot.nick, 'restart', 'SpiceBot_Restart') + bot.restart() diff --git a/sopel_modules/SpiceBot_SBTools/__init__.py b/sopel_modules/SpiceBot_SBTools/__init__.py index 2575cdd..cb442e1 100644 --- a/sopel_modules/SpiceBot_SBTools/__init__.py +++ b/sopel_modules/SpiceBot_SBTools/__init__.py @@ -251,6 +251,10 @@ def channel_list_current(bot): """Environment Functions""" +def spicebot_reload(bot): + bot.reload_plugins() + + def service_manip(bot, servicename, dowhat, log_from='service_manip'): if str(dowhat) not in ["start", "stop", "restart"]: return diff --git a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py index ef27a1a..f86d971 100644 --- a/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py +++ b/sopel_modules/SpiceBot_StartupMonologue/StartupMonologue.py @@ -18,6 +18,10 @@ def setup(bot): pass +def shutdown(bot): + pass + + @module.event('001') @module.rule('.*') @module.thread(True) diff --git a/sopel_modules/SpiceBot_Update/Update.py b/sopel_modules/SpiceBot_Update/Update.py index c137b5c..e45acec 100644 --- a/sopel_modules/SpiceBot_Update/Update.py +++ b/sopel_modules/SpiceBot_Update/Update.py @@ -29,6 +29,10 @@ def setup(bot): bot.config.define_section("SpiceBot_Update", SpiceBot_Update_MainSection, validate=False) +def shutdown(bot): + pass + + @sopel.module.nickname_commands('update') def nickname_comand_chanstats(bot, trigger): @@ -57,7 +61,8 @@ def nickname_comand_chanstats(bot, trigger): if commandused == 'deps': spicebot_update(bot, "True") - service_manip(bot, bot.nick, 'restart', 'SpiceBot_Update') + # service_manip(bot, bot.nick, 'restart', 'SpiceBot_Update') + bot.restart() def spicebot_update(bot, deps="False"): diff --git a/sopel_modules/SpiceBot_Uptime/Uptime.py b/sopel_modules/SpiceBot_Uptime/Uptime.py index 1e56e13..81ba858 100644 --- a/sopel_modules/SpiceBot_Uptime/Uptime.py +++ b/sopel_modules/SpiceBot_Uptime/Uptime.py @@ -22,6 +22,11 @@ def setup(bot): bot.memory["SpiceBot_Uptime"] = now +def shutdown(bot): + if "SpiceBot_Uptime" in bot.memory: + del bot.memory["SpiceBot_Uptime"] + + @sopel.module.nickname_commands('uptime') def bot_command_srewyou(bot, trigger): timesince = str(humanized_time(time.time() - bot.memory["SpiceBot_Uptime"])) + " ago." diff --git a/sopel_modules/SpiceBot_osd/__init__.py b/sopel_modules/SpiceBot_osd/__init__.py index 92c3810..e4c73d0 100644 --- a/sopel_modules/SpiceBot_osd/__init__.py +++ b/sopel_modules/SpiceBot_osd/__init__.py @@ -54,6 +54,10 @@ def setup(bot): bot.config.define_section("MAXTARGCONFIG", MAXTARGCONFIG, validate=False) +def shutdown(bot): + pass + + # RPL_ISUPPORT = '005' @module.event('005') @module.rule('.*')