diff options
| author | 2019-10-31 13:07:55 +0100 | |
|---|---|---|
| committer | 2019-10-31 13:07:55 +0100 | |
| commit | bed913eb358f3effa592cab507f329ce8f50171a (patch) | |
| tree | a6b9c44e34c1330178164a2ee1ef58528546dc1b | |
| parent | Merge pull request #527 from kraktus/compact_free (diff) | |
Re-post attachments
Before sending the attachments to API for logging, we now re-post them in the channel that have the id
stored in the constant Guild.attachment_repost (it needs to be configured). These new links will never expires.
| -rw-r--r-- | bot/cogs/antispam.py | 4 | ||||
| -rw-r--r-- | bot/cogs/moderation/modlog.py | 19 | ||||
| -rw-r--r-- | bot/constants.py | 1 | ||||
| -rw-r--r-- | config-default.yml | 1 |
4 files changed, 20 insertions, 5 deletions
diff --git a/bot/cogs/antispam.py b/bot/cogs/antispam.py index 1340eb608..a450c18ce 100644 --- a/bot/cogs/antispam.py +++ b/bot/cogs/antispam.py @@ -1,4 +1,3 @@ -import asyncio import logging from collections.abc import Mapping from dataclasses import dataclass, field @@ -243,9 +242,6 @@ class AntiSpam(Cog): async def _process_deletion_context(self, context_id: int) -> None: """Processes the Deletion Context queue.""" - log.trace("Sleeping before processing message deletion queue.") - await asyncio.sleep(10) - if context_id not in self.message_deletion_queue: log.error(f"Started processing deletion queue for context `{context_id}`, but it was not found!") return diff --git a/bot/cogs/moderation/modlog.py b/bot/cogs/moderation/modlog.py index 88f2b6c67..6d4b66644 100644 --- a/bot/cogs/moderation/modlog.py +++ b/bot/cogs/moderation/modlog.py @@ -2,6 +2,7 @@ import asyncio import logging import typing as t from datetime import datetime +from io import BytesIO import discord from dateutil.relativedelta import relativedelta @@ -53,7 +54,8 @@ class ModLog(Cog, name="ModLog"): 'author': message.author.id, 'channel_id': message.channel.id, 'content': message.content, - 'embeds': [embed.to_dict() for embed in message.embeds] + 'embeds': [embed.to_dict() for embed in message.embeds], + 'attachments': await self.reupload_attachments(message) if message.attachments else [], } for message in messages ] @@ -116,6 +118,21 @@ class ModLog(Cog, name="ModLog"): return await self.bot.get_context(log_message) # Optionally return for use with antispam + async def reupload_attachments( + self, + message: discord.Message, + channel_id: int = GuildConstant.attachment_repost + ) -> t.List[str]: + """Re-upload message's attachments to the the channel_id and return the list of re-posted attachments URLs.""" + channel = self.bot.get_channel(channel_id) + out = [] + for attachment in message.attachments: + buffer = BytesIO() + await attachment.save(buffer, use_cached=True) + reupload = await channel.send(file=discord.File(buffer, filename=attachment.filename)) + out.append(reupload.attachments[0].url) + return out + @Cog.listener() async def on_guild_channel_create(self, channel: GUILD_CHANNEL) -> None: """Log channel create event to mod log.""" diff --git a/bot/constants.py b/bot/constants.py index 838fe7a79..9582fea96 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -398,6 +398,7 @@ class Guild(metaclass=YAMLGetter): id: int ignored: List[int] staff_channels: List[int] + attachment_repost: int class Keys(metaclass=YAMLGetter): diff --git a/config-default.yml b/config-default.yml index 4638a89ee..9d2ee7941 100644 --- a/config-default.yml +++ b/config-default.yml @@ -127,6 +127,7 @@ guild: staff_channels: [*ADMINS, *ADMIN_SPAM, *MOD_SPAM, *MODS, *HELPERS, *ORGANISATION, *DEFCON] ignored: [*ADMINS, *MESSAGE_LOG, *MODLOG] + attachment_repost: *MODLOG roles: admin: &ADMIN_ROLE 267628507062992896 |