From: Vincent Le Gallic Date: Tue, 18 Jun 2013 17:22:32 +0000 (+0200) Subject: Fonction de blacklist X-Git-Url: http://gitweb.pimeys.fr/?a=commitdiff_plain;h=1ab43ff7fea0335875d1c08fe0f5f522eaf0c1bd;p=bots%2Fsaturnin.git Fonction de blacklist --- diff --git a/config.py b/config.py index 9f2768f..0e31d89 100644 --- a/config.py +++ b/config.py @@ -98,5 +98,4 @@ u"Are you the farmer?", times_up_delays = [60*10, 60*20] times_up_sentences = [u"I stayed alive, you're too slow !!!"] -ignored_pseudos = r'^Soldat\d+$' -ignored_pan_masks = [("*!leger@zamok.crans.org", "jben!*@*")] +blacklisted_masks = [("*!leger@zamok.crans.org", None)] diff --git a/saturnin.py b/saturnin.py index 4903ec3..75165df 100755 --- a/saturnin.py +++ b/saturnin.py @@ -56,11 +56,17 @@ def is_something(chain,matches,avant=u".*(?:^| )",apres=u"(?:$|\.| |,|;).*",case regexp_pan = re.compile(u".*(" + "|".join(config.killwords) + u").*") def is_pan(chain): return regexp_pan.match(unicode(chain,"utf8").lower()) -def ignore_pan(serv, ev): - """Retourne ``True`` si il faut ignorer ce pan.""" - for (blackmask, exceptmask) in config.ignored_pan_masks: + +def ignore_event(serv, ev): + """Retourne ``True`` si il faut ignorer cet évènement.""" + for (blackmask, exceptmask) in config.blacklisted_masks: usermask = ev.source() - return bool(irclib.mask_matches(usermask, blackmask) and not irclib.mask_matches(usermask, exceptmask)) + 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 @@ -121,6 +127,8 @@ class Saturnin(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: @@ -454,9 +462,9 @@ class Saturnin(ircbot.SingleServerIRCBot): self.serv.privmsg(to, "Scores by pseudo : "+" ; ".join(["%s %s"%(i[0],i[1]) for i in scores])) def on_pubmsg(self, serv, ev): - auteur = irclib.nm_to_n(ev.source()) - if re.match(config.ignored_pseudos, auteur): + if ignore_event(serv, ev): return + auteur = irclib.nm_to_n(ev.source()) channel = ev.target() message = ev.arguments()[0] try: @@ -499,11 +507,11 @@ class Saturnin(ircbot.SingleServerIRCBot): self.sendscores(auteur) else: if is_pan(message): - if ignore_pan(serv, ev): - return self.shot(channel, auteur) 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()