Skip to content

Conversation

@Atmois
Copy link
Contributor

@Atmois Atmois commented Sep 8, 2024

Description

Fixes a regression making reports non-anonymous aswell as now creates a thread for each post.

Guidelines

  • My code follows the style guidelines of this project (formatted with Ruff)

  • I have performed a self-review of my own code

  • I have commented my code, particularly in hard-to-understand areas

  • I have made corresponding changes to the documentation if needed

  • My changes generate no new warnings

  • I have tested this change

  • Any dependent changes have been merged and published in downstream modules

  • I have added all appropriate labels to this PR

  • I have followed all of these guidelines.

How Has This Been Tested? (if applicable)

n/a

Screenshots (if applicable)

image

Additional Information

n/a

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Sep 8, 2024

Reviewer's Guide by Sourcery

This pull request improves the reporting system by fixing a regression that made reports non-anonymous and introduces a new feature to create a thread for each report. The changes are implemented in the tux/ui/modals/report.py file, focusing on the on_submit method of a report modal.

File-Level Changes

Change Details Files
Restore anonymity to reports
  • Remove user's name and avatar from the report embed
  • Set a fixed 'tux' username for all reports
tux/ui/modals/report.py
Create a thread for each report
  • Store the sent message in a variable
  • Create a new thread using the sent message
  • Set thread name to match the report title
  • Configure thread to auto-archive after 7 days (10080 minutes)
tux/ui/modals/report.py

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @Atmois - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Please correct the spelling in the PR title from 'Reportimprovment' to 'Report Improvement'.
  • Provide more detailed information on how you tested the anonymity fix and thread creation feature.
  • Consider using a constant or configuration value instead of hardcoding 'tux' as the anonymous username.
Here's what I looked at during the review
  • 🟡 General issues: 3 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

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",

await report_log_channel.create_thread(
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,
        )


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

@Atmois Atmois changed the title Reportimprovment Fix report regression & add threads to each report Sep 8, 2024
@kzndotsh kzndotsh merged commit bd2360d into main Sep 10, 2024
@kzndotsh kzndotsh deleted the reportimprovment branch September 10, 2024 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants