From 1a684b3a06279e12e77e4c58c53696e08ec91032 Mon Sep 17 00:00:00 2001 From: Hung IRC Bot Date: Wed, 16 May 2012 10:27:25 +0200 Subject: [PATCH] =?utf8?q?Gestion=20des=20contributions=20(nombre=20de=20l?= =?utf8?q?ettres=20trouv=C3=A9es=20par=20qui)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- hung.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/hung.py b/hung.py index 5c3d97b..f9917cc 100755 --- a/hung.py +++ b/hung.py @@ -149,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,None]] + self.play_status[message[1]]=[[None,None,None]] serv.privmsg(auteur,"Play channels : "+" ".join(self.play_channels)) log(self.serveur,"priv",auteur," ".join(message)+"[successful]") else: @@ -198,8 +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 (%s)"%(k,"".join([str(i[0]) for i in self.play_status[k][0]]) - ,self.play_status[k][1])) + serv.privmsg(auteur,"%s : %s (%s) [%s]"%(k,"".join([str(i[0]) for i in self.play_status[k][0]]) + ,self.play_status[k][1], self.play_status[k][2])) elif cmd=="die": if auteur in self.overops: log(self.serveur,"priv",auteur," ".join(message)+"[successful]") @@ -266,7 +266,7 @@ class Hung(ircbot.SingleServerIRCBot): 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,definition] + self.play_status[canal]=[mot,definition,{}] self.affiche_mot(serv, canal, begin="Devinez") def on_pubmsg(self, serv, ev): @@ -307,21 +307,27 @@ class Hung(ircbot.SingleServerIRCBot): elif cmd in ["play","jeu","encore","again","partie","pendu","game","mot","go","allez"]: 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,None]]: + if self.play_status[canal]==[[None,None,None]]: self.start_partie(serv, canal) else: self.affiche_mot(serv, canal, begin="%s: Rappel"%(auteur)) else: - self.play_status[canal]=[[None,None]] + self.play_status[canal]=[[None,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,None]]): + and self.play_status.has_key(canal) and self.play_status[canal]!=[[None,None,None]]): giv_let=cmd.upper() liste=self.play_status[canal][0] listeapres=[(lettre[0],lettre[1] or lettre[0]==giv_let) for lettre in liste] if liste!=listeapres: + nbtrouvees=(sum([lettre[1] for lettre in listeapres if not lettre[0] in "'-"]) + - sum([lettre[1] for lettre in liste if not lettre[0] in "'-"])) + if self.play_status[canal][2].has_key(auteur): + self.play_status[canal][2][auteur]+= nbtrouvees + else: + self.play_status[canal][2][auteur] = nbtrouvees self.play_status[canal][0]=listeapres self.affiche_mot(serv, canal, begin="%s placé"%(giv_let)) if all([lettre[1] for lettre in listeapres]): @@ -329,7 +335,10 @@ class Hung(ircbot.SingleServerIRCBot): definition = self.play_status[canal][1] serv.privmsg(canal,"Bravo ! C'était %s"%(realword)) serv.privmsg(canal,definition) - self.play_status[canal]=[[None,None]] + nlettre=float(len(realword.replace("'","").replace("-",""))) + contribs=["%s:%s%%"%(pseudo,int(100*contrib/nlettre)) for pseudo,contrib in self.play_status[canal][2].items()] + serv.privmsg(canal,"Contributions : %s"%(" ".join(contribs)) ) + self.play_status[canal]=[[None,None,None]] if cmd in ["meur", "meurt","meurre","meurres"] and not canal in self.quiet_channels: -- 2.39.2