Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bot/exts/filtering/filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
23 changes: 16 additions & 7 deletions bot/exts/utils/attachment_pastebin_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,21 @@ 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.
# 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 "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}")
Expand Down Expand Up @@ -106,11 +119,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.")
Expand Down