diff options
author | 2021-04-19 05:40:45 +0530 | |
---|---|---|
committer | 2021-10-11 12:05:36 +0530 | |
commit | 0f92fe11ffc8c6262c62bd7e9d0c4c81bd8da6f5 (patch) | |
tree | 8b4649d6cabfd907c318192a25deada220e175ef | |
parent | Do required flake8 changes in docstrings. (diff) |
Don't send errors, instead log them.
Errors shouldn't be sent in #incidents. Instead, log them with log.exception and make the function return.
-rw-r--r-- | bot/exts/moderation/incidents.py | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/bot/exts/moderation/incidents.py b/bot/exts/moderation/incidents.py index 7ef7eb327..a259db10d 100644 --- a/bot/exts/moderation/incidents.py +++ b/bot/exts/moderation/incidents.py @@ -123,9 +123,9 @@ 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 + 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) @@ -140,7 +140,7 @@ def has_signals(message: discord.Message) -> bool: return ALL_SIGNALS.issubset(own_reactions(message)) -async def make_message_link_embed(ctx: Context, message_link: str) -> discord.Embed: +async def make_message_link_embed(ctx: Context, message_link: str) -> t.Optional[discord.Embed]: """ Create an embedded representation of the discord message link contained in the incident report. @@ -156,8 +156,7 @@ async def make_message_link_embed(ctx: Context, message_link: str) -> discord.Em message = await message_convert_object.convert(ctx, message_link) except discord.DiscordException as e: - embed.title = str(e) - embed.colour = Colours.soft_red + log.exception(f"Failed to make message link embed for '{message_link}', raised exception: {e}") else: text = message.content @@ -169,8 +168,7 @@ async def make_message_link_embed(ctx: Context, message_link: str) -> discord.Em f"**Content:** {textwrap.shorten(text, 300, placeholder='...')}\n" "\n" ) - - return embed + return embed async def add_signals(incident: discord.Message) -> None: @@ -214,7 +212,9 @@ async def extract_message_links(message: discord.Message, bot: Bot) -> t.Optiona embeds = [] for message_link in message_links: ctx = await bot.get_context(message) - embeds.append(await make_message_link_embed(ctx, message_link[0])) + embed = await make_message_link_embed(ctx, message_link[0]) + if embed: + embeds.append(embed) return embeds[:10] |