aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2020-04-13 22:42:16 -0700
committerGravatar MarkKoz <[email protected]>2020-06-13 11:21:02 -0700
commit76eff088a6e2aa832165087d441effee26d8fead (patch)
treea9abb3115e5e8beaf03d694b568e43ed94218556
parentCode block: add helper function to check if msg should be parsed (diff)
Code block: add helper function to check for channel cooldown
-rw-r--r--bot/cogs/codeblock/cog.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/bot/cogs/codeblock/cog.py b/bot/cogs/codeblock/cog.py
index 9dd42fa81..be7c3df84 100644
--- a/bot/cogs/codeblock/cog.py
+++ b/bot/cogs/codeblock/cog.py
@@ -182,6 +182,14 @@ class CodeBlockCog(Cog, name="Code Block"):
and channel.category.id in (Categories.help_available, Categories.help_in_use)
)
+ def is_on_cooldown(self, channel: discord.TextChannel) -> bool:
+ """
+ Return True if an embed was sent for `channel` in the last 300 seconds.
+
+ Note: only channels in the `channel_cooldowns` have cooldowns enabled.
+ """
+ return (time.time() - self.channel_cooldowns.get(channel.id, 0)) < 300
+
def is_valid_channel(self, channel: discord.TextChannel) -> bool:
"""Return True if `channel` is a help channel, may be on cooldown, or is whitelisted."""
return (
@@ -217,8 +225,7 @@ class CodeBlockCog(Cog, name="Code Block"):
properly formatted Python syntax highlighting codeblocks.
"""
if self.should_parse(msg): # no token in the msg
- on_cooldown = (time.time() - self.channel_cooldowns.get(msg.channel.id, 0)) < 300
- if not on_cooldown or DEBUG_MODE:
+ if not self.is_on_cooldown(msg.channel) or DEBUG_MODE:
try:
if self.has_bad_ticks(msg):
ticks = msg.content[:3]