diff options
| -rw-r--r-- | bot/exts/backend/error_handler.py | 7 | ||||
| -rw-r--r-- | bot/exts/moderation/clean.py | 6 | ||||
| -rw-r--r-- | bot/exts/moderation/modlog.py | 47 | 
3 files changed, 38 insertions, 22 deletions
| diff --git a/bot/exts/backend/error_handler.py b/bot/exts/backend/error_handler.py index 5126c0267..761991488 100644 --- a/bot/exts/backend/error_handler.py +++ b/bot/exts/backend/error_handler.py @@ -311,8 +311,11 @@ class ErrorHandler(Cog):              await ctx.send("There does not seem to be anything matching your query.")              ctx.bot.stats.incr("errors.api_error_404")          elif e.status == 400: -            content = await e.response.json() -            log.error(f"API responded with 400 for command {ctx.command}: %r.", content) +            log.error( +                "API responded with 400 for command %s: %r.", +                ctx.command, +                e.response_json or e.response_text, +            )              await ctx.send("According to the API, your request is malformed.")              ctx.bot.stats.incr("errors.api_error_400")          elif 500 <= e.status < 600: diff --git a/bot/exts/moderation/clean.py b/bot/exts/moderation/clean.py index 67f1851c4..1c47f8342 100644 --- a/bot/exts/moderation/clean.py +++ b/bot/exts/moderation/clean.py @@ -7,7 +7,7 @@ from datetime import datetime  from itertools import takewhile  from typing import Callable, Iterable, Literal, Optional, TYPE_CHECKING, Union -from discord import Colour, Message, NotFound, TextChannel, User, errors +from discord import Colour, Message, NotFound, TextChannel, Thread, User, errors  from discord.ext.commands import Cog, Context, Converter, Greedy, group, has_any_role  from discord.ext.commands.converter import TextChannelConverter  from discord.ext.commands.errors import BadArgument @@ -130,8 +130,8 @@ class Clean(Cog):          else:              if channels == "*":                  channels = { -                    channel for channel in ctx.guild.channels -                    if isinstance(channel, TextChannel) +                    channel for channel in ctx.guild.channels + ctx.guild.threads +                    if isinstance(channel, (TextChannel, Thread))                      # Assume that non-public channels are not needed to optimize for speed.                      and channel.permissions_for(ctx.guild.default_role).view_channel                  } diff --git a/bot/exts/moderation/modlog.py b/bot/exts/moderation/modlog.py index 80f68e442..67991730e 100644 --- a/bot/exts/moderation/modlog.py +++ b/bot/exts/moderation/modlog.py @@ -6,12 +6,14 @@ from datetime import datetime, timezone  from itertools import zip_longest  import discord +from botcore.site_api import ResponseCodeError  from dateutil.relativedelta import relativedelta  from deepdiff import DeepDiff  from discord import Colour, Message, Thread  from discord.abc import GuildChannel  from discord.ext.commands import Cog, Context  from discord.utils import escape_markdown, format_dt, snowflake_time +from sentry_sdk import add_breadcrumb  from bot.bot import Bot  from bot.constants import Categories, Channels, Colours, Emojis, Event, Guild as GuildConstant, Icons, Roles, URLs @@ -53,24 +55,35 @@ class ModLog(Cog, name="ModLog"):          if attachments is None:              attachments = [] -        response = await self.bot.api_client.post( -            'bot/deleted-messages', -            json={ -                'actor': actor_id, -                'creation': datetime.now(timezone.utc).isoformat(), -                'deletedmessage_set': [ -                    { -                        'id': message.id, -                        'author': message.author.id, -                        'channel_id': message.channel.id, -                        'content': message.content.replace("\0", ""),  # Null chars cause 400. -                        'embeds': [embed.to_dict() for embed in message.embeds], -                        'attachments': attachment, -                    } -                    for message, attachment in zip_longest(messages, attachments, fillvalue=[]) -                ] +        deletedmessage_set = [ +            { +                "id": message.id, +                "author": message.author.id, +                "channel_id": message.channel.id, +                "content": message.content.replace("\0", ""),  # Null chars cause 400. +                "embeds": [embed.to_dict() for embed in message.embeds], +                "attachments": attachment,              } -        ) +            for message, attachment in zip_longest(messages, attachments, fillvalue=[]) +        ] + +        try: +            response = await self.bot.api_client.post( +                "bot/deleted-messages", +                json={ +                    "actor": actor_id, +                    "creation": datetime.now(timezone.utc).isoformat(), +                    "deletedmessage_set": deletedmessage_set, +                } +            ) +        except ResponseCodeError as e: +            add_breadcrumb( +                category="api_error", +                message=str(e), +                level="error", +                data=deletedmessage_set, +            ) +            raise          return f"{URLs.site_logs_view}/{response['id']}" | 
