From e5bca50d9ec1272aaaa2ae8f4882e6e75f2e044c Mon Sep 17 00:00:00 2001 From: onerandomusername Date: Tue, 21 Oct 2025 14:44:41 -0400 Subject: [PATCH 1/3] fix: check for unknown/None content_type for pastebin uploader --- .../utils/attachment_pastebin_uploader.py | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/bot/exts/utils/attachment_pastebin_uploader.py b/bot/exts/utils/attachment_pastebin_uploader.py index 1ea74b5090..16c76fc75e 100644 --- a/bot/exts/utils/attachment_pastebin_uploader.py +++ b/bot/exts/utils/attachment_pastebin_uploader.py @@ -77,8 +77,24 @@ async def on_message_delete(self, message: discord.Message) -> None: @commands.Cog.listener() async def on_message(self, message: discord.Message) -> None: """Listens for messages containing attachments and offers to upload them to the pastebin.""" - # Check if the message contains an embedded file and is not sent by a bot or in DMs. - if message.author.bot or not message.guild or not any("charset" in a.content_type for a in message.attachments): + # Check the message is not sent by a bot or in DMs. + if message.author.bot or not message.guild: + return + + # Check if the message contains any text-based attachments. + # Note that Discord does not always provide a content type + # its not good enough to check the content type is text/plain, + # we still need to check the charset + attachments: list[discord.Attachment] = [] + for attachment in message.attachments: + if ( + attachment.content_type + and attachment.content_type.startswith("text/plain") + and "charset" in attachment.content_type + ): + attachments.append(attachment) + + if not attachments: return log.trace(f"Offering to upload attachments for {message.author} in {message.channel}, message {message.id}") @@ -106,11 +122,7 @@ async def on_message(self, message: discord.Message) -> None: self.pending_messages.discard(message.id) # Extract the attachments. - files = [ - await self._convert_attachment(f) - for f in message.attachments - if "charset" in f.content_type - ] + files = [await self._convert_attachment(f) for f in attachments] # Upload the files to the paste bin, exiting early if there's an error. log.trace(f"Attempting to upload {len(files)} file(s) to pastebin.") From 46e87eacd06be2acf606c62f7562b3057a74fa20 Mon Sep 17 00:00:00 2001 From: onerandomusername Date: Tue, 21 Oct 2025 16:22:27 -0400 Subject: [PATCH 2/3] don't check text/plain --- bot/exts/utils/attachment_pastebin_uploader.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/bot/exts/utils/attachment_pastebin_uploader.py b/bot/exts/utils/attachment_pastebin_uploader.py index 16c76fc75e..5b6bf02338 100644 --- a/bot/exts/utils/attachment_pastebin_uploader.py +++ b/bot/exts/utils/attachment_pastebin_uploader.py @@ -82,14 +82,11 @@ async def on_message(self, message: discord.Message) -> None: return # Check if the message contains any text-based attachments. - # Note that Discord does not always provide a content type - # its not good enough to check the content type is text/plain, - # we still need to check the charset + # we only require a charset here, as its setting is matched attachments: list[discord.Attachment] = [] for attachment in message.attachments: if ( attachment.content_type - and attachment.content_type.startswith("text/plain") and "charset" in attachment.content_type ): attachments.append(attachment) From 291cf01d47df8dd5d23a062e1048f5f6cd0bd6fe Mon Sep 17 00:00:00 2001 From: onerandomusername Date: Sun, 26 Oct 2025 00:32:37 -0400 Subject: [PATCH 3/3] fix: check content_type is not None before checking charset in filtering --- bot/exts/filtering/filtering.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/exts/filtering/filtering.py b/bot/exts/filtering/filtering.py index 97b194d658..210ae3fb05 100644 --- a/bot/exts/filtering/filtering.py +++ b/bot/exts/filtering/filtering.py @@ -235,7 +235,7 @@ async def on_message(self, msg: Message) -> None: text_contents = [ await _extract_text_file_content(a) - for a in msg.attachments if "charset" in a.content_type + for a in msg.attachments if a.content_type and "charset" in a.content_type ] if text_contents: