From 61d874398c626eeafcf14e5f49796a36f3d2dd4e Mon Sep 17 00:00:00 2001 From: Lachlan Pease Date: Tue, 21 May 2019 23:38:56 +1000 Subject: [PATCH] Updated Sopel.say to make message throttle and loop detection configurable. Fixes #1342 --- sopel/bot.py | 4 ++-- sopel/config/core_section.py | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/sopel/bot.py b/sopel/bot.py index c10d59898d..51f643612d 100644 --- a/sopel/bot.py +++ b/sopel/bot.py @@ -408,7 +408,7 @@ 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 @@ -416,7 +416,7 @@ def say(self, text, recipient, max_messages=1): # 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 diff --git a/sopel/config/core_section.py b/sopel/config/core_section.py index 5cef54cd13..dda60c5d3f 100644 --- a/sopel/config/core_section.py +++ b/sopel/config/core_section.py @@ -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."""