diff --git a/techsupport_bot/bot.py b/techsupport_bot/bot.py index c30e7afa0..1308ecc83 100644 --- a/techsupport_bot/bot.py +++ b/techsupport_bot/bot.py @@ -216,6 +216,23 @@ async def on_ready(self) -> None: for guild in self.guilds: await self.register_new_guild_config(str(guild.id)) + # DM Logging + + async def log_DM(self, sent_from: str, source: str, content: str) -> None: + """Logs a DM from any source + + Args: + sent_from (str): The username of the person who DMed the bot + source (str): What bot the person DMed + content (str): The string contents of the message recieved + """ + owner = await self.get_owner() + embed = auxiliary.generate_basic_embed( + f"{source} recieved a PM", f"PM from: {sent_from}\n{content}" + ) + embed.timestamp = datetime.datetime.utcnow() + await owner.send(embed=embed) + async def on_message(self, message: discord.Message) -> None: """Logs DMs and ensure that commands are processed @@ -232,11 +249,10 @@ async def on_message(self, message: discord.Message) -> None: attachment_urls = ", ".join(a.url for a in message.attachments) content_string = f'"{message.content}"' if message.content else "" attachment_string = f"({attachment_urls})" if attachment_urls else "" - await self.logger.send_log( - message=( - f"PM from `{message.author}`: {content_string} {attachment_string}" - ), - level=LogLevel.INFO, + await self.log_DM( + message.author, + "Main Discord Bot", + f"{content_string} {attachment_string}", ) await self.process_commands(message) diff --git a/techsupport_bot/commands/modmail.py b/techsupport_bot/commands/modmail.py index 58ac3f605..1a68e7744 100644 --- a/techsupport_bot/commands/modmail.py +++ b/techsupport_bot/commands/modmail.py @@ -83,7 +83,15 @@ async def on_message(self, message: discord.Message) -> None: Args: message (discord.Message): Every sent message, gets filtered to only dms """ + if isinstance(message.channel, discord.DMChannel) and not message.author.bot: + # Log all DMs regardless of what happens to them + await Ts_client.log_DM( + message.author, + "Modmail", + message.content, + ) + # User is banned from creating modmail threads if await Ts_client.models.ModmailBan.query.where( Ts_client.models.ModmailBan.user_id == str(message.author.id) diff --git a/techsupport_bot/commands/relay.py b/techsupport_bot/commands/relay.py index 7510862f1..34bee3d54 100644 --- a/techsupport_bot/commands/relay.py +++ b/techsupport_bot/commands/relay.py @@ -502,5 +502,8 @@ async def handle_dm_from_irc(self, message: str, event) -> None: message (str): The message from IRC that the IRC Bot recieved event (irc.client.Event): The event object that triggered this function """ - owner = await self.bot.get_owner() - await owner.send(f"PM from `{event.source}`: {message}") + await self.bot.log_DM( + event.source, + "IRC Bot", + message, + )