From a140e55d58b6af4b50c1cd83a78aa387f78e1a80 Mon Sep 17 00:00:00 2001 From: Vincent Le Gallic Date: Mon, 14 Apr 2014 08:50:36 +0200 Subject: [PATCH] !author --- config.py | 3 +++ parrot.py | 9 +++++++++ quotes.py | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/config.py b/config.py index ad2d897..ab9e5de 100644 --- 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)" + +#: Nombre maximum d'auteurs qu'on peut demander à afficher +search_max_authors = 20 diff --git a/parrot.py b/parrot.py index 17d99c1..d3039a4 100755 --- 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)) + 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.""" diff --git a/quotes.py b/quotes.py index c1aca76..fa9ac0a 100644 --- a/quotes.py +++ b/quotes.py @@ -119,7 +119,7 @@ class QuoteDB(object): 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 = ".*" -- 2.39.2