From 9364aa55acbe262ccf7d849ab647091995a6cc79 Mon Sep 17 00:00:00 2001 From: khuxkm Date: Wed, 21 Nov 2018 12:22:05 -0500 Subject: [PATCH] Add debug mode reloader --- bot.py | 61 +++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 15 deletions(-) diff --git a/bot.py b/bot.py index 455edcf..d8e95bf 100644 --- a/bot.py +++ b/bot.py @@ -10,6 +10,30 @@ import json DEBUG = os.path.exists(os.path.expanduser("~/minerbot2.debug")) +def reloadDebug(bot): + global DEBUG + DEBUG = os.path.exists(os.path.expanduser("~/minerbot2.debug")) + if not DEBUG: + for channel in CHANNELS: + if channel not in bot.chanlist: + bot.join(channel) + bot.chanlist.append(channel) + for channel in bot.chanlist: + if channel not in CHANNELS: + bot.part(channel,"exiting debug mode") + bot.chanlist.remove(channel) + else: + with open(os.path.expanduser("~/minerbot2.debug")) as f: + botchannels = [l.rstrip() for l in f if l.rstrip()] + for channel in bot.chanlist: + if channel not in botchannels: + bot.part(channel,"entering debug mode") + bot.chanlist.remove(channel) + for channel in botchannels: + if channel not in bot.chanlist: + bot.join(channel) + bot.chanlist.append(channel) + def log(s): with open(os.path.expanduser("~/minerbot2.log"),"a") as f: f.write(s.rstrip()+"\n") @@ -124,6 +148,9 @@ class TVBot(irc.bot.SingleServerIRCBot): elif sub=="global": for channel in self.chanlist: c.privmsg(channel,"[GLOBAL] "+" ".join(p)) + elif sub=="debug": + reloadDebug(self) + log("Reloaded debug mode") def load(self): for attr in self.data: @@ -266,23 +293,27 @@ class TVBot(irc.bot.SingleServerIRCBot): return # blocked user! self.command_handlers[parts[0]](c,e,parts) +CHANNELS = [ + '#team', + '#meta', + '#quotes', + '#journal', + '#sudoers', + '#tildeverse', + '#stevenuniverse', + '#suwp', + '#bots', + '#twtxt', + '#tildelinux' +] + + if __name__ == '__main__': - channels = [ - '#team', - '#meta', - '#quotes', - '#journal', - '#sudoers', - '#tildeverse', - '#stevenuniverse', - '#suwp', - '#bots', - '#twtxt', - '#tildelinux' - ] if DEBUG: with open(os.path.expanduser("~/minerbot2.debug")) as f: - channels = [l.rstrip() for l in f if l.rstrip()] - bot = TVBot(channels, 'minerbot2', 'localhost') + botchannels = [l.rstrip() for l in f if l.rstrip()] + else: + botchannels = CHANNELS + bot = TVBot(botchannels, 'minerbot2', 'localhost') bot.start()