From: Hung IRC Bot Date: Wed, 16 May 2012 08:27:25 +0000 (+0200) Subject: Gestion des contributions (nombre de lettres trouvées par qui) X-Git-Url: http://gitweb.pimeys.fr/?a=commitdiff_plain;h=1a684b3a06279e12e77e4c58c53696e08ec91032;p=bots%2Fhung.git Gestion des contributions (nombre de lettres trouvées par qui) --- 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: