Skip to content
Merged
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
10 changes: 7 additions & 3 deletions tux/ui/modals/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ async def on_submit(self, interaction: discord.Interaction) -> None:
embed = EmbedCreator.create_embed(
bot=self.bot,
embed_type=EmbedCreator.INFO,
user_name=interaction.user.name,
user_display_avatar=interaction.user.display_avatar.url,
user_name="tux",
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Consider using a more generic term for anonymous reports

Instead of hardcoding "tux" as the user name for anonymous reports, consider using a more neutral term like "Anonymous" or "System". This would make the purpose of the change clearer and avoid potential confusion.

Suggested change
user_name="tux",
user_name="Anonymous",

title=(f"Anonymous report for {self.short.value}"), # type: ignore
description=self.long.value, # type: ignore
)
Expand Down Expand Up @@ -89,4 +88,9 @@ async def on_submit(self, interaction: discord.Interaction) -> None:
delete_after=30,
)

await report_log_channel.send(embed=embed)
message = await report_log_channel.send(embed=embed)
await report_log_channel.create_thread(
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Add error handling for thread creation

Consider adding a try-except block around the thread creation to handle potential errors, especially since this is an asynchronous operation. This would improve the robustness of the code.

try:
    await report_log_channel.create_thread(
        name=f"Anonymous report for {self.short.value}",  # type: ignore
        message=message,
    )
except discord.HTTPException as e:
    logging.error(f"Failed to create thread: {e}")
    # Handle the error appropriately, e.g., send a message to a backup channel

name=f"Anonymous report for {self.short.value}", # type: ignore
message=message,
auto_archive_duration=10080,
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Extract magic number to a named constant or configuration value

The value 10080 for auto_archive_duration is a magic number. Consider extracting this to a named constant or configuration value for better maintainability and clarity.

AUTO_ARCHIVE_DURATION = 10080  # 7 days in minutes

class ReportModal(discord.ui.Modal):
    # ... existing code ...

    async def on_submit(self, interaction: discord.Interaction) -> None:
        # ... existing code ...
        await report_log_channel.create_thread(
            name=f"Anonymous report for {self.short.value}",  # type: ignore
            message=message,
            auto_archive_duration=AUTO_ARCHIVE_DURATION,
        )

)