aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Sebastiaan Zeeff <[email protected]>2019-11-15 01:15:01 +0100
committerGravatar Sebastiaan Zeeff <[email protected]>2019-11-15 01:15:01 +0100
commit89890d6e1b673622cba918be48f325540e45db9e (patch)
tree17aeb679e951a9713ba188d0836b8c99666b017f
parentRefactor DuckPond msg relay to separate method (diff)
Move payload checks to start of DuckPond.on_raw_reaction_add
The `DuckPond.on_raw_message_add` event listener makes an API call to fetch the message the reaction was added to. However, we don't need to fetch the message if the reaction that was added is not relevant to the duck pond. To prevent such unnecessary API calls, I have moved the code that checks for the relevance of the reaction event to before the code that fetches the message.
-rw-r--r--bot/cogs/duck_pond.py14
1 files changed, 7 insertions, 7 deletions
diff --git a/bot/cogs/duck_pond.py b/bot/cogs/duck_pond.py
index b2b4ad0c2..68fb09408 100644
--- a/bot/cogs/duck_pond.py
+++ b/bot/cogs/duck_pond.py
@@ -129,6 +129,13 @@ class DuckPond(Cog):
amount of ducks specified in the config under duck_pond/threshold, it will
send the message off to the duck pond.
"""
+ # Is the emoji in the reaction a duck?
+ if payload.emoji.is_custom_emoji():
+ if payload.emoji.id not in constants.DuckPond.custom_emojis:
+ return
+ elif payload.emoji.name != "🦆":
+ return
+
channel = discord.utils.get(self.bot.get_all_channels(), id=payload.channel_id)
message = await channel.fetch_message(payload.message_id)
member = discord.utils.get(message.guild.members, id=payload.user_id)
@@ -137,13 +144,6 @@ class DuckPond(Cog):
if not self.is_staff(member) or member.bot:
return
- # Is the emoji in the reaction a duck?
- if payload.emoji.is_custom_emoji():
- if payload.emoji.id not in constants.DuckPond.custom_emojis:
- return
- elif payload.emoji.name != "🦆":
- return
-
# Does the message already have a green checkmark?
if await self.has_green_checkmark(message):
return