From 7d71c6f52fd5741dbb8afcf31acafb7e481ecfcd 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 --- hung.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/hung.py b/hung.py index d91e4e0..9517d27 100755 --- a/hung.py +++ b/hung.py @@ -42,6 +42,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 UnicodeBotError(Exception): pass @@ -124,6 +134,8 @@ class Hung(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: @@ -339,6 +351,8 @@ class Hung(ircbot.SingleServerIRCBot): self.affiche_mot(serv, canal, begin="Devinez") 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] @@ -447,6 +461,8 @@ class Hung(ircbot.SingleServerIRCBot): 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