X-Git-Url: http://gitweb.pimeys.fr/?a=blobdiff_plain;f=hung.py;h=0000a911ec927254b52597bf1785c9e870604f48;hb=6ac9765ce7280aa6b2e5cf1acd4f45a53593a910;hp=674c09ebb04888cd963a64b1004cf61c5325ccfa;hpb=3a47cb6a49f4d1d7712408493c572f2765bb7a67;p=bots%2Fhung.git diff --git a/hung.py b/hung.py index 674c09e..0000a91 100755 --- a/hung.py +++ b/hung.py @@ -194,8 +194,11 @@ class Hung(ircbot.SingleServerIRCBot): if auteur in self.ops: if len(message)>1: if message[1] in self.play_channels: - serv.privmsg(auteur,"Je play déjà sur %s."%(message[1])) - log(self.serveur,"priv",auteur," ".join(message)+"[failed]") + if len(message) > 2: + self.start_partie(serv, message[1], " ".join(message[2:])) + else: + serv.privmsg(auteur,"Je play déjà sur %s."%(message[1])) + log(self.serveur,"priv",auteur," ".join(message)+"[failed]") else: self.play_channels.append(message[1]) self.play_status[message[1]]=[None,None,None] @@ -319,13 +322,16 @@ class Hung(ircbot.SingleServerIRCBot): obfuskated=" ".join([lettre[0] if lettre[1] else "_" for lettre in mot]) serv.privmsg(canal,"%s : %s"%(begin,obfuskated)) - def start_partie(self, serv, canal): - mots=[mot.strip() for mot in open(config.dico_mots).readlines()] - defs=[defi.strip() for defi in open(config.dico_defs).readlines()] - indice = random.randrange(0,len(mots)) - mot,definition=mots[indice],defs[indice] + def start_partie(self, serv, canal, mot=None): + if mot is None: + mots=[mot.strip() for mot in open(config.dico_mots).readlines()] + defs=[defi.strip() for defi in open(config.dico_defs).readlines()] + indice = random.randrange(0,len(mots)) + mot,definition=mots[indice],defs[indice] + else: + definition = "(custom word)" # ' et - sont considérés comme déjà devinés - mot = [(lettre,lettre in "'-()") for lettre in list(mot)] + mot = [(lettre,lettre in config.non_guess_chars) for lettre in list(mot)] self.play_status[canal]=[mot,definition,{}] self.tried_letters[canal] = set () self.lives[canal] = config.lives @@ -424,7 +430,7 @@ class Hung(ircbot.SingleServerIRCBot): serv.privmsg(canal,"%s: %s"%(auteur,ligne.encode("utf8"))) # on essaye de voir si le mot fourni matche la partie en cours mot = cmd - if self.play_status[canal][0]!=None and is_mot(mot, self.play_status[canal][0]): + if canal in self.play_channels and self.play_status[canal][0]!=None and is_mot(mot, self.play_status[canal][0]): # 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]])