From 87f718cb7f6517903d41f3bfd64b5fe06883e02f Mon Sep 17 00:00:00 2001 From: kwaaak Date: Tue, 26 Mar 2019 22:17:48 +0100 Subject: [PATCH] More variable renaming and simplification https://github.com/sopel-irc/sopel/pull/1518/files#r268612840 --- sopel/bot.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/sopel/bot.py b/sopel/bot.py index 9086d7347a..81b8d14008 100644 --- a/sopel/bot.py +++ b/sopel/bot.py @@ -305,20 +305,18 @@ def say(self, text, recipient, max_messages=1): recipient_id = Identifier(recipient) - reciprec = self.stack.get(recipient_id) - if not reciprec: - reciprec = self.stack[recipient_id] = { - 'messages': [], - 'burst': self.config.core.flood_burst_lines, - } - - if not reciprec['burst']: + recipient = self.stack.setdefault(recipient_id, { + 'messages': [], + 'flood_left': self.config.core.flood_burst_lines, + }) + + if not reciprec['flood_left']: elapsed = time.time() - reciprec['messages'][-1][0] - reciprec['burst'] = min( + reciprec['flood_left'] = min( self.config.core.flood_burst_lines, int(elapsed) * self.config.core.flood_refill_rate) - if not reciprec['burst']: + if not reciprec['flood_left']: elapsed = time.time() - reciprec['messages'][-1][0] penalty = float(max(0, len(text) - 50)) / 70 wait = self.config.core.flood_empty_wait + penalty @@ -337,7 +335,7 @@ def say(self, text, recipient, max_messages=1): return self.write(('PRIVMSG', recipient), text) - reciprec['burst'] = max(0, reciprec['burst'] - 1) + reciprec['flood_left'] = max(0, reciprec['flood_left'] - 1) reciprec['messages'].append((time.time(), self.safe(text))) reciprec['messages'] = reciprec['messages'][-10:] finally: