From c22f5b299a841b33ded1eb1758879541a3404497 Mon Sep 17 00:00:00 2001 From: Vincent Le Gallic Date: Mon, 11 Jun 2012 02:18:45 +0200 Subject: [PATCH] =?utf8?q?On=20ne=20propose=20pas=20d'=C3=A9nigme=20si=20l?= =?utf8?q?e=20chan=20est=20mort?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Salesman.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Salesman.py b/Salesman.py index 820754d..ffb6be5 100755 --- a/Salesman.py +++ b/Salesman.py @@ -55,6 +55,12 @@ config_quit_messages=[u"goto Tombouctou"] config_leave_messages=[u"On continuera à jouer plus tard ;)"] +# Quand personne ne cause, on finit par se taire +# temps au bout duquel, si personne n'a parlé, on se tait +config_idle_time=20*60 +# liste des bots, qui ne sont pas considérés comme de l'activité +config_idle_bots=["deconnaisseur","Basile","historien","Hung","Salesman","Shadobot","Wen","___"] + class UnicodeBotError(Exception): pass def bot_unicode(chain): @@ -114,6 +120,7 @@ class Salesman(ircbot.SingleServerIRCBot): self.stay_channels=config_stay_channels self.play_channels=config_play_channels self.play_status={i:[0] for i in self.play_channels} + self.last_activity={} self.quiet_channels=[] def give_me_my_pseudo(self,serv): @@ -133,12 +140,17 @@ class Salesman(ircbot.SingleServerIRCBot): for c in self.chanlist: log(self.serveur,"JOIN %s"%(c)) serv.join(c) + self.update_activity(c,"") # la chaîne vide ne sera jamais un nom de bot et donc marchera toujours for c in self.play_channels: token=time.time()-3600 self.play_status[c]=[0,token] serv.execute_delayed(random.randrange(ttrig),self.start_enigme,(serv,c,token)) def start_enigme(self,serv,channel,token=None): + # On reste silencieux si lechan n'est pas actif + if not self.is_active(channel): + serv.execute_delayed(ttrig*5,self.start_enigme,(serv,channel,token)) + return if self.play_status[channel][0]==0 and channel in self.play_channels: ok="skip" if token==self.play_status[channel][-1]: @@ -446,6 +458,7 @@ class Salesman(ircbot.SingleServerIRCBot): auteur = irclib.nm_to_n(ev.source()) canal = ev.target() message = ev.arguments()[0] + self.update_activity(canal,auteur) try: test=bot_unicode(message) except UnicodeBotError: @@ -544,6 +557,7 @@ class Salesman(ircbot.SingleServerIRCBot): log(self.serveur,"%s kické de %s par %s (raison : %s)" %(victime,channel,auteur,raison)) time.sleep(5) serv.join(channel) + self.update_activity(message[1],"") # on ne dit rien au rejoin #l1,l2=config_kick_answers,config_kick_actions #n1,n2=len(l1),len(l2) @@ -584,6 +598,12 @@ class Salesman(ircbot.SingleServerIRCBot): def _getnick(self): return self.serv.get_nickname() nick = property(_getnick) + + def update_activity(self,canal,pseudo): + if not pseudo in config_idle_bots: + self.last_activity[canal]=time.time() + def is_active(self,canal): + return time.time()-self.last_activity[canal]