From: Vincent Le Gallic Date: Mon, 14 Apr 2014 07:12:48 +0000 (+0200) Subject: !search pour avoir une quote contenant un terme de recherche X-Git-Url: http://gitweb.pimeys.fr/?p=bots%2Fparrot.git;a=commitdiff_plain;h=ceb91bbbe344c41702edb1707a7d4b05ecca2e39 !search pour avoir une quote contenant un terme de recherche --- diff --git a/parrot.py b/parrot.py index 8214594..1f5b70d 100755 --- a/parrot.py +++ b/parrot.py @@ -458,6 +458,17 @@ class Parrot(ircbot.SingleServerIRCBot): serv.privmsg(canal, "%s: %s" % (auteur, (u", ".join(authors)).encode("utf-8"))) else: serv.privmsg(canal, "%s: Pas d'auteur correspondant à la recherche." % (auteur,)) + 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 de quotes correspondant à la recherche." % (auteur,)) def on_action(self, serv, ev): """À la réception d'une action."""