Add debug mode reloader
This commit is contained in:
parent
498eb52fc3
commit
9364aa55ac
61
bot.py
61
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()
|
||||
|
||||
|
|
Loading…
Reference in New Issue