]> gitweb.pimeys.fr Git - bots/parrot.git/blobdiff - parrot.py
On peut demander à afficher le contexte des quotes sur le channel
[bots/parrot.git] / parrot.py
index ae7adb91b6ac2a1051d477e32c5478715d787cbe..8ce0673d5d315ae5a62b476be3b6b7cd714346e1 100755 (executable)
--- a/parrot.py
+++ b/parrot.py
@@ -439,10 +439,17 @@ class Parrot(ircbot.SingleServerIRCBot):
                     self.quotedb.save()
                 else:
                     serv.privmsg(canal, (u"%s: Je le savais déjà." % (auteur,)).encode("utf-8"))
+            # Whou, attention, hack dégueu
+            # on enlève context- au début des !commands si il y est,
+            # et on passe à True le paramètre show_context pour s'en souvenir
+            show_context = False
+            if message.startswith(u"!context-"):
+                show_context = True
+                message = u"!" + message[9:]
             if message.startswith(u"!quote"):
                 if message.strip() == u"!quote":
                     q = self.quotedb.random()
-                    serv.privmsg(canal, str(q))
+                    serv.privmsg(canal, q.display(show_context))
                 elif message.startswith("!quote "):
                     author = message[7:].strip()
                     try:
@@ -450,7 +457,7 @@ class Parrot(ircbot.SingleServerIRCBot):
                     except IndexError:
                         serv.privmsg(canal, (u"Pas de quote de %s en mémoire." % author).encode("utf-8"))
                         return
-                    serv.privmsg(canal, str(q))
+                    serv.privmsg(canal, q.display(show_context))
             elif message.startswith(u"!author") or message.startswith(u"!from"):
                 words = message.split()
                 cmd = words[0].lstrip("!")
@@ -467,7 +474,7 @@ class Parrot(ircbot.SingleServerIRCBot):
                 elif cmd.startswith("from"):
                     quotes = sum([self.quotedb.quotesfrom(a) for a in authors], [])
                     q = random.choice(quotes)
-                    serv.privmsg(canal, str(q))
+                    serv.privmsg(canal, q.display(show_context))
             elif message.startswith(u"!search"):
                 words = message.split()
                 cmd = words[0].lstrip("!")
@@ -476,7 +483,7 @@ class Parrot(ircbot.SingleServerIRCBot):
                 quotes = self.quotedb.search(inquote=search, regexp=regexp)
                 if quotes:
                     q = random.choice(quotes)
-                    serv.privmsg(canal, str(q))
+                    serv.privmsg(canal, q.display(show_context))
                 else:
                     serv.privmsg(canal, "%s: Pas de quotes correspondant à la recherche." % (auteur,))