Add admin 'wipe' command

Add framework for admin commands (reserved to channel ops),
and introduce the wipe command (cleans up the database).
This commit is contained in:
Thierry Carrez 2017-05-29 15:43:35 +02:00
parent e7c7b36710
commit 048dfc01e2
2 changed files with 17 additions and 0 deletions

View File

@ -124,6 +124,19 @@ class PTGBot(irc.bot.SingleServerIRCBot):
return return
self.send(chan, "%s: ack" % (nick,)) self.send(chan, "%s: ack" % (nick,))
if msg.startswith('!'):
if not self.channels[chan].is_oper(nick):
self.send(chan, "%s: Need op for admin commands" % (nick,))
return
words = msg.split()
command = words[0][1:].lower()
if command == 'wipe':
self.data.wipe()
else:
self.send(chan, "%s: unknown command '%s'" % (nick, command))
return
self.send(chan, "%s: done" % (nick,))
def send(self, channel, msg): def send(self, channel, msg):
self.connection.privmsg(channel, msg) self.connection.privmsg(channel, msg)
time.sleep(ANTI_FLOOD_SLEEP) time.sleep(ANTI_FLOOD_SLEEP)

View File

@ -44,6 +44,10 @@ class PTGDataBase():
# TODO: Load from ethercalc # TODO: Load from ethercalc
pass pass
def wipe(self):
self.data = {'now': {}, 'next': {}}
self.save()
def save(self): def save(self):
# self.from_ethercalc() # self.from_ethercalc()
with open(self.filename, 'w') as fp: with open(self.filename, 'w') as fp: