Skip to content

Commit

Permalink
Updated Sopel.say to make message throttle and loop detection configu…
Browse files Browse the repository at this point in the history
…rable.

Fixes sopel-irc#1342
  • Loading branch information
predakanga committed May 21, 2019
1 parent 1220067 commit 61d8743
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sopel/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,15 +408,15 @@ def say(self, text, recipient, max_messages=1):
if elapsed < 3:
penalty = float(max(0, len(text) - 40)) / 70
wait = min(0.8 + penalty, 2) # Never wait more than 2 seconds
if elapsed < wait:
if elapsed < wait and self.config.core.message_throttle:
time.sleep(wait - elapsed)

# Loop detection
messages = [m[1] for m in self.stack[recipient_id][-8:]]

# If what we about to send repeated at least 5 times in the
# last 2 minutes, replace with '...'
if messages.count(text) >= 5 and elapsed < 120:
if messages.count(text) >= 5 and elapsed < 120 and self.config.core.message_loop_detection:
text = '...'
if messages.count('...') >= 3:
# If we said '...' 3 times, discard message
Expand Down
6 changes: 6 additions & 0 deletions sopel/config/core_section.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ def homedir(self):
'WARNING')
"""The lowest severity of logs to display."""

message_throttle = ValidatedAttribute('message_throttle', bool, default=True)
"""Whether messages will be throttled if too many are sent in a short time."""

message_loop_detection = ValidatedAttribute('message_loop_detection', bool, default=True)
"""Whether repeated messages will be replaced with '...', then dropped."""

modes = ValidatedAttribute('modes', default='B')
"""User modes to be set on connection."""

Expand Down

0 comments on commit 61d8743

Please sign in to comment.