X-Git-Url: http://gitweb.pimeys.fr/?a=blobdiff_plain;f=parrot.py;h=1f5b70def7f3b3aa91f987595253692ce024fdd7;hb=b58870bba04ffabc1a7469e6fd80e4bc60ebc41c;hp=a507663bc0d9e6dcdbc76fd402e49e3a3910bd0d;hpb=13c49d5b0a7f767598a4fab5074d729adaa11b39;p=bots%2Fparrot.git diff --git a/parrot.py b/parrot.py index a507663..1f5b70d 100755 --- a/parrot.py +++ b/parrot.py @@ -426,7 +426,7 @@ class Parrot(ircbot.SingleServerIRCBot): self.serv.privmsg(canal, "%s: %s" % (auteur, config.quote_display_url.encode("utf-8"))) else: # Vu que ce bot est prévu pour parser des quotes il va falloir bosser ici - match = quote_pattern.match(message) + match = self.quote_pattern.match(message) if match: d = match.groupdict() if self.quotedb.store(d["author"], d["content"]): @@ -446,6 +446,29 @@ 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" + 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] + ["+%s" % (len(authors) - config.search_max_authors)] + if authors: + 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."""