Fonction de blacklist
authorVincent Le Gallic <legallic@crans.org>
Tue, 18 Jun 2013 17:33:35 +0000 (19:33 +0200)
committerVincent Le Gallic <legallic@crans.org>
Tue, 18 Jun 2013 17:33:35 +0000 (19:33 +0200)
ibot.py

diff --git a/ibot.py b/ibot.py
index c18a3da..2506491 100755 (executable)
--- a/ibot.py
+++ b/ibot.py
@@ -46,6 +46,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
+
 def is_something(chain,matches,avant=u".*(?:^| )",apres=u"(?:$|\.| |,|;).*",case_sensitive=False,debug=False):
     if case_sensitive:
         chain=unicode(chain,"utf8")
@@ -161,6 +172,8 @@ class Ibot(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:
@@ -395,6 +408,8 @@ class Ibot(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]
@@ -440,6 +455,8 @@ class Ibot(ircbot.SingleServerIRCBot):
                 serv.kick(canal, auteur, u"iKick".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()