From: Vincent Le Gallic Date: Tue, 8 Apr 2014 00:16:16 +0000 (+0200) Subject: On peut trigger des dump et des restore via IRC X-Git-Url: http://gitweb.pimeys.fr/?a=commitdiff_plain;h=b9063a8c634b789e417f2fde616294ac3849377c;p=bots%2Fparrot.git On peut trigger des dump et des restore via IRC --- diff --git a/parrot.py b/parrot.py index a844a53..17a24a0 100755 --- a/parrot.py +++ b/parrot.py @@ -162,6 +162,23 @@ class Parrot(ircbot.SingleServerIRCBot): log(self.serveur, place, auteur, something + "%r" % params + ("[successful]" if success else "[failed]")) + def acknowledge(self, asked_by, asked_where, message): + """Répond quelque chose au demandeur d'une action. + ``asked_where=None`` signifie en privé.""" + if asked_where is None: + self.serv.privmsg(asked_by, message) + else: + self.serv.privmsg(asked_where, "%s: %s" % (asked_by, message)) + + def dump(self, asked_by, asked_where=None): + """Dumpe les quotes. ``asked_where=None`` signifie en privé.""" + quotes.dump(self.quotedb) + self.acknowledge(asked_by, asked_where, "Quotes dumpées") + + def restore(self, asked_by, asked_where=None): + """Restaure les quotes à partir du dump. ``asked_where=None`` signifie en privé.""" + self.quotedb = quotes.restore() + self.acknowledge(asked_by, asked_where, "Quotes restaurées à partir du dump (pas de backup effectué).") ### Surcharge des events du Bot def on_welcome(self, serv, ev): @@ -345,6 +362,10 @@ class Parrot(ircbot.SingleServerIRCBot): serv.privmsg(auteur, " ".join(self.overops)) else: notunderstood = True + elif cmd == u"dump" and auteur in self.ops: + self.dump(asked_by=auteur) + elif cmd == u"restore" and auteur in self.overops: + self.restore(asked_by=auteur) else: notunderstood = True if notunderstood: @@ -396,6 +417,10 @@ class Parrot(ircbot.SingleServerIRCBot): elif cmd in [u"ping"] and not canal in self.quiet_channels: serv.privmsg(canal, "%s: pong" % (auteur)) + elif cmd in [u"dump"]: + self.dump(asked_by=auteur, asked_where=canal) + elif cmd in [u"restore"] and auteur in self.overops: + self.restore(asked_by=auteur, asked_where=canal) else: # Vu que ce bot est prévu pour parser des quotes il va falloir bosser ici match = quote_pattern.match(message)