]> gitweb.pimeys.fr Git - bots/historien.git/commitdiff
On peut gagner seulement avec l'année, mais y'a des bonus
authorVincent Le Gallic <legallic@crans.org>
Fri, 25 May 2012 09:03:37 +0000 (11:03 +0200)
committerVincent Le Gallic <legallic@crans.org>
Fri, 25 May 2012 09:03:37 +0000 (11:03 +0200)
historien.py

index df9b99c81cf546ddcdef6af05ab955d44405b5f5..c4eed0b6ef632b4fce96d62cc2a0ba6c1f174e18 100755 (executable)
@@ -76,8 +76,11 @@ def log(serveur,channel,auteur=None,message=None):
     f.close()
 
 
+config_score_annee=1
+config_score_bonus_mois=3
+config_score_bonus_jour=4
+
 def reussi(message,answer,auteur):
-    print message, "#?#", answer
     if auteur in config_level3:
         return answer in message
     if auteur in config_level2:
@@ -88,12 +91,17 @@ def reussi(message,answer,auteur):
             print tuple(date)
         except ThisIsNotADate:
             return False
-        as_string="%02d/%02d/%04d"%(date[2],date[1],date[0])
-        print as_string
-        if as_string==answer:
-            return True
-        else:
-            return False
+        realdate=map(lambda x:int(x), answer.split('/'))
+        realdate.reverse()
+        print date,"#?#",realdate
+        score=0
+        if date[0]==realdate[0]:
+            score=config_score_annee
+            if date[1]==realdate[1]:
+                score+=config_score_mois
+                if date[2]==realdate[2]:
+                    score+=config_score_jour
+        return score
 
 def is_something(chain,matches,avant=u".*(?:^| )",apres=u"(?:$|\.| |,|;).*",case_sensitive=False,debug=False):
     if case_sensitive:
@@ -549,10 +557,12 @@ class Deconnaisseur(ircbot.SingleServerIRCBot):
         if tryother:
             if self.play_status.get(canal,[-1])[0] in [1,2]:
                 answer=self.play_status[canal][1]
-                if reussi(message.decode("utf8"),answer,auteur):
-                    serv.privmsg(canal,(u"%s: bravo ! (C'était le %s)"%(auteur,answer)).encode("utf8"))
+                score_obtenu=reussi(message.decode("utf8"),answer,auteur)
+                if score_obtenu:
+                    bonusmsg=" [+bonus_moi"*(score_obtenu>config_score_annee)+"+bonus_anne"*(score_obtenu>config_score_annee+config_score_mois)+"]"
+                    serv.privmsg(canal,(u"%s: bravo ! (C'était le %s)%s"%(auteur,answer,bonusmsg)).encode("utf8"))
                     log(self.serveur,canal,auteur+"$win",message)
-                    self.add_score(auteur,1)
+                    self.add_score(auteur,score_obtenu)
                     token=time.time()
                     self.play_status[canal]=[0,token]
                     serv.execute_delayed(random.randrange(Ttrig*5,Ttrig*10),self.start_enigme,(serv,canal,token))