Add debug mode reloader

This commit is contained in:
Robert Miles 2018-11-21 12:22:05 -05:00
parent 498eb52fc3
commit 9364aa55ac
1 changed files with 46 additions and 15 deletions

61
bot.py
View File

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