From: Vincent Le Gallic Date: Thu, 17 May 2012 22:46:51 +0000 (+0200) Subject: On répond à une action sympatique X-Git-Url: http://gitweb.pimeys.fr/?a=commitdiff_plain;h=46cb50f7f073876410d641c252a08717a357c674;p=bots%2Fbasile.git On répond à une action sympatique + de la cosmétique en (?: ) --- 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()