Skip to content

Commit

Permalink
More variable renaming and simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
kwaaak authored Mar 26, 2019
1 parent ef2dcf5 commit 87f718c
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions sopel/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit 87f718c

Please sign in to comment.