From: Vincent Le Gallic Date: Tue, 18 Jun 2013 17:33:35 +0000 (+0200) Subject: Fonction de blacklist X-Git-Url: http://gitweb.pimeys.fr/?a=commitdiff_plain;h=602331d4815e721be1f8fcffa81391b3ba681a4b;p=bots%2Fhistorien.git Fonction de blacklist --- diff --git a/historien.py b/historien.py index 1e47415..33b9af6 100755 --- a/historien.py +++ b/historien.py @@ -51,6 +51,16 @@ def log(serveur,channel,auteur=None,message=None): print chain f.close() +def ignore_event(serv, ev): + """Retourne ``True`` si il faut ignorer cet évènement.""" + for (blackmask, exceptmask) in config.blacklisted_masks: + usermask = ev.source() + if exceptmask is None: + exceptit = False + else: + exceptit = bool(irclib.mask_matches(usermask, exceptmask)) + blackit = bool(irclib.mask_matches(usermask, blackmask)) + return blackit and not exceptit class GoodCentury(Exception): pass @@ -219,6 +229,8 @@ class Historien(ircbot.SingleServerIRCBot): return (False,message) def on_privmsg(self, serv, ev): + if ignore_event(serv, ev): + return message=ev.arguments()[0] auteur = irclib.nm_to_n(ev.source()) try: @@ -465,6 +477,8 @@ class Historien(ircbot.SingleServerIRCBot): serv.privmsg(auteur,"Je n'ai pas compris. Essaye HELP…") def on_pubmsg(self, serv, ev): + if ignore_event(serv, ev): + return auteur = irclib.nm_to_n(ev.source()) canal = ev.target() message = ev.arguments()[0]