]> gitweb.pimeys.fr Git - bots/parrot.git/blobdiff - parrot.py
!from : quote aléatoire en faisant une recherche sur l'auteur
[bots/parrot.git] / parrot.py
index 6229e8d4a5c4189d82a0a6945fe5d8c3a52e4e50..26a204a46ecd702ecad93c5a667b5902cc5b699c 100755 (executable)
--- a/parrot.py
+++ b/parrot.py
@@ -446,18 +446,34 @@ class Parrot(ircbot.SingleServerIRCBot):
                         serv.privmsg(canal, (u"Pas de quote de %s en mémoire." % author).encode("utf-8"))
                         return
                     serv.privmsg(canal, str(q))
-            elif message.startswith(u"!author"):
+            elif message.startswith(u"!author") or message.startswith(u"!from"):
                 words = message.split()
                 cmd = words[0].lstrip("!")
-                regexp = cmd in ["author-r", "authorreg", "author-reg", "author-regex"]
+                regexp = any([cmd.endswith(suffix) for suffix in config.regex_suffixes])
                 search = u" ".join(words[1:])
                 authors = self.quotedb.search_authors(search, regexp)
-                if len(authors) > config.search_max_authors:
-                    authors = authors[:config.search_max_authors+1] + [unicode(len(authors) - config.search_max_authors)]
-                if authors:
-                    serv.privmsg(canal, "%s: %s" % (auteur, (u" ".join(authors)).encode("utf-8")))
+                if not authors:
+                    serv.privmsg(canal, "%s: Pas d'auteur correspondant à la recherche." % (auteur,))
+                    return
+                if cmd.startswith("author"):
+                    if len(authors) > config.search_max_authors:
+                        authors = authors[:config.search_max_authors+1] + ["+%s" % (len(authors) - config.search_max_authors)]
+                    serv.privmsg(canal, "%s: %s" % (auteur, (u", ".join(authors)).encode("utf-8")))
+                elif cmd.startswith("from"):
+                    quotes = sum([self.quotedb.quotesfrom(a) for a in authors], [])
+                    q = random.choice(quotes)
+                    serv.privmsg(canal, str(q))
+            elif message.startswith(u"!search"):
+                words = message.split()
+                cmd = words[0].lstrip("!")
+                regexp = cmd in ["search" + suffix for suffix in config.regex_suffixes]
+                search = u" ".join(words[1:])
+                quotes = self.quotedb.search(inquote=search, regexp=regexp)
+                if quotes:
+                    q = random.choice(quotes)
+                    serv.privmsg(canal, str(q))
                 else:
-                    serv.privmsg(canal, "%s: Pas d'auteur correspondant à la recherche.")
+                    serv.privmsg(canal, "%s: Pas de quotes correspondant à la recherche." % (auteur,))
 
     def on_action(self, serv, ev):
         """À la réception d'une action."""