else:
ok="refuse"
if ok=="do_it":
- enigme,indice,answer=self.get_enigme()
+ enigme,answer=self.get_enigme()
log(self.serveur,channel,u"$Énigme$".encode("utf8"),("%s | %s"%(enigme, answer)).encode("utf8"))
serv.privmsg(channel,enigme.encode("utf8"))
token=time.time()
- self.play_status[channel]=[1,enigme,indice,answer_reg,answer,token]
- serv.execute_delayed(random.randrange(ttrig*3,ttrig*5),self.give_indice,(serv,channel,token))
+ self.play_status[channel]=[1,enigme,answer,token]
+ # ce bot n'a pas d'indices
+ serv.execute_delayed(random.randrange(ttrig*7,ttrig*10),self.give_answer,(serv,channel,token))
elif ok=="refuse":
raise RefuseError
- def give_indice(self,serv,channel,token):
- if self.play_status[channel][0]==1:
- if token==None:
- # c'est donc que l'indice a été demandé
- 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]
- 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]
+ if self.play_status[channel][0]==1 and self.play_status[channel][-1]==token:
+ answer=self.play_status[channel][2]
serv.privmsg(channel,"C'était : %s"%(answer).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 déconnaissances
+ # on récupère les capitales
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(" | ") for i in l]
+ dec={int(i[0]):list(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]
+ capitale,pays=dec[id_choisi]
+ # on peut jouer capitale -> pays ou pays -> capitale
+ enigme,answer=random.choice([[capitale,pays],[pays,capitale]])
# 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.close()
- return enigme.decode("utf8"),indice.decode("utf8"),answer_reg.decode("utf8"),answer.decode("utf8")
+ return map(lambda x:x.decode("utf8"), [enigme,answer])
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 ["ville","capitale","pays","énigme","enigme","encore"]:
if canal in self.play_channels:
if self.play_status.get(canal,[-1])[0]==0:
try:
# trie par pseudo
scores.sort(lambda x,y:cmp(x[0].lower(),y[0].lower()))
serv.privmsg(auteur,"Scores by pseudo : "+" ; ".join(["%s %s"%(i[0],i[1]) for i in scores]))
- if cmd=="indice" and canal in self.play_channels:
- self.give_indice(serv,canal,None)
if is_tag(message) and not canal in self.quiet_channels:
if auteur in self.ops:
action=random.choice(config_tag_actions)
else:
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):
+ if self.play_status.get(canal,[-1])[0]==1:
+ answer=self.play_status[canal][2]
+ if reussi(message.decode("utf8"),answer,auteur):
serv.privmsg(canal,(u"%s: bravo ! (C'était %s)"%(auteur,answer)).encode("utf8"))
log(self.serveur,canal,auteur+"$win",message)
self.add_score(auteur,1)
if __name__=="__main__":
import sys
if len(sys.argv)==1:
- print "Usage : deconnaisseur.py <serveur> [--debug]"
+ print "Usage : Salesman.py <serveur> [--debug]"
exit(1)
serveur=sys.argv[1]
if "debug" in sys.argv or "--debug" in sys.argv:
except KeyError:
print "Server Unknown : %s"%(serveur)
exit(404)
- deco=Deconnaisseur(serveur,debug)
- deco.start()
+ salesman=Salesman(serveur,debug)
+ salesman.start()