chanlist=["#flood", "#bot"] # liste des chans à rejoindre
stay_channels=["#flood", "#bot"] # liste des chans que le bot ne quitte pas, même sur demande d'un leave de la part d'un OP
quiet_channels=[] # liste des chans sur lesquels le bot ne parle pas
-spawn_channels = ["#flood"]
+play_channels = ["#flood"]
# les logs
logfile_template="saturnin.%s.log" # fichier de log (%s est remplacé par le nom du serveur)
leave_fail_messages = quit_fail_messages
# config spécial canard
-canards = [ur"\_%s<" % (tete) for tete in [u"0óøoOØ"]] + [""]
+canards = [ur"\_%s< " % (tete) for tete in u"0óøoOØ@"] + [""]
killwords = [u"pan", u"bim", u"bang"]
-score_file="scores.pickle"
\ No newline at end of file
+score_file="scores.pickle"
+
+spawn_delays = [60*10, 60*20]
+spawn_sentences = [
+u"Coin ! Coin !",
+u"A year spent in artificial intelligence is enough to make one believe in God.",
+u"Coin ! Coin ! I've got a bad feeling about this.",
+u"I'm the king of the world!",
+u"I am INVINCIBLE!",
+u"Coin ! Coin ! Run Forrest! Run!",
+u"Airplanes may kill you, but they ain't likely to hurt you.",
+u"For NASA, space is still a high priority.",
+u"Live long and prosper",
+u"I'm the king of the world!",
+u"zzzzzzzZZZZZZZZZZzzzzzzzzzzZZZZZZZZZz",
+u"The only time I have problems is when I sleep.",
+u"Think in the morning. Act in the noon. Eat in the evening. Sleep in the night.",
+u"Life is something to do when you can't get to sleep.",
+u"Men talk of killing time, while time quietly kills them.",
+u"Coin ! Coin ! It's a bird...it's a plane...it's _________!",
+]
+
+killed_templates = [u"I was killed by {0}"]
+proba_miss = 30 #%
+miss_templates = [
+u"The (bad) hunter {0} missed me !!!",
+u"The (bad) hunter {0} missed me !",
+u"The (bad) hunter {0} missed me…",
+u"The (bad) hunter {0} tried ... aw come on, baby, just touch it",
+u"The (bad) hunter {0} missed it by that much",
+u"The (bad) hunter {0} didn't touch me ... Victory is mine!",
+u"The (bad) hunter {0} Tried to kill me But, Noooooooooooo!",
+u"The (bad) hunter {0} have made a FAIL shot Do they teach you that in the CIA?",
+]
+proba_miss_sentence = 50 #%
+miss_sentences = [
+u"Are you on drugs ?",
+u"I've seen penguins that can shoot better than that.",
+u"Priceless. There is things you cannot buy, for the rest there is…",
+u"I can't hear you ! I'm using the scrambler.",
+]
+proba_killed_sentence = 40 #%
+killed_sentences = [
+u"While I thought that I was learning how to live, I have been learning how to die.",
+u"I can see your force is bigger than mine",
+u"Do you like D*cks ???",
+u"I'll be back.",
+u"I am become death, the destroyer of worlds.",
+u"I believed I was invincible.",
+u"Everything that has a beginning, has an end.",
+u"SOMEONE CALL 911!!!",
+u"And loving it!",
+u"NOOOOOOO!",
+u"I'm calling you a killer. A natural born killer. You always have been, and you always will be.",
+u"Are you the farmer?",
+]
+
+times_up_delays = [60*5, 60*10]
+times_up_sentences = [u"I stayed alive, you're too slow !!!"]
\ No newline at end of file
self.chanlist=config.chanlist
self.stay_channels=config.stay_channels
self.quiet_channels=config.quiet_channels
- self.spawn_channels=config.spawn_channels
- self.status = { chan : False for chan in self.spawn_channels }
+ self.play_channels=config.play_channels
+ self.status = { chan : [0, None] for chan in self.play_channels }
+ # 0 : pas de spawn prévu
+ # 1 : un spawn prévu,
+ # avec en deuxième paramètre le timestamp du moment où il a été déclenché (pas du moment où il se fera)
+ # 2 : alive
self.last_perdu=0
def give_me_my_pseudo(self,serv):
serv.privmsg("NickServ","IDENTIFY %s"%(config.irc_password))
log(self.serveur,"Connected")
if self.debug:
- self.chanlist = self.spawn_channels = ["#bot"]
- self.status = { chan : False for chan in self.spawn_channels }
+ self.chanlist = self.play_channels = ["#bot"]
+ self.status = { chan : [0, 0] for chan in self.play_channels }
for c in self.chanlist:
log(self.serveur,"JOIN %s"%(c))
serv.join(c)
+ if c in self.play_channels:
+ spawn_delay = random.randrange(*config.spawn_delays)
+ self.spawn(c, time.time(), spawn_delay)
def pourmoi(self, serv, message):
"""renvoie (False,lemessage) ou (True, le message amputé de "pseudo: ")"""
Me rend silencieux sur le channel.""",None],
"noquiet": [None,"""NOQUIET <channel>
Me rend la parole sur le channel.""",None],
+ "play": [None, """PLAY
+ Passe un channel en mode "jouer" """,None],
+ "noplay": [None, """NOPLAY
+ Passe un channel en mode "ne pas jouer" """,None],
+ "SPAWN": [None, """SPAWN <channel>
+ Me fait spawner sur le channel.""",None],
+ "reload": [None,"""RELOAD
+ Recharge la configuration.""",None],
"say": [None,None,"""SAY <channel> <message>
Me fait parler sur le channel."""],
"do": [None,None,"""DO <channel> <action>
Me déconnecte du serveur IRC."""]
}
helpmsg_default="Liste des commandes disponibles :\nHELP SCORE SCORES"
- helpmsg_ops=" JOIN LEAVE QUIET NOQUIET LOST"
+ helpmsg_ops=" JOIN LEAVE QUIET NOQUIET PLAY NOPLAY SPAWN"
helpmsg_overops=" SAY DO STAY NOSTAY OPS OVEROPS KICK DIE"
op,overop=auteur in self.ops, auteur in self.overops
if len(message)==1:
log(self.serveur,"priv",auteur," ".join(message)+"[failed]")
else:
notunderstood=True
+ elif cmd=="play":
+ 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]")
+ else:
+ self.play_channels.append(message[1])
+ self.spawn(message[1], 1)
+ serv.privmsg(auteur,"Play channels : "+" ".join(self.play_channels))
+ log(self.serveur,"priv",auteur," ".join(message)+"[successful]")
+ else:
+ serv.privmsg(auteur,"Play channels : "+" ".join(self.play_channels))
+ else:
+ notunderstood=True
+ elif cmd=="noplay":
+ if auteur in self.ops:
+ if len(message)>1:
+ if message[1] in self.play_channels:
+ self.play_channels.remove(message[1])
+ serv.privmsg(auteur,"Play channels : "+" ".join(self.play_channels))
+ log(self.serveur,"priv",auteur," ".join(message)+"[successful]")
+ else:
+ serv.privmsg(auteur,"Je ne play pas sur %s."%(message[1]))
+ log(self.serveur,"priv",auteur," ".join(message)+"[failed]")
+ else:
+ notunderstood=True
+ elif cmd=="spawn":
+ if auteur in self.ops:
+ if len(message)>1:
+ if message[1] in self.play_channels:
+ # Le plus pratique pour pas s'embêter c'est de mettre un
+ # delay d'une seconde, comme ça .spawn() fait le boulot
+ self.spawn(message[1], time.time(), 1)
+ else:
+ serv.privmsg(auteur, "Je ne joue pas sur %s" % message[1])
+ else:
+ serv.privmsg(auteur, "Syntaxe : SPAWN <channel>")
+ else:
+ notunderstood=True
elif cmd=="say":
if auteur in self.overops and len(message)>2:
serv.privmsg(message[1]," ".join(message[2:]))
serv.privmsg(auteur," ".join(self.overops))
else:
notunderstood=True
+ elif cmd=="reload":
+ if auteur in self.ops:
+ reload(config)
+ serv.privmsg(auteur,"done")
+ else:
+ notunderstood=True
elif cmd=="score":
if len(message)>1:
if len(message) in [3,4] and message[1].lower()=="transfert":
# trie par score
scores.sort(lambda x,y:cmp(x[1],y[1]))
scores.reverse()
- self.serv.privmsg(auteur,"Scores by score : "+" ; ".join(["%s %s"%(i[0],i[1]) for i in scores]))
+ self.serv.privmsg(to, "Scores by score : "+" ; ".join(["%s %s"%(i[0],i[1]) for i in scores]))
# trie par pseudo
scores.sort(lambda x,y:cmp(x[0].lower(),y[0].lower()))
- self.serv.privmsg(auteur,"Scores by pseudo : "+" ; ".join(["%s %s"%(i[0],i[1]) for i in scores]))
+ self.serv.privmsg(to, "Scores by pseudo : "+" ; ".join(["%s %s"%(i[0],i[1]) for i in scores]))
def on_pubmsg(self, serv, ev):
auteur = irclib.nm_to_n(ev.source())
- canal = ev.target()
+ channel = ev.target()
message = ev.arguments()[0]
try:
test=bot_unicode(message)
except UnicodeBotError:
- if config.utf8_trigger and not canal in self.quiet_channels:
- serv.privmsg(canal, (u"%s: %s"%(auteur,random.choice(config.utf8_fail_answers))).encode("utf8"))
+ if config.utf8_trigger and not channel in self.quiet_channels:
+ serv.privmsg(channel, (u"%s: %s"%(auteur,random.choice(config.utf8_fail_answers))).encode("utf8"))
return
pour_moi,message=self.pourmoi(serv,message)
if pour_moi and message.split()!=[]:
args=""
if cmd in ["meurs","die","crève"]:
if auteur in self.overops:
- log(self.serveur,canal,auteur,message+"[successful]")
+ log(self.serveur,channel,auteur,message+"[successful]")
self.mourir()
else:
- serv.privmsg(canal,("%s: %s"%(auteur,random.choice(config.quit_fail_messages))).encode("utf8"))
- log(self.serveur,canal,auteur,message+"[failed]")
+ serv.privmsg(channel,("%s: %s"%(auteur,random.choice(config.quit_fail_messages))).encode("utf8"))
+ log(self.serveur,channel,auteur,message+"[failed]")
elif cmd in ["part","leave","dégage","va-t-en","tut'tiresailleurs,c'estmesgalets"]:
- if auteur in self.ops and (not (canal in self.stay_channels)
+ if auteur in self.ops and (not (channel in self.stay_channels)
or auteur in self.overops):
- self.quitter(canal)
- log(self.serveur,canal,auteur,message+"[successful]")
- if canal in self.chanlist:
- self.chanlist.remove(canal)
+ self.quitter(channel)
+ log(self.serveur,channel,auteur,message+"[successful]")
+ if channel in self.chanlist:
+ self.chanlist.remove(channel)
else:
- serv.privmsg(canal,("%s: %s"%(auteur,random.choice(config.leave_fail_messages))).encode("utf8"))
- log(self.serveur,canal,auteur,message+"[failed]")
+ serv.privmsg(channel,("%s: %s"%(auteur,random.choice(config.leave_fail_messages))).encode("utf8"))
+ log(self.serveur,channel,auteur,message+"[failed]")
elif cmd == "score":
self.sendscore(auteur)
elif cmd == "scores":
self.sendscores(auteur)
else:
if is_pan(message):
- self.shot(auteur)
+ self.shot(channel, auteur)
def on_action(self, serv, ev):
action = ev.arguments()[0]
#~ serv.privmsg(channel, (u"%s: %s"%(auteur,random.choice(config.utf8_fail_answers))).encode("utf8"))
#~ return
#~ mypseudo=self.nick
-
-
+
def on_kick(self,serv,ev):
auteur = irclib.nm_to_n(ev.source())
channel = ev.target()
#~ else:
#~ serv.privmsg(channel,l1[i].format(auteur).encode("utf8"))
+ def spawn(self, channel, timestamp, delay=0):
+ if channel in self.play_channels:
+ if delay>0:
+ self.serv.execute_delayed(delay, self.spawn, (channel, timestamp))
+ self.status[channel] = [1, timestamp]
+ else:
+ # on teste le timestamp pour pas s'emmêler dans les spawn
+ infos = self.status.get(channel, [0,0])
+ if infos == [1, timestamp]:
+ spawn_sentence = random.choice(config.canards) + random.choice(config.spawn_sentences)
+ self.serv.privmsg(channel, spawn_sentence.encode("utf8"))
+ self.status[channel] = [2, timestamp]
+ times_up_delay = random.randrange(*config.times_up_delays)
+ self.serv.execute_delayed(times_up_delay, self.too_slow, (channel, timestamp))
+
+ def too_slow(self, channel, timestamp):
+ infos = self.status.get(channel, [0,0])
+ if infos == [2, timestamp]:
+ self.serv.privmsg(channel, random.choice(config.times_up_sentences).encode("utf8"))
+ respawn_delay = random.randrange(*config.spawn_delays)
+ self.spawn(channel, time.time(), respawn_delay)
+
+ def shot(self, channel, auteur):
+ if self.status.get(channel, [0, 0])[0] == 2:
+ succeed = random.randrange(0,101) > config.proba_miss
+ if succeed:
+ self.serv.privmsg(channel, random.choice(config.killed_templates).format(auteur).encode("utf8"))
+ self.add_score(auteur, 1)
+ if random.randrange(0, 101) < config.proba_killed_sentence:
+ self.serv.privmsg(channel, random.choice(config.killed_sentences).encode("utf8"))
+ respawn_delay = random.randrange(*config.spawn_delays)
+ self.spawn(channel, time.time(), respawn_delay)
+ else:
+ self.serv.privmsg(channel, random.choice(config.miss_templates).format(auteur).encode("utf8"))
+ if random.randrange(0,101) < config.proba_miss_sentence:
+ self.serv.privmsg(channel, random.choice(config.miss_sentences).encode("utf8"))
+
def quitter(self,chan,leave_message=None):
if leave_message==None:
leave_message=random.choice(config.leave_messages)
f.close()
return scores
- def add_score(self,pseudo,value):
+ def add_score(self, pseudo, value):
scores=self.get_scores()
if scores.has_key(pseudo):
scores[pseudo]+=value