config_level2=[]
config_level3=["[20-100]","Petite-Peste","PEB"]
+config_debug_stdout = True
+config_logfile_template="deconnaisseur.%s.log"
+def get_config_logfile(serveur):
+ serveurs={"acoeur.crans.org":"acoeur","irc.crans.org":"crans"}
+ return config_logfile_template%(serveurs[serveur])
+
class UnicodeBotError(Exception):
pass
def bot_unicode(chain):
except UnicodeDecodeError:
raise UnicodeBotError
-def log(serveur,channel="prout",auteur=None,message=None):
- #f=open(config_logfile,"a")
- #if auteur==message==None:
- # chain=channel
- #else:
- # chain="%s [%s:%s] %s"%(time.strftime("%T"),channel,auteur,message)
- #f.write(chain+"\n")
- #print chain
- #f.close()
- a=0 # does nothing
+def log(serveur,channel,auteur=None,message=None):
+ f=open(get_config_logfile(serveur),"a")
+ if auteur==message==None:
+ # alors c'est que c'est pas un channel mais juste une ligne de log
+ chain="%s %s"%(time.strftime("%F %T"),channel)
+ else:
+ chain="%s [%s:%s] %s"%(time.strftime("%F %T"),channel,auteur,message)
+ f.write(chain+"\n")
+ if config_debug_stdout:
+ print chain
+ f.close()
def reussi(message,answer,answer_regexp,auteur):
serv.nick(config_pseudo)
def on_welcome(self, serv, ev):
+ self.serv=serv # ça serv ira :)
self.give_me_my_pseudo(serv)
serv.privmsg("NickServ","identify %s"%(config_password))
- log("Connected")
+ log(self.serveur,"Connected")
if self.debug:
self.chanlist=["#bot"]
self.play_channels=["#bot"]
for c in self.chanlist:
- log("JOIN %s"%(c))
+ log(self.serveur,"JOIN %s"%(c))
serv.join(c)
for c in self.play_channels:
token=time.time()-3600
ok="refuse"
if ok=="do_it":
enigme,indice,answer_reg,answer=self.get_enigme()
- print "%s; %s; %s; %s"%(enigme, indice, answer_reg, answer)
+ log(self.serveur,channel,u"$Énigme$".encode("utf8"),("%s; %s; %s; %s"%(enigme, indice, answer_reg, answer)).encode("utf8"))
serv.privmsg(channel,enigme.encode("utf8"))
token=time.time()
self.play_status[channel]=[1,enigme,indice,answer_reg,answer,token]
return enigme.decode("utf8"),indice.decode("utf8"),answer_reg.decode("utf8"),answer.decode("utf8")
def pourmoi(self, serv, message):
- pseudo=serv.get_nickname()
+ pseudo=self.nick
size=len(pseudo)
if message[:size]==pseudo and len(message)>size and message[size]==":":
return (True,message[size+1:].strip(" "))
serv.join(message[1])
self.chanlist.append(message[1])
serv.privmsg(auteur,"Channels : "+" ".join(self.chanlist))
- log("priv",auteur," ".join(message))
+ log(self.serveur,"priv",auteur," ".join(message))
else:
serv.privmsg(auteur,"Channels : "+" ".join(self.chanlist))
else:
if not (message[1] in self.stay_channels) or auteur in self.overops:
serv.part(message[1])
self.chanlist.remove(message[1])
- log("priv",auteur," ".join(message)+"[successful]")
+ log(self.serveur,"priv",auteur," ".join(message)+"[successful]")
else:
serv.privmsg(auteur,"Non, je reste !")
- log("priv",auteur," ".join(message)+"[failed]")
+ log(self.serveur,"priv",auteur," ".join(message)+"[failed]")
else:
serv.privmsg(auteur,"Je ne suis pas sur %s"%(message[1]))
else:
if len(message)>1:
if message[1] in self.stay_channels:
serv.privmsg(auteur,"Je stay déjà sur %s."%(message[1]))
- log("priv",auteur," ".join(message)+"[failed]")
+ log(self.serveur,"priv",auteur," ".join(message)+"[failed]")
else:
self.stay_channels.append(message[1])
serv.privmsg(auteur,"Stay channels : "+" ".join(self.stay_channels))
- log("priv",auteur," ".join(message)+"[successful]")
+ log(self.serveur,"priv",auteur," ".join(message)+"[successful]")
else:
serv.privmsg(auteur,"Stay channels : "+" ".join(self.stay_channels))
else:
if message[1] in self.stay_channels:
self.stay_channels.remove(message[1])
serv.privmsg(auteur,"Stay channels : "+" ".join(self.stay_channels))
- log("priv",auteur," ".join(message)+"[successful]")
+ log(self.serveur,"priv",auteur," ".join(message)+"[successful]")
else:
serv.privmsg(auteur,"Je ne stay pas sur %s."%(message[1]))
- log("priv",auteur," ".join(message)+"[failed]")
+ log(self.serveur,"priv",auteur," ".join(message)+"[failed]")
else:
notunderstood=True
elif cmd=="play":
if len(message)>1:
if message[1] in self.play_channels:
serv.privmsg(auteur,"Je play déjà sur %s."%(message[1]))
- log("priv",auteur," ".join(message)+"[failed]")
+ log(self.serveur,"priv",auteur," ".join(message)+"[failed]")
else:
self.play_channels.append(message[1])
self.play_status[message[1]]=[0,time.time()-3600]
serv.privmsg(auteur,"Play channels : "+" ".join(self.play_channels))
- log("priv",auteur," ".join(message)+"[successful]")
+ log(self.serveur,"priv",auteur," ".join(message)+"[successful]")
else:
serv.privmsg(auteur,"Play channels : "+" ".join(self.play_channels))
else:
if message[1] in self.play_channels:
self.play_channels.remove(message[1])
serv.privmsg(auteur,"Play channels : "+" ".join(self.play_channels))
- log("priv",auteur," ".join(message)+"[successful]")
+ log(self.serveur,"priv",auteur," ".join(message)+"[successful]")
else:
serv.privmsg(auteur,"Je ne play pas sur %s."%(message[1]))
- log("priv",auteur," ".join(message)+"[failed]")
+ log(self.serveur,"priv",auteur," ".join(message)+"[failed]")
else:
notunderstood=True
elif cmd=="quiet":
elif cmd=="say":
if auteur in self.overops and len(message)>2:
serv.privmsg(message[1]," ".join(message[2:]))
- log("priv",auteur," ".join(message))
+ log(self.serveur,"priv",auteur," ".join(message))
elif len(message)<=2:
serv.privmsg(auteur,"Syntaxe : SAY <channel> <message>")
else:
if cmd in ["meurs","die","crève"]:
if auteur in self.overops:
self.die()
- log(canal,auteur,message+"[successful]")
+ log(self.serveur,canal,auteur,message+"[successful]")
else:
serv.privmsg(canal,"%s: crève !"%(auteur))
- log(canal,auteur,message+"[failed]")
+ log(self.serveur,canal,auteur,message+"[failed]")
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))
if cmd in ["part","leave","dégage"]:
if auteur in self.ops and (not (canal in self.stay_channels)
or auteur in self.overops):
serv.part(canal,message="Éjecté par %s"%(auteur))
- log(canal,auteur,message+"[successful]")
+ log(self.serveur,canal,auteur,message+"[successful]")
self.chanlist.remove(canal)
else:
serv.privmsg(canal,"%s: Non, je reste !"%(auteur))
- log(canal,auteur,message+"[failed]")
+ log(self.serveur,canal,auteur,message+"[failed]")
if cmd in ["deviens","pseudo"]:
if auteur in self.ops:
become=args
serv.nick(become)
- log(canal,auteur,message+"[successful]")
+ log(self.serveur,canal,auteur,message+"[successful]")
if cmd in ["coucou"] and not canal in self.quiet_channels:
serv.privmsg(canal,"%s: coucou"%(auteur))
if cmd in ["ping"] and not canal in self.quiet_channels:
answer=self.play_status[canal][4]
if reussi(message.decode("utf8"),answer,answer_regexp,auteur):
serv.privmsg(canal,(u"%s: bravo ! (C'était %s)"%(auteur,answer)).encode("utf8"))
+ log(self.serveur,canal,auteur+"$win",message)
self.add_score(auteur,1)
token=time.time()
self.play_status[canal]=[0,token]
serv.execute_delayed(random.randrange(Ttrig*5,Ttrig*10),self.start_enigme,(serv,canal,token))
+
+ def on_kick(self,serv,ev):
+ auteur = irclib.nm_to_n(ev.source())
+ channel = ev.target()
+ victime = ev.arguments()[0]
+ raison = ev.arguments()[1]
+ if victime==self.nick:
+ log(self.serveur,"%s kické par %s (raison : %s)" %(victime,auteur,raison))
+ time.sleep(5)
+ serv.join(channel)
+ # on ne dit rien au rejoin
+ #l1,l2=config_kick_answers,config_kick_actions
+ #n1,n2=len(l1),len(l2)
+ #i=random.randrange(n1+n2)
+ #if i>=n1:
+ # serv.action(channel,l2[i-n1].format(auteur).encode("utf8"))
+ #else:
+ # serv.privmsg(channel,l1[i].format(auteur).encode("utf8"))
+
def get_scores(self):
f=open(config_score_file)
scores=pickle.load(f)
f=open(config_score_file,"w")
pickle.dump(scores,f)
f.close()
+
+ def _getnick(self):
+ return self.serv.get_nickname()
+ nick = property(_getnick)
if __name__=="__main__":
import sys