]> gitweb.pimeys.fr Git - bots/hung.git/commitdiff
On est capable de lancer une partie et de rappeler le mot courant
authorVincent Le Gallic <legallic@crans.org>
Mon, 14 May 2012 10:59:39 +0000 (12:59 +0200)
committerVincent Le Gallic <legallic@crans.org>
Mon, 14 May 2012 10:59:39 +0000 (12:59 +0200)
hung.py

diff --git a/hung.py b/hung.py
index 9d640fe12b7104a3282c4b91c4358f8d0cba3704..7f25389af3c85e6605bbcd487435b6c857599bae 100755 (executable)
--- a/hung.py
+++ b/hung.py
@@ -23,8 +23,9 @@ if "--quiet" in sys.argv:
 
 config_irc_password="I'mAHungMan"
 config_irc_pseudo="Hung"
-config_chanlist=["#flood"]
-config_stay_channels=["#flood"]
+config_chanlist=["#bot","#flood"]
+config_stay_channels=["#bot","#flood"]
+config_play_channels=["#flood"]
 config_quiet_channels=[]
 config_logfile_template="hung.%s.log"
 def get_config_logfile(serveur):
@@ -34,6 +35,8 @@ config_overops=["[20-100]","[20-100]_"]
 config_ops=[]
 config_report_bugs_to=["[20-100]"]
 
+config_dico_file="dico"
+
 def log(serveur,channel,auteur=None,message=None):
     f=open(get_config_logfile(serveur),"a")
     if auteur==message==None:
@@ -67,6 +70,7 @@ class Hung(ircbot.SingleServerIRCBot):
         self.chanlist=config_chanlist
         self.stay_channels=config_stay_channels
         self.play_channels=config_play_channels
+        self.play_status={}
         self.quiet_channels=config_quiet_channels
 
 
@@ -144,7 +148,7 @@ class Hung(ircbot.SingleServerIRCBot):
                         log("priv",auteur," ".join(message)+"[failed]")
                     else:
                         self.play_channels.append(message[1])
-                        self.play_status[message[1]]=None
+                        self.play_status[message[1]]=[None]
                         serv.privmsg(auteur,"Play channels : "+" ".join(self.play_channels))
                         log("priv",auteur," ".join(message)+"[successful]")
                 else:
@@ -190,6 +194,10 @@ class Hung(ircbot.SingleServerIRCBot):
 
             else:
                 notunderstood=True
+        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) for i in self.play_status[k]])))
         elif cmd=="die":
             if auteur in self.overops:
                 log(self.serveur,"priv",auteur," ".join(message)+"[successful]")
@@ -242,7 +250,21 @@ class Hung(ircbot.SingleServerIRCBot):
             notunderstood=True
         if notunderstood:
             serv.privmsg(auteur,"Je n'ai pas compris. Essaye HELP…")
-    
+
+    def affiche_mot(self, serv, canal, begin="Mot courant"):
+        if self.play_status.has_key(canal):
+            mot = self.play_status[canal]
+            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)
+        # ' 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.affiche_mot(serv, canal, begin="Devinez")
+
     def on_pubmsg(self, serv, ev):
         auteur = irclib.nm_to_n(ev.source())
         canal = ev.target()
@@ -278,7 +300,18 @@ class Hung(ircbot.SingleServerIRCBot):
                 else:
                     serv.privmsg(canal,"%s: Non, je reste !"%(auteur))
                     log(self.serveur,canal,auteur,message+"[failed]")
-            
+            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]:
+                            self.start_partie(serv, canal)
+                        else:
+                            self.affiche_mot(serv, canal, begin="%s: Rappel"%(auteur))
+                    else:
+                        self.play_status[canal]=[None]
+                        self.start_partie(serv, canal)
+                elif not canal in self.play_channels:
+                    serv.privmsg(canal,"%s: pas ici…"%(auteur))
             if cmd in ["meur", "meurt","meurre","meurres"] and not canal in self.quiet_channels:
                 serv.privmsg(canal,'%s: Mourir, impératif, 2ème personne du singulier : "meurs" (de rien)'%(auteur))
         else: