diff options
| author | 2020-06-12 14:53:00 +0200 | |
|---|---|---|
| committer | 2020-06-12 15:02:23 +0200 | |
| commit | 5762e57696978843991058f7bbfa826e3020dbba (patch) | |
| tree | 2c6d1cb6e2a8b3048df09dafd843dc6e1f4b2fa3 | |
| parent | Incidents: add `event_lock` for simple event synchronization (diff) | |
Incidents: abstract incident checking into a helper method
The code is now basically self-documenting, the docstring is no
longer necessary.
The ultimate goal is to allow `crawl_incidents` to be more smart
about which messages need to be passed to `add_signals`, so that
it doesn't need to sleep after each message.
| -rw-r--r-- | bot/cogs/moderation/incidents.py | 38 |
1 files changed, 14 insertions, 24 deletions
diff --git a/bot/cogs/moderation/incidents.py b/bot/cogs/moderation/incidents.py index 1cfa45dc4..e3c3922a1 100644 --- a/bot/cogs/moderation/incidents.py +++ b/bot/cogs/moderation/incidents.py @@ -24,6 +24,17 @@ ALLOWED_ROLES: t.Set[int] = {Roles.moderators, Roles.admins, Roles.owners} ALLOWED_EMOJI: t.Set[str] = {signal.value for signal in Signal} +def is_incident(message: discord.Message) -> bool: + """True if `message` qualifies as an incident, False otherwise.""" + conditions = ( + message.channel.id == Channels.incidents, # Message sent in #incidents + not message.author.bot, # Not by a bot + not message.content.startswith("#"), # Doesn't start with a hash + not message.pinned, # And isn't header + ) + return all(conditions) + + class Incidents(Cog): """Automation for the #incidents channel.""" @@ -80,27 +91,6 @@ class Incidents(Cog): @Cog.listener() async def on_message(self, message: discord.Message) -> None: - """ - Pass each incident sent in #incidents to `add_signals`. - - We recognize several exceptions. The following will be ignored: - * Messages sent outside of #incidents - * Messages Sent by bots - * Messages starting with the hash symbol # - * Pinned (header) messages - - Prefix message with # in situations where a verbal response is necessary. - Each such message must be deleted manually. - """ - if message.channel.id != Channels.incidents or message.author.bot: - return - - if message.content.startswith("#"): - log.debug(f"Ignoring comment message: {message.content=}") - return - - if message.pinned: - log.debug(f"Ignoring header message: {message.pinned=}") - return - - await self.add_signals(message) + """Pass `message` to `add_signals` if and only if it satisfies `is_incident`.""" + if is_incident(message): + await self.add_signals(message) |