From 62480799ac7952c8aa8a99660317b2db35b88b7a Mon Sep 17 00:00:00 2001 From: Vincent Le Gallic Date: Tue, 18 Jun 2013 19:33:35 +0200 Subject: [PATCH] Fonction de blacklist --- themis.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/themis.py b/themis.py index 2ec8361..3bf8773 100755 --- a/themis.py +++ b/themis.py @@ -41,6 +41,17 @@ 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 + reg_is_smiley = re.compile(u".*("+u"|".join(config.smileys)+u")") def is_smiley(chain): chain=unicode(chain,"utf8") @@ -184,6 +195,8 @@ class Themis(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: @@ -383,6 +396,8 @@ class Themis(ircbot.SingleServerIRCBot): serv.privmsg(auteur,"Je n'ai pas compris. Essayez 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] @@ -488,6 +503,8 @@ class Themis(ircbot.SingleServerIRCBot): serv.privmsg(canal,answer.format(auteur).encode("utf8")) def on_action(self, serv, ev): + if ignore_event(serv, ev): + return action = ev.arguments()[0] auteur = irclib.nm_to_n(ev.source()) channel = ev.target() -- 2.39.2