]> gitweb.pimeys.fr Git - bots/hung.git/commitdiff
On passe les mots en mode mot/definition
authorVincent Le Gallic <legallic@crans.org>
Tue, 15 May 2012 14:58:06 +0000 (16:58 +0200)
committerVincent Le Gallic <legallic@crans.org>
Tue, 15 May 2012 14:58:06 +0000 (16:58 +0200)
hung.py

diff --git a/hung.py b/hung.py
index f1214cbedbf79a01497a6acfa56c8e18c47ecb26..94f3952985afe7b021599d2f3a04e6962ab374a4 100755 (executable)
--- a/hung.py
+++ b/hung.py
@@ -35,7 +35,8 @@ config_overops=["[20-100]","[20-100]_"]
 config_ops=[]
 config_report_bugs_to=["[20-100]"]
 
-config_dico_file="dico"
+config_dico_mots="mots.txt"
+config_dico_defs="definitions.txt"
 
 def log(serveur,channel,auteur=None,message=None):
     f=open(get_config_logfile(serveur),"a")
@@ -148,7 +149,7 @@ class Hung(ircbot.SingleServerIRCBot):
                         log(self.serveur,"priv",auteur," ".join(message)+"[failed]")
                     else:
                         self.play_channels.append(message[1])
-                        self.play_status[message[1]]=[None]
+                        self.play_status[message[1]]=[[None,None]]
                         serv.privmsg(auteur,"Play channels : "+" ".join(self.play_channels))
                         log(self.serveur,"priv",auteur," ".join(message)+"[successful]")
                 else:
@@ -197,7 +198,8 @@ class Hung(ircbot.SingleServerIRCBot):
         elif cmd in ["states","status"]:
             if auteur in self.overops:
                 for k in self.play_status.keys():
-                    serv.privmsg(auteur,"%s : %s"%(k,"".join([str(i[0]) for i in self.play_status[k]])))
+                    serv.privmsg(auteur,"%s : %s (%s)"%(k,"".join([str(i[0]) for i in self.play_status[k][0]])
+                                                     ,self.play_status[k][1]))
         elif cmd=="die":
             if auteur in self.overops:
                 log(self.serveur,"priv",auteur," ".join(message)+"[successful]")
@@ -253,16 +255,18 @@ class Hung(ircbot.SingleServerIRCBot):
 
     def affiche_mot(self, serv, canal, begin="Mot courant"):
         if self.play_status.has_key(canal):
-            mot = self.play_status[canal]
+            mot = self.play_status[canal][0]
             obfuskated=" ".join([lettre[0] if lettre[1] else "_" for lettre in mot])
             serv.privmsg(canal,"%s : %s"%(begin,obfuskated))
 
     def start_partie(self, serv, canal):
-        dico=[mot.strip() for mot in open(config_dico_file).readlines()]
-        mot = random.choice(dico)
+        mots=[mot.strip() for mot in open(config_dico_mots).readlines()]
+        defs=[defi.strip() for defi in open(config_dico_defs).readlines()]
+        indice = random.randrange(0,len(mots))
+        mot,definition=mots[indice],defs[indice]
         # ' et - sont considérés comme déjà devinés
         mot = [(lettre,lettre in "'-") for lettre in list(mot)]
-        self.play_status[canal]=mot
+        self.play_status[canal]=[mot,definition]
         self.affiche_mot(serv, canal, begin="Devinez")
 
     def on_pubmsg(self, serv, ev):
@@ -303,26 +307,26 @@ class Hung(ircbot.SingleServerIRCBot):
             elif cmd in ["play","jeu","encore","again","partie","pendu","game","mot"]:
                 if not canal in self.quiet_channels and canal in self.play_channels:
                     if self.play_status.has_key(canal):
-                        if self.play_status[canal]==[None]:
+                        if self.play_status[canal]==[[None,None]]:
                             self.start_partie(serv, canal)
                         else:
                             self.affiche_mot(serv, canal, begin="%s: Rappel"%(auteur))
                     else:
-                        self.play_status[canal]=[None]
+                        self.play_status[canal]=[[None,None]]
                         self.start_partie(serv, canal)
                 elif not canal in self.play_channels:
                     serv.privmsg(canal,"%s: pas ici…"%(auteur))
             elif (cmd in list("azertyuiopqsdfghjklmwxcvbn") and canal in self.play_channels 
-                  and self.play_status.has_key(canal) and self.play_status[canal]!=[None]):
+                  and self.play_status.has_key(canal) and self.play_status[canal]!=[[None,None]]):
                 giv_let=cmd.upper()
-                liste=self.play_status[canal]
+                liste=self.play_status[canal][0]
                 listeapres=[(lettre[0],lettre[1] or lettre[0]==giv_let) for lettre in liste]
                 if liste!=listeapres:
-                    self.play_status[canal]=listeapres
+                    self.play_status[canal][0]=listeapres
                     self.affiche_mot(serv, canal, begin="%s placé"%(giv_let))
                 if all([lettre[1] for lettre in listeapres]):
                     serv.privmsg(canal,"Bravo ! C'était %s"%("".join([lettre[0] for lettre in listeapres])))
-                    self.play_status[canal]=[None]
+                    self.play_status[canal]=[[None,None]]
                     
                 
             if cmd in ["meur", "meurt","meurre","meurres"] and not canal in self.quiet_channels: