From b9613bcfbcf3eaaad5a4bde70b82ee7aace57255 Mon Sep 17 00:00:00 2001 From: Vincent Le Gallic Date: Fri, 25 May 2012 06:36:49 +0200 Subject: [PATCH] =?utf8?q?Prog=20adapt=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- historien.py | 61 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 25 deletions(-) diff --git a/historien.py b/historien.py index bc8e3fe..350668b 100755 --- a/historien.py +++ b/historien.py @@ -12,7 +12,7 @@ import random import time import pickle import re - +from cast_as_date import * config_password="EtTaMère,ElleEstNéeQuand?" config_pseudo="historien" @@ -75,15 +75,25 @@ def log(serveur,channel,auteur=None,message=None): print chain f.close() -## 20-100 -def reussi(message,answer,answer_regexp,auteur): + +def reussi(message,answer,auteur): + print message, "#?#", answer if auteur in config_level3: return answer in message if auteur in config_level2: - return remplace_accents(answer) in message + return answer in message else: - if re.match(remplace_accents(answer_regexp).lower(),remplace_accents(message).lower()): + try: + date=cast_as_date(message.lower()) + print tuple(date) + except ThisIsNotADate: + return False + as_string="%02d/%02d/%d"%(date[2],date[1],date[0]) + print as_string + if as_string==answer: return True + else: + return False def is_something(chain,matches,avant=u".*(?:^| )",apres=u"(?:$|\.| |,|;).*",case_sensitive=False,debug=False): if case_sensitive: @@ -149,11 +159,11 @@ class Deconnaisseur(ircbot.SingleServerIRCBot): else: ok="refuse" if ok=="do_it": - enigme,indice,answer_reg,answer=self.get_enigme() - log(self.serveur,channel,u"$Date$".encode("utf8"),("%s; %s; %s; %s"%(enigme, indice, answer_reg, answer)).encode("utf8")) - serv.privmsg(channel,enigme.encode("utf8")) + date,evenement=self.get_enigme() + log(self.serveur,channel,u"$Date$".encode("utf8"),("%s : %s"%(date, evenement)).encode("utf8")) + serv.privmsg(channel,evenement.encode("utf8")) token=time.time() - self.play_status[channel]=[1,enigme,indice,answer_reg,answer,token] + self.play_status[channel]=[1,date,evenement,token] serv.execute_delayed(random.randrange(ttrig*3,ttrig*5),self.give_indice,(serv,channel,token)) elif ok=="refuse": raise RefuseError @@ -164,14 +174,15 @@ class Deconnaisseur(ircbot.SingleServerIRCBot): if self.play_status[channel][-1]+config_time_incompressible_clue2: serv.privmsg(message[1]," ".join(message[2:])) @@ -497,7 +509,7 @@ class Deconnaisseur(ircbot.SingleServerIRCBot): serv.privmsg(canal,"%s: coucou"%(auteur)) if cmd in ["ping"] and not canal in self.quiet_channels: serv.privmsg(canal,"%s: pong"%(auteur)) - if cmd in ["déconnaissance","deconnaissance","énigme","enigme","encore"]: + if cmd in ["date","dates","histoire","énigme","enigme","encore"]: if canal in self.play_channels: if self.play_status.get(canal,[-1])[0]==0: try: @@ -505,7 +517,7 @@ class Deconnaisseur(ircbot.SingleServerIRCBot): except RefuseError: serv.privmsg(canal,"%s: Je peux souffler une minute ?"%(auteur)) else: - serv.privmsg(canal,("%s: Rappel : %s"%(auteur,self.play_status[canal][1])).encode("utf8") ) + serv.privmsg(canal,("%s: Rappel : %s"%(auteur,self.play_status[canal][2])).encode("utf8") ) else: serv.privmsg(canal,"%s: pas ici…"%(auteur)) if cmd in ["score","!score"]: @@ -536,10 +548,9 @@ class Deconnaisseur(ircbot.SingleServerIRCBot): tryother=True if tryother: if self.play_status.get(canal,[-1])[0] in [1,2]: - answer_regexp=self.play_status[canal][3] - answer=self.play_status[canal][4] - if reussi(message.decode("utf8"),answer,answer_regexp,auteur): - serv.privmsg(canal,(u"%s: bravo ! (C'était %s)"%(auteur,answer)).encode("utf8")) + 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")) log(self.serveur,canal,auteur+"$win",message) self.add_score(auteur,1) token=time.time() -- 2.39.2