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:
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:
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:
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: