From: Vincent Le Gallic Date: Mon, 17 Jun 2013 11:31:10 +0000 (+0200) Subject: Maintenant on peut consommer n'importe quoi X-Git-Url: http://gitweb.pimeys.fr/?a=commitdiff_plain;h=667757031c816e434da2065b2d129402a7a72f5f;p=bots%2Fbasile.git Maintenant on peut consommer n'importe quoi --- diff --git a/basile.py b/basile.py index f3c193c..ecbef4e 100755 --- a/basile.py +++ b/basile.py @@ -651,15 +651,15 @@ class Basile(ircbot.SingleServerIRCBot): elif cmd in [u"ping"] and not canal in self.quiet_channels: serv.privmsg(canal, "%s: pong" % (auteur)) - elif cmd in [u"solde", u"!solde", u"!coca"]: + elif cmd in [u"solde", u"!solde", u"!coca"] or cmd.startswith("!"): if self.identities.has_key(auteur): idbde = self.identities[auteur]["idbde"] if cmd in [u"solde", u"!solde"]: success, solde, pseudo = nk.get_solde(self.nk, self.identities[auteur]["idbde"], serv, canal) if success: serv.privmsg(canal, "%s: %s (%s)" % (auteur, float(solde)/100, pseudo.encode("utf8"))) - elif cmd in [u"!coca"]: - success = nk.consomme(self.nk, self.identities[auteur]["idbde"], u"Coca", serv, canal) + elif cmd in [u"!coca"] or cmd.startswith("!"): + success = nk.consomme(self.nk, self.identities[auteur]["idbde"], message[1:], serv, canal) log(self.serveur, canal, auteur, message + ("[successful]" if success else "[failed]")) else: serv.privmsg(canal, "%s: Je ne connais pas votre pseudo note." % (auteur)) diff --git a/nk.py b/nk.py index f7f4bb3..0cbaed0 100644 --- a/nk.py +++ b/nk.py @@ -115,8 +115,11 @@ def consomme(sock, idbde, conso, serv, canal): retcode = ret["retcode"] if retcode == 0: boutons = ret["msg"] - ibouton = [b["label"].lower() for b in boutons].index(conso.lower()) - bouton = boutons[ibouton] + boutons = [b for b in boutons if b["label"].lower() == conso.lower()] + if len(boutons) == 0: + serv.privmsg(canal, (u"Impossible de trouver la conso %s" % (conso)).encode("utf-8")) + return False + bouton = boutons[0] sock.write(json.dumps(["consos", [[bouton["id"], idbde, 1]]])) ret = full_read(sock) if ret["retcode"] == 0: