From dd11439d6c91b37b683f2a69e68436df159a6fac Mon Sep 17 00:00:00 2001 From: Vincent Le Gallic Date: Tue, 20 Aug 2019 13:48:29 +0200 Subject: [PATCH] On splitte le message de scores, souvent trop long --- config.py | 4 +++- saturnin.py | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/config.py b/config.py index 187d09a..6b13635 100644 --- a/config.py +++ b/config.py @@ -12,6 +12,8 @@ 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 play_channels = ["#flood"] +# taille max des messages IRC +MAX_LENGTH = 490 report_bugs_to = ["[20-100]"] # les logs @@ -39,7 +41,7 @@ killwords = [u"pan", u"bim", u"bang"] score_file="scores.pickle" -spawn_delays = [60*120, 60*240] +spawn_delays = [60*60, 60*480] spawn_sentences = [ u"Coin ! Coin !", u"A year spent in artificial intelligence is enough to make one believe in God.", diff --git a/saturnin.py b/saturnin.py index e1ac570..848019c 100755 --- a/saturnin.py +++ b/saturnin.py @@ -461,15 +461,29 @@ class Saturnin(ircbot.SingleServerIRCBot): def sendscore(self, to): self.serv.privmsg(to, "Votre score : %s"%(self.get_scores().get(to,0)) ) + def _sendscores(self, to, scores): + message = '' + for [nick, score] in scores: + score = '{}: {}'.format(nick, score) + if len(message) < config.MAX_LENGTH - len(score): + message += ' ' + score + else: + self.serv.privmsg(to, message) + message = score + if message: + self.serv.privmsg(to, message) + def sendscores(self, to): scores=self.get_scores().items() # trie par score scores.sort(lambda x,y:cmp(x[1],y[1])) scores.reverse() - self.serv.privmsg(to, "Scores by score : "+" ; ".join(["%s %s"%(i[0],i[1]) for i in scores])) + self.serv.privmsg(to, "Scores by score : ") + self._sendscores(to, scores) # trie par pseudo scores.sort(lambda x,y:cmp(x[0].lower(),y[0].lower())) - self.serv.privmsg(to, "Scores by pseudo : "+" ; ".join(["%s %s"%(i[0],i[1]) for i in scores])) + self.serv.privmsg(to, "Scores by pseudo : ") + self._sendscores(to, scores) def on_pubmsg(self, serv, ev): if ignore_event(serv, ev): -- 2.39.2