]> gitweb.pimeys.fr Git - bots/hung.git/commitdiff
+scores (dans un fichier)
authorHung IRC Bot <hung@crans.org>
Wed, 16 May 2012 08:54:56 +0000 (10:54 +0200)
committerHung IRC Bot <hung@crans.org>
Wed, 16 May 2012 08:54:56 +0000 (10:54 +0200)
hung.py
scores.pickle [new file with mode: 0644]

diff --git a/hung.py b/hung.py
index f9917cc900eb1f0b7da9b82e9c71f5b492d6f434..b49fc62a8317fd6dc2e0729eab905f70026e05d3 100755 (executable)
--- a/hung.py
+++ b/hung.py
@@ -38,6 +38,9 @@ config_report_bugs_to=["[20-100]"]
 config_dico_mots="mots.txt"
 config_dico_defs="definitions.txt"
 
+config_scores_file="scores.pickle"
+
+
 def log(serveur,channel,auteur=None,message=None):
     f=open(get_config_logfile(serveur),"a")
     if auteur==message==None:
@@ -248,6 +251,8 @@ class Hung(ircbot.SingleServerIRCBot):
                 serv.privmsg(auteur,"Syntaxe : DO <channel> <action>")
             else:
                 notunderstood=True
+        elif cmd in ["score","scores"]:
+            self.send_scores(serv,auteur)
         else:
             notunderstood=True
         if notunderstood:
@@ -337,10 +342,13 @@ class Hung(ircbot.SingleServerIRCBot):
                     serv.privmsg(canal,definition)
                     nlettre=float(len(realword.replace("'","").replace("-","")))
                     contribs=["%s:%s%%"%(pseudo,int(100*contrib/nlettre)) for pseudo,contrib in self.play_status[canal][2].items()]
+                    contribs_score={pseudo:int(10*contrib/nlettre) for pseudo,contrib in self.play_status[canal][2].items()}
+                    self.add_score(contribs_score)
                     serv.privmsg(canal,"Contributions : %s"%("  ".join(contribs)) )
                     self.play_status[canal]=[[None,None,None]]
                     
-                
+            elif cmd in ["score","scores","!score","!scores"]:
+                self.send_scores(serv,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:
@@ -358,6 +366,33 @@ class Hung(ircbot.SingleServerIRCBot):
             return
         mypseudo=serv.get_nickname()
         
+    def get_scores(self):
+        f=open(config_scores_file)
+        scores=pickle.load(f)
+        f.close()
+        return scores
+    def save_scores(self,scores):
+        f=open(config_scores_file,'w')
+        pickle.dump(scores,f)
+        f.close()
+    def add_score(self,dico):
+        scores=self.get_scores()
+        for k,v in dico.items():
+            if scores.has_key(k):
+                scores[k]+=v
+            else:
+                scores[k]=v
+        self.save_scores(scores)
+    def send_scores(self, serv, destinataire):
+        scores=self.get_scores()
+        scores=scores.items()
+        scores.sort(lambda x,y:cmp(x[1],y[1]))
+        scores.reverse()
+        serv.privmsg(destinataire,"Scores by score : "+" ; ".join(["%s %s"%(k,v) for (k,v) in scores]) )
+        scores.sort(lambda x,y:cmp(x[0].lower(),y[0].lower()))
+        serv.privmsg(destinataire,"Scores by pseudo : "+" ; ".join(["%s %s"%(k,v) for (k,v) in scores]) )
+
+
 if __name__=="__main__":
     import sys
     if len(sys.argv)==1:
diff --git a/scores.pickle b/scores.pickle
new file mode 100644 (file)
index 0000000..242f633
--- /dev/null
@@ -0,0 +1,5 @@
+(dp0
+S'[20-100]'
+p1
+I20
+s.
\ No newline at end of file