import time
import pickle
import re
-
+from cast_as_date import *
config_password="EtTaMère,ElleEstNéeQuand?"
config_pseudo="historien"
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:
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
if self.play_status[channel][-1]+config_time_incompressible_clue<time.time():
token=self.play_status[channel][-1]
if self.play_status[channel][-1]==token:
- indice=self.play_status[channel][2]
+ date=self.play_status[channel][1]
+ indice=date[:5]
serv.privmsg(channel,"indice : %s"%(indice).encode("utf8"))
self.play_status[channel][0]=2
serv.execute_delayed(random.randrange(ttrig*1,ttrig*3),self.give_answer,(serv,channel,token))
def give_answer(self,serv,channel,token):
if self.play_status[channel][0]==2 and self.play_status[channel][-1]==token:
- answer=self.play_status[channel][4]
- serv.privmsg(channel,"C'était : %s"%(answer).encode("utf8"))
+ date=self.play_status[channel][1]
+ serv.privmsg(channel,"C'était le %s"%(date).encode("utf8"))
token=time.time()
self.play_status[channel]=[0,token]
serv.execute_delayed(random.randrange(Ttrig*5,Ttrig*10),self.start_enigme,(serv,channel,token))
def get_enigme(self):
# on récupère les dates
f=open(config_source_file)
- t=f.read()
+ l=f.readlines()
f.close()
- l=re.findall("%\n(.*)\n(.*)\n(.*)\n(.*)\n(.*)\n",t)
- dec={int(i[0]):list(i[1:]) for i in l if len(i)==5}
+ l=[i.split(" : ",2) for i in l]
+ dates={int(i[0]):i[1:] for i in l}
# on va chercher combien de fois elles ont été jouées
played_file=get_config_played_file(self.serveur)
f=open(played_file)
mini=min(played.values())
# on choisit un id dans ceux qui ont ce nombre d'occurences
id_choisi=random.choice([k for k,v in played.items() if v==mini])
- enigme,indice,answer_reg,answer=dec[id_choisi]
+ date,evenement=dates[id_choisi]
+ evenement=evenement.replace("\n","")
# on incrémente la choisie
played[id_choisi]+=1
# on enregistre le played_file
f=open(played_file,"w")
- f.write("\n".join(["%-3s : %s"%(k,v) for k,v in played.items()]))
+ f.write("\n".join(["%-4s : %s"%(k,v) for k,v in played.items()]))
f.close()
- return enigme.decode("utf8"),indice.decode("utf8"),answer_reg.decode("utf8"),answer.decode("utf8")
+ return map(lambda x:x.decode("utf8"), [date,evenement])
def pourmoi(self, serv, message):
pseudo=self.nick
elif cmd in ["states","status"]:
if auteur in self.overops:
for k in self.play_status.keys():
- serv.privmsg(auteur,(u"%s : %s"%(k,"; ".join([unicode(i) for i in self.play_status[k]]))).encode("utf8") )
+ serv.privmsg(auteur,(u"%s : %s"%(k," | ".join([unicode(i) for i in self.play_status[k]]))).encode("utf8") )
elif cmd=="say":
if auteur in self.overops and len(message)>2:
serv.privmsg(message[1]," ".join(message[2:]))
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:
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"]:
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()