From 46cb50f7f073876410d641c252a08717a357c674 Mon Sep 17 00:00:00 2001 From: Vincent Le Gallic Date: Fri, 18 May 2012 00:46:51 +0200 Subject: [PATCH] =?utf8?q?On=20r=C3=A9pond=20=C3=A0=20une=20action=20sympa?= =?utf8?q?tique=20=20+=20de=20la=20cosm=C3=A9tique=20en=20(=3F:=20)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- basile.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/basile.py b/basile.py index e456eb3..6329d51 100755 --- a/basile.py +++ b/basile.py @@ -212,11 +212,11 @@ def is_something(chain,matches,avant=u".*(?:^| )",apres=u"(?:$|\.| |,|;).*",case return o def is_insult(chain,debug=True): - return is_something(chain,config_insultes,avant=".*(^| |')") + return is_something(chain,config_insultes,avant=".*(?:^| |')") def is_not_insult(chain): chain=unicode(chain,"utf8") insult_regexp=u"("+u"|".join(config_insultes)+u")" - middle_regexp=u"(un(|e) ((putain|enfoiré) d(e |'))*|)(| super )( (gros|petit|grand|énorme) |)" + middle_regexp=u"(une? (?:(?:putain|enfoiré) d(?:e |'))*|)(?:| super )(?: (?:gros|petit|grand|énorme) |)" reg=".*pas %s%s.*"%(middle_regexp,insult_regexp) if re.match(reg,chain): return True @@ -236,10 +236,10 @@ def is_tamere(chain): return is_something(chain,config_tamere_triggers) def is_bad_action_trigger(chain,pseudo): return is_something(chain,config_bad_action_triggers,avant=u"^", - apres="( [a-z]*ment)? %s($|\.| |,|;).*"%(pseudo)) + apres="(?: [a-z]*ment)? %s($|\.| |,|;).*"%(pseudo)) def is_good_action_trigger(chain,pseudo): return is_something(chain,config_good_action_triggers,avant=u"^", - apres="( [a-z]*ment)? %s($|\.| |,|;).*"%(pseudo)) + apres="(?: [a-z]*ment)? %s($|\.| |,|;).*"%(pseudo)) def is_pan(chain): return re.match(u"^(pan|bim|bang) .*$",unicode(chain,"utf8").lower().strip()) @@ -872,7 +872,15 @@ class Basile(ircbot.SingleServerIRCBot): serv.action(channel,l2[i-n1].encode("utf8")) else: serv.privmsg(channel,"%s: %s"%(auteur,l1[i].encode("utf8"))) - + if is_good_action_trigger(action,mypseudo) and not channel in self.quiet_channels: + l1,l2=config_good_action_answers,config_good_action_actions + n1,n2=len(l1),len(l2) + i=random.randrange(n1+n2) + if i>=n1: + serv.action(channel,l2[i-n1].encode("utf8")) + else: + serv.privmsg(channel,"%s: %s"%(auteur,l1[i].encode("utf8"))) + def on_kick(self,serv,ev): auteur = irclib.nm_to_n(ev.source()) channel = ev.target() -- 2.39.2