]> gitweb.pimeys.fr Git - bots/basile.git/blobdiff - basile.py
Précaution encodage foireux dans on_action
[bots/basile.git] / basile.py
index cb69a9f8b72f4abf3d794f8fa15a75561053ee43..e7ed6cae2bcedde6de97c3a0f849c1d1314550e7 100755 (executable)
--- a/basile.py
+++ b/basile.py
@@ -178,9 +178,13 @@ def connect_NK():
 
 def login_NK(username,password,typ="bdd"):
     sock=connect_NK()
 
 def login_NK(username,password,typ="bdd"):
     sock=connect_NK()
+    if typ=="special": # ça c'est pour Basile lui-même
+        masque='["note"]'
+    elif typ=="bdd":
+        masque='[["all"],["all"],false]'
     try:
         # Basile a un compte special user
     try:
         # Basile a un compte special user
-        commande='login [%s,%s,"%s"]'%(json.dumps(username),json.dumps(password),typ)
+        commande='login [%s,%s,"%s",%s]'%(json.dumps(username),json.dumps(password),typ,masque)
         sock.write(commande)
         out=sock.read()
     except Exception as exc:
         sock.write(commande)
         out=sock.read()
     except Exception as exc:
@@ -428,15 +432,17 @@ class Basile(ircbot.SingleServerIRCBot):
  HELP       Affiche de l'aide sur une commande.
  CONNECT    Ouvre une connection au serveur Note Kfet.
  IDENTIFY   Me permet de savoir qui tu es sur la note kfet.
  HELP       Affiche de l'aide sur une commande.
  CONNECT    Ouvre une connection au serveur Note Kfet.
  IDENTIFY   Me permet de savoir qui tu es sur la note kfet.
- DROP       Me fait oublier ton identité."""
+ DROP       Me fait oublier ton identité.
+ SOLDE      Obtenir ton solde"""
             helpmsg_ops="""
  JOIN       Faire rejoindre un chan
  LEAVE      Faire quitter un chan
  QUIET      Se taire sur un chan
  NOQUIET    Opposé de QUIET
             helpmsg_ops="""
  JOIN       Faire rejoindre un chan
  LEAVE      Faire quitter un chan
  QUIET      Se taire sur un chan
  NOQUIET    Opposé de QUIET
- LOST       Perdre sur un chan"""
+ LOST       Perdre sur un chan
+ SOLDE <pseudo>  Donner le solde de quelqu'un"""
             helpmsg_overops="""
             helpmsg_overops="""
- SAY        Fais envoyer un message sur un chan ou à une personne
+ SAY        Fait envoyer un message sur un chan ou à une personne
  STAY       Ignorera les prochains LEAVE pour un chan
  NOSTAY     Opposé de STAY
  DIE        Mourir"""
  STAY       Ignorera les prochains LEAVE pour un chan
  NOSTAY     Opposé de STAY
  DIE        Mourir"""
@@ -590,6 +596,33 @@ class Basile(ircbot.SingleServerIRCBot):
                 serv.privmsg(auteur,"Syntaxe : LOST <channel>")
             else:
                 notunderstood=True
                 serv.privmsg(auteur,"Syntaxe : LOST <channel>")
             else:
                 notunderstood=True
+        elif cmd=="solde":
+            if len(message)==1:
+                if self.identities.has_key(auteur):
+                    try:
+                        self.nk.write('search ["x",["pseudo"],%s]'%(json.dumps(self.identities[auteur])))
+                        ret=json.loads(self.nk.read())
+                        solde=ret["msg"][0]["solde"]
+                        pseudo=ret["msg"][0]["pseudo"]
+                    except Exception as exc:
+                        print exc
+                        serv.privmsg(auteur,"failed")
+                        log(self.serveur,"priv",auteur," ".join(message)+"[failed]")
+                        return
+                    serv.privmsg(auteur,"%s (%s)"%(float(solde)/100,pseudo.encode("utf8")))
+                else:
+                    serv.privmsg(canal,"Je ne connais pas ton pseudo note.")
+            elif auteur in self.ops:
+                try:
+                    self.nk.write('search ["x",["pseudo"],%s]'%(json.dumps(message[1])))
+                    ret=json.loads(self.nk.read())
+                    solde=ret["msg"][0]["solde"]
+                    pseudo=ret["msg"][0]["pseudo"]
+                except Exception as exc:
+                    serv.privmsg(auteur,"failed")
+                    log(self.serveur,"priv",auteur," ".join(message)+"[failed]")
+                    return
+                serv.privmsg(auteur,"%s (%s)"%(float(solde)/100,pseudo.encode("utf8")))
         else:
             notunderstood=True
         if notunderstood:
         else:
             notunderstood=True
         if notunderstood:
@@ -602,9 +635,10 @@ class Basile(ircbot.SingleServerIRCBot):
         try:
             test=bot_unicode(message)
         except UnicodeBotError:
         try:
             test=bot_unicode(message)
         except UnicodeBotError:
-            serv.privmsg(canal,
-              "%s: Euh, tu fais de la merde avec ton encodage là, j'ai failli crasher…"%(auteur))
-            return
+            if not canal in self.quiet_channels:
+                serv.privmsg(canal,
+                  "%s: Euh, tu fais de la merde avec ton encodage là, j'ai failli crasher…"%(auteur))
+                return
         pour_moi,message=self.pourmoi(serv,message)
         if pour_moi and message.split()!=[]:
             cmd=message.split()[0].lower()
         pour_moi,message=self.pourmoi(serv,message)
         if pour_moi and message.split()!=[]:
             cmd=message.split()[0].lower()
@@ -791,13 +825,20 @@ class Basile(ircbot.SingleServerIRCBot):
         action = ev.arguments()[0]
         auteur = irclib.nm_to_n(ev.source())
         channel = ev.target()
         action = ev.arguments()[0]
         auteur = irclib.nm_to_n(ev.source())
         channel = ev.target()
+        try:
+            test=bot_unicode(message)
+        except UnicodeBotError:
+            serv.privmsg(channel,
+              "%s : Euh, tu fais de la merde avec ton encodage là, j'ai failli crasher…"%(auteur))
+            return
         mypseudo=serv.get_nickname()
         mypseudo=serv.get_nickname()
+        
         if is_action_trigger(action,mypseudo):
             l1,l2=config_action_answers,config_action_actions
             n1,n2=len(l1),len(l2)
             i=random.randrange(n1+n2)
             if i>=n1:
         if is_action_trigger(action,mypseudo):
             l1,l2=config_action_answers,config_action_actions
             n1,n2=len(l1),len(l2)
             i=random.randrange(n1+n2)
             if i>=n1:
-                serv.action(channel,l2[i-n1])
+                serv.action(channel,l2[i-n1].encode("utf8"))
             else:
                 serv.privmsg(channel,"%s: %s"%(auteur,l1[i].encode("utf8")))
 
             else:
                 serv.privmsg(channel,"%s: %s"%(auteur,l1[i].encode("utf8")))