]> gitweb.pimeys.fr Git - bots/hung.git/commitdiff
Le matching de whole word marche ignore correctement les accents
authorVincent Le Gallic <legallic@crans.org>
Sun, 27 May 2012 15:18:46 +0000 (17:18 +0200)
committerVincent Le Gallic <legallic@crans.org>
Sun, 27 May 2012 15:18:46 +0000 (17:18 +0200)
hung.py

diff --git a/hung.py b/hung.py
index 6746f64f2d752a96d651c1c7a21814d0f2483f43..30278ea1043c28d517ddc71ac34768fd208aecce 100755 (executable)
--- a/hung.py
+++ b/hung.py
@@ -103,6 +103,12 @@ def is_something(chain,matches,avant=u".*(?:^| )",apres=u"(?:$|\.| |,|;).*",case
 def is_tag(chain):
     return is_something(chain,config_tag_triggers)
 
+def is_mot(mot,liste):
+    real_word = "".join([lettre[0] for lettre in liste])
+    real_word = real_word.decode("utf8").lower()
+    mot=remplace_accents(mot.decode("utf8"))
+    return mot==real_word
+
 class Hung(ircbot.SingleServerIRCBot):
     def __init__(self,serveur,debug=False):
         temporary_pseudo=config_irc_pseudo+str(random.randrange(10000,100000))
@@ -399,21 +405,16 @@ class Hung(ircbot.SingleServerIRCBot):
                         serv.privmsg(canal,"%s: %s"%(auteur,ligne.encode("utf8")))
             # on essaye de voir si le mot fourni matche la partie en cours
             mot = cmd
-            # bon, ce teste merde et j'arrive pas à trouver pourquoi, alors j'ai craqué, je l'ai mis dans un try
-            # bouh ! beurk ! pas bien ! promis, j'irai me flageller…
-            try:
-                if remplace_accents(mot)==("".join([i[0] for i in self.play_status[canal][0]])).lower():
-                    # on a trouvé le mot
-                    # on regarde combien de lettre il manquait
-                    manquait = sum([not lettre[1] for lettre in self.play_status[canal][0]])
-                    self.add_score({auteur: manquait})
-                    if self.play_status[canal][2].has_key(auteur):
-                        self.play_status[canal][2][auteur]+=manquait
-                    else:
-                        self.play_status[canal][2][auteur]=manquait
-                    self.gagne(serv, canal, bonus=auteur, bonusvalue=manquait)
-            except:
-                pass
+            if is_mot(mot, self.play_status[canal][0]):
+                # on a trouvé le mot
+                # on regarde combien de lettre il manquait
+                manquait = sum([not lettre[1] for lettre in self.play_status[canal][0]])
+                self.add_score({auteur: manquait})
+                if self.play_status[canal][2].has_key(auteur):
+                    self.play_status[canal][2][auteur]+=manquait
+                else:
+                    self.play_status[canal][2][auteur]=manquait
+                self.gagne(serv, canal, bonus=auteur, bonusvalue=manquait)
         else:
             pass