except UnicodeDecodeError as exc:
raise UnicodeBotError
+def remplace_accents(chaine):
+ chaine=chaine.lower()
+ remplacements = {u"á":u"a",u"à":u"a",u"â":u"a",u"ä":u"a",u"é":u"e",u"è":u"e",u"ê":u"e",u"ë":u"e",u"í":u"i",u"ì":u"i",u"î":u"i",u"ï":u"i",u"ó":u"o", u"ò":u"o",u"ô":u"o",u"ö":u"o",u"ú":u"u",u"ù":u"u",u"û":u"u",u"ü":u"u",u"ý":u"y",u"ỳ":u"y",u"ŷ":u"y",u"ÿ":u"y",u"œ":u"oe",u"æ":u"ae"}
+ for avant,apres in remplacements.items():
+ chaine=chaine.replace(avant,apres)
+ return chaine
+
+
class Hung(ircbot.SingleServerIRCBot):
def __init__(self,serveur,debug=False):
temporary_pseudo=config_irc_pseudo+str(random.randrange(10000,100000))
log(self.serveur,"priv",auteur," ".join(message)+"[failed]")
else:
self.play_channels.append(message[1])
- self.play_status[message[1]]=[[None,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:
elif cmd in ["states","status"]:
if auteur in self.overops:
for k in self.play_status.keys():
- serv.privmsg(auteur,"%s : %s (%s) [%s]"%(k,"".join([str(i[0]) for i in self.play_status[k][0]])
+ if self.play_status[k]==[None,None,None]:
+ serv.privmsg(auteur,"None")
+ else:
+ 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:
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,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,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,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]
self.play_status[canal][0]=listeapres
self.affiche_mot(serv, canal, begin="%s placé"%(giv_let))
if all([lettre[1] for lettre in listeapres]):
- realword="".join([lettre[0] for lettre in self.play_status[canal][0]])
- definition = self.play_status[canal][1]
- serv.privmsg(canal,"Bravo ! C'était %s"%(realword))
- 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]]
+ self.gagne(serv, canal)
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))
+ # on essaye de voir si le mot fourni matche la partie en cours
+ mot = cmd
+ # bon, ce teste merde et j'arrive pas à trouver pourquoi, alors j'ai craqué, je l'ai mis dans un try
+ # bouh ! beurk ! pas bien ! promis, j'irai me flageller…
+ try:
+ if remplace_accents(mot)==("".join([i[0] for i in self.play_status[canal][0]])).lower():
+ # on a trouvé le mot
+ # on regarde combien de lettre il manquait
+ manquait = sum([not lettre[1] for lettre in self.play_status[canal][0]])
+ self.add_score({auteur: manquait})
+ if self.play_status[canal][2].has_key(auteur):
+ self.play_status[canal][2][auteur]+=manquait
+ else:
+ self.play_status[canal][2][auteur]=manquait
+ self.gagne(serv, canal, bonus=auteur, bonusvalue=manquait)
+ except:
+ pass
else:
pass
+
def on_action(self, serv, ev):
action = ev.arguments()[0]
auteur = irclib.nm_to_n(ev.source())
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]) )
+ def gagne(self, serv, canal, bonus=None, bonusvalue=2):
+ realword="".join([lettre[0] for lettre in self.play_status[canal][0]])
+ definition = self.play_status[canal][1]
+ serv.privmsg(canal,"Bravo ! C'était %s"%(realword))
+ serv.privmsg(canal,definition)
+ nlettre=float(len(realword.replace("'","").replace("-","")))
+ contribs=["%s:%s%%"%(pseudo,str(int(100*contrib/nlettre))+("+bonus(%s)"%(bonusvalue))*(bonus==pseudo)) 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]
+
if __name__=="__main__":
import sys