]> gitweb.pimeys.fr Git - bots/parrot.git/commitdiff
!author
authorVincent Le Gallic <legallic@crans.org>
Mon, 14 Apr 2014 06:50:36 +0000 (08:50 +0200)
committerVincent Le Gallic <legallic@crans.org>
Mon, 14 Apr 2014 06:50:44 +0000 (08:50 +0200)
config.py
parrot.py
quotes.py

index ad2d89751c20e03ca3e01b6f3d6a09a4f07c884e..ab9e5defbb727d79dc68f61e0c8b810f467c67e5 100644 (file)
--- a/config.py
+++ b/config.py
@@ -133,3 +133,6 @@ quote_dump_file = u"quotes.txt"
 
 #: URL où sont disponibles les quotes
 quote_display_url = u"http://cerebro.crans.org/parrot-quotes.txt (campus-only)"
 
 #: URL où sont disponibles les quotes
 quote_display_url = u"http://cerebro.crans.org/parrot-quotes.txt (campus-only)"
+
+#: Nombre maximum d'auteurs qu'on peut demander à afficher
+search_max_authors = 20
index 17d99c199e9dc70a50ff735ed9aa5e0707cc551b..d3039a4a432711ec2c4a79683e03a184a84d1df2 100755 (executable)
--- a/parrot.py
+++ b/parrot.py
@@ -446,6 +446,15 @@ 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))
                         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"):
+                words = message.split()
+                cmd = words[0].lstrip("!")
+                regexp = cmd in ["author-r", "authorreg", "author-reg", "author-regex"]:
+                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)]
+                serv.privmsg(canal, "%s: %s" % (auteur, (u" ".join(authors)).encode("utf-8")))
 
     def on_action(self, serv, ev):
         """À la réception d'une action."""
 
     def on_action(self, serv, ev):
         """À la réception d'une action."""
index c1aca7617cbe1017cb4dc128c1b64b628e126a89..fa9ac0afdedf3c8dfc6b945150d46533b4b03f72 100644 (file)
--- a/quotes.py
+++ b/quotes.py
@@ -119,7 +119,7 @@ class QuoteDB(object):
         return l
 
     def search_authors(self, author=None, regexp=False):
         return l
 
     def search_authors(self, author=None, regexp=False):
-        """Renvoie la liste des auteur contenant ``author`` ou qui matchent la regexp."""
+        """Renvoie la liste des auteurs contenant ``author`` ou qui matchent la regexp."""
         if regexp:
             if author is None:
                 author = ".*"
         if regexp:
             if author is None:
                 author = ".*"