diff options
| author | 2020-06-12 15:10:21 +0200 | |
|---|---|---|
| committer | 2020-06-12 15:10:21 +0200 | |
| commit | b7f61a4bf92b19a42dd1f72336d67a092b5d8029 (patch) | |
| tree | d56baf50cb5fdcf44b2bc6d418d86d9895c6b141 | |
| parent | Incidents: implement `has_signals` helper (diff) | |
Incidents: move `add_signals` to module namespace
Looks like we'll need quite a few helpers, and I think it's cleaner
to keep them at module level.
It helps avoid the question of: what do I do if a staticmethod
depends on another staticmethod?
| -rw-r--r-- | bot/cogs/moderation/incidents.py | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/bot/cogs/moderation/incidents.py b/bot/cogs/moderation/incidents.py index 0d146bdc5..f7ef86836 100644 --- a/bot/cogs/moderation/incidents.py +++ b/bot/cogs/moderation/incidents.py @@ -46,6 +46,21 @@ def has_signals(message: discord.Message) -> bool: return not missing_signals +async def add_signals(incident: discord.Message) -> None: + """Add `Signal` member emoji to `incident` as reactions.""" + existing_reacts = own_reactions(incident) + + for signal_emoji in Signal: + + # This will not raise, but it is a superfluous API call that can be avoided + if signal_emoji.value in existing_reacts: + log.debug(f"Skipping emoji as it's already been placed: {signal_emoji}") + + else: + log.debug(f"Adding reaction: {signal_emoji}") + await incident.add_reaction(signal_emoji.value) + + class Incidents(Cog): """Automation for the #incidents channel.""" @@ -85,23 +100,8 @@ class Incidents(Cog): log.debug("Crawl task finished!") - @staticmethod - async def add_signals(incident: discord.Message) -> None: - """Add `Signal` member emoji to `incident` as reactions.""" - existing_reacts = own_reactions(incident) - - for signal_emoji in Signal: - - # This will not raise, but it is a superfluous API call that can be avoided - if signal_emoji.value in existing_reacts: - log.debug(f"Skipping emoji as it's already been placed: {signal_emoji}") - - else: - log.debug(f"Adding reaction: {signal_emoji}") - await incident.add_reaction(signal_emoji.value) - @Cog.listener() async def on_message(self, message: discord.Message) -> None: """Pass `message` to `add_signals` if and only if it satisfies `is_incident`.""" if is_incident(message): - await self.add_signals(message) + await add_signals(message) |