cleaner way to restart the bot

This commit is contained in:
deathbybandaid 2019-05-04 19:22:37 -04:00
parent d579cfd24e
commit a628f495f2
20 changed files with 101 additions and 2 deletions

View File

@ -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)

View File

@ -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": []}

View File

@ -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):

View File

@ -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:

View File

@ -21,6 +21,10 @@ def setup(bot):
SopelDB._create_table = SopelDBCache._create_table
def shutdown(bot):
pass
class SopelDBCache:
"""Dynamic Table Creation"""

View File

@ -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"]

View File

@ -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"""

View File

@ -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"])])

View File

@ -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")

View File

@ -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")

View File

@ -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")

View File

@ -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!")

View File

@ -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):

View File

@ -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)

View File

@ -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()

View File

@ -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

View File

@ -18,6 +18,10 @@ def setup(bot):
pass
def shutdown(bot):
pass
@module.event('001')
@module.rule('.*')
@module.thread(True)

View File

@ -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"):

View File

@ -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."

View File

@ -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('.*')