Skip to content
Merged
Changes from 2 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
8 changes: 8 additions & 0 deletions techsupport_bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def __init__(
)
)
self.command_execute_history: dict[str, dict[int, bool]] = {}
self.notified_dm_log: list[int] = []
Copy link

Copilot AI Jun 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a set[int] for notified_dm_log to improve membership-check performance and automatically prevent duplicate entries (e.g., self.notified_dm_users: set[int] = set()).

Suggested change
self.notified_dm_log: list[int] = []
self.notified_dm_log: set[int] = set()

Copilot uses AI. Check for mistakes.

# Loads the file config, which includes things like the token
self.load_file_config()
Expand Down Expand Up @@ -265,6 +266,13 @@ async def on_message(self: Self, message: discord.Message) -> None:
and message.author.id != owner.id
and not message.author.bot
):
if message.author.id not in self.notified_dm_log:
self.notified_dm_log.append(message.author.id)
await message.author.send(
"All DMs sent to this bot are permanently logged and not "
"regularly checked. No responses will be given to any messages."
)
Comment on lines +271 to +274
Copy link

Copilot AI Jun 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrap the DM send call in a try/except block (e.g., catching discord.Forbidden) to handle cases where a user has DMs closed and avoid unhandled exceptions halting your event loop.

Suggested change
await message.author.send(
"All DMs sent to this bot are permanently logged and not "
"regularly checked. No responses will be given to any messages."
)
try:
await message.author.send(
"All DMs sent to this bot are permanently logged and not "
"regularly checked. No responses will be given to any messages."
)
except discord.Forbidden as exception:
await self.logger.send_log(
message=f"Could not DM user {message.author} about logging policy",
level=LogLevel.ERROR,
exception=exception,
)

Copilot uses AI. Check for mistakes.

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 ""
Expand Down
Loading