Skip to content
Merged
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
26 changes: 21 additions & 5 deletions techsupport_bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions techsupport_bot/commands/modmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions techsupport_bot/commands/relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)