diff options
author | 2019-11-27 17:42:48 +0100 | |
---|---|---|
committer | 2019-11-27 17:42:48 +0100 | |
commit | 4be37c1486ccb0a8fb680cb6dce51f8ad8028569 (patch) | |
tree | 09f9ff73d3ccb1d23b2d2fa55afdaa8c27607021 | |
parent | Apply suggestions from code review (diff) |
Move duckpond payload emoji check to method to create testable unit
I moved the check that tests if a payload contains a duck emoji to a
separate method. This makes it easier to test this part of the code
as a separate unit than when it's contained in the larger event
listener.
In addition, I kaizened the name `relay_message_to_duckpond` to the
less verbose `relay_message`; that's already clear enough.
-rw-r--r-- | bot/cogs/duck_pond.py | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/bot/cogs/duck_pond.py b/bot/cogs/duck_pond.py index 68fb09408..2d25cd17e 100644 --- a/bot/cogs/duck_pond.py +++ b/bot/cogs/duck_pond.py @@ -91,7 +91,7 @@ class DuckPond(Cog): duck_reactors.append(user.id) return duck_count - async def relay_message_to_duck_pond(self, message: Message) -> None: + async def relay_message(self, message: Message) -> None: """Relays the message's content and attachments to the duck pond channel.""" clean_content = message.clean_content @@ -120,6 +120,17 @@ class DuckPond(Cog): await message.add_reaction("✅") + @staticmethod + def _payload_has_duckpond_emoji(payload: RawReactionActionEvent) -> bool: + """Test if the RawReactionActionEvent payload contains a duckpond emoji.""" + if payload.emoji.is_custom_emoji(): + if payload.emoji.id in constants.DuckPond.custom_emojis: + return True + elif payload.emoji.name == "🦆": + return True + + return False + @Cog.listener() async def on_raw_reaction_add(self, payload: RawReactionActionEvent) -> None: """ @@ -130,10 +141,7 @@ class DuckPond(Cog): 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 != "🦆": + if not self._payload_has_duckpond_emoji(payload): return channel = discord.utils.get(self.bot.get_all_channels(), id=payload.channel_id) @@ -153,7 +161,7 @@ class DuckPond(Cog): # If we've got more than the required amount of ducks, send the message to the duck_pond. if duck_count >= constants.DuckPond.threshold: - await self.relay_message_to_duck_pond(message) + await self.relay_message(message) @Cog.listener() async def on_raw_reaction_remove(self, payload: RawReactionActionEvent) -> None: |