]> gitweb.pimeys.fr Git - bots/basile.git/commitdiff
On répond à une action sympatique
authorVincent Le Gallic <legallic@crans.org>
Thu, 17 May 2012 22:46:51 +0000 (00:46 +0200)
committerVincent Le Gallic <legallic@crans.org>
Thu, 17 May 2012 22:46:51 +0000 (00:46 +0200)
 + de la cosmétique en (?: )

basile.py

index e456eb34ca01f6697f36b708c9aa033572097778..6329d513089952022dc79c4e7da41391b38f56f5 100755 (executable)
--- 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()