aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2020-05-10 18:53:42 -0700
committerGravatar MarkKoz <[email protected]>2020-05-11 12:03:12 -0700
commitab860e23a7e6206e68cb350257b63083cfbe1a15 (patch)
tree22c79bc6ef184912141cf1fee12f2f5e5874fa32
parentCorrect the return type annotation for the autospec decorator (diff)
Token remover: split some of `take_action` into separate functions
-rw-r--r--bot/cogs/token_remover.py32
1 files changed, 21 insertions, 11 deletions
diff --git a/bot/cogs/token_remover.py b/bot/cogs/token_remover.py
index 543f4c5a7..d6919839e 100644
--- a/bot/cogs/token_remover.py
+++ b/bot/cogs/token_remover.py
@@ -68,31 +68,41 @@ class TokenRemover(Cog):
await self.on_message(after)
async def take_action(self, msg: Message, found_token: str) -> None:
- """Remove the `msg` containing a token an send a mod_log message."""
- user_id, creation_timestamp, hmac = found_token.split('.')
+ """Remove the `msg` containing the `found_token` and send a mod log message."""
self.mod_log.ignore(Event.message_delete, msg.id)
- await msg.delete()
- await msg.channel.send(DELETION_MESSAGE_TEMPLATE.format(mention=msg.author.mention))
+ await self.delete_message(msg)
- message = (
- "Censored a seemingly valid token sent by "
- f"{msg.author} (`{msg.author.id}`) in {msg.channel.mention}, token was "
- f"`{user_id}.{creation_timestamp}.{'x' * len(hmac)}`"
- )
- log.debug(message)
+ log_message = self.format_log_message(msg, found_token)
+ log.debug(log_message)
# Send pretty mod log embed to mod-alerts
await self.mod_log.send_log_message(
icon_url=Icons.token_removed,
colour=Colour(Colours.soft_red),
title="Token removed!",
- text=message,
+ text=log_message,
thumbnail=msg.author.avatar_url_as(static_format="png"),
channel_id=Channels.mod_alerts,
)
self.bot.stats.incr("tokens.removed_tokens")
+ @staticmethod
+ async def delete_message(msg: Message) -> None:
+ """Remove a `msg` containing a token and send an explanatory message in the same channel."""
+ await msg.delete()
+ await msg.channel.send(DELETION_MESSAGE_TEMPLATE.format(mention=msg.author.mention))
+
+ @staticmethod
+ def format_log_message(msg: Message, found_token: str) -> str:
+ """Return the log message to send for `found_token` being censored in `msg`."""
+ user_id, creation_timestamp, hmac = found_token.split('.')
+ return (
+ "Censored a seemingly valid token sent by "
+ f"{msg.author} (`{msg.author.id}`) in {msg.channel.mention}, token was "
+ f"`{user_id}.{creation_timestamp}.{'x' * len(hmac)}`"
+ )
+
@classmethod
def find_token_in_message(cls, msg: Message) -> t.Optional[str]:
"""Return a seemingly valid token found in `msg` or `None` if no token is found."""