From 08ace9289649498cdbd129ea9fa4db15057a0c28 Mon Sep 17 00:00:00 2001 From: Vincent Le Gallic Date: Fri, 25 May 2012 11:03:37 +0200 Subject: [PATCH] =?utf8?q?On=20peut=20gagner=20seulement=20avec=20l'ann?= =?utf8?q?=C3=A9e,=20mais=20y'a=20des=20bonus?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- historien.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/historien.py b/historien.py index df9b99c..c4eed0b 100755 --- a/historien.py +++ b/historien.py @@ -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)) -- 2.39.2