aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Boris Muratov <[email protected]>2021-08-17 17:58:13 +0300
committerGravatar Boris Muratov <[email protected]>2021-08-17 17:58:13 +0300
commit20aea4ff8cf0362d08108535cd8f837cfb74d82b (patch)
treeac7e7f51a5213c022ce588afaf67402c1b225fa8
parentMerge #1752 - help channels: fix initialisation of available channels set (diff)
Move max_interval to init
The on_message event calculated the max interval value every time for no reason. The value is constant throughout the bot's up time.
-rw-r--r--bot/exts/filters/antispam.py16
1 files changed, 8 insertions, 8 deletions
diff --git a/bot/exts/filters/antispam.py b/bot/exts/filters/antispam.py
index 226da2790..da4583e76 100644
--- a/bot/exts/filters/antispam.py
+++ b/bot/exts/filters/antispam.py
@@ -116,6 +116,13 @@ class AntiSpam(Cog):
self.message_deletion_queue = dict()
+ # Fetch the rule configuration with the highest rule interval.
+ max_interval_config = max(
+ AntiSpamConfig.rules.values(),
+ key=itemgetter('interval')
+ )
+ self.max_interval = max_interval_config['interval']
+
self.bot.loop.create_task(self.alert_on_validation_error(), name="AntiSpam.alert_on_validation_error")
@property
@@ -155,15 +162,8 @@ class AntiSpam(Cog):
):
return
- # Fetch the rule configuration with the highest rule interval.
- max_interval_config = max(
- AntiSpamConfig.rules.values(),
- key=itemgetter('interval')
- )
- max_interval = max_interval_config['interval']
-
# Store history messages since `interval` seconds ago in a list to prevent unnecessary API calls.
- earliest_relevant_at = datetime.utcnow() - timedelta(seconds=max_interval)
+ earliest_relevant_at = datetime.utcnow() - timedelta(seconds=self.max_interval)
relevant_messages = [
msg async for msg in message.channel.history(after=earliest_relevant_at, oldest_first=False)
if not msg.author.bot