Skip to content

Conversation

@electron271
Copy link
Member

@electron271 electron271 commented Apr 9, 2025

Description

add snippet alias support by creating a snippet with the content being the name of another snippet and refactor some stuff

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)

tested in dev tux instance

Screenshots (if applicable)

Please add screenshots to help explain your changes.

Additional Information

Please add any other information that is important to this PR.

Summary by Sourcery

Enhance snippet functionality by adding alias support and refactoring permission checks for snippet management

New Features:

  • Add support for snippet aliases, allowing users to create snippets that reference other existing snippets
  • Implement automatic alias creation when a snippet's content matches an existing snippet name

Enhancements:

  • Refactor permission checks for snippet operations to use a centralized snippet_check method
  • Simplify snippet management logic by consolidating permission and validation checks
  • Remove separate force delete snippet command in favor of a more flexible permission system

Chores:

  • Clean up and remove redundant code related to snippet permission checks
  • Improve logging for snippet operations

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Apr 9, 2025

Reviewer's Guide by Sourcery

This pull request introduces snippet alias support and refactors permission checks for snippet management commands. It also improves error handling and user feedback. Snippet aliases allow users to create snippets that point to other snippets, simplifying snippet management and reducing redundancy. The permission check refactoring consolidates all permission checks into a single function, improving code maintainability and reducing code duplication.

No diagrams generated as the changes look simple and do not need a visual representation.

File-Level Changes

Change Details Files
Introduced snippet alias functionality, allowing snippets to act as pointers to other snippets.
  • Added an alias field to the Snippet model in the database schema.
  • Modified the create_snippet command to check if the content matches an existing snippet name, and if so, create an alias instead of a regular snippet.
  • Updated the get_snippet command to resolve aliases and return the content of the aliased snippet.
  • Added create_snippet_alias to create snippet aliases in the database.
tux/cogs/utility/snippets.py
tux/database/controllers/snippet.py
prisma/schema/commands/snippets.prisma
Refactored permission checks for snippet management commands into a single, reusable function.
  • Created a snippet_check function to encapsulate all permission checks, including mod overrides, ban status, role permissions, lock status, and ownership.
  • Replaced individual permission checks in delete_snippet and edit_snippet with calls to the new snippet_check function.
  • Removed the force_delete_snippet command, as the snippet_check function now handles mod overrides.
  • Removed duplicate permission checks in create_snippet.
tux/cogs/utility/snippets.py
Improved error handling and user feedback for snippet-related operations.
  • Added a send_snippet_error function to send consistent error messages to the user.
  • Improved error messages for various scenarios, such as snippet not found, permission denied, and invalid alias.
  • Added logging for snippet creation, deletion, and editing events.
tux/cogs/utility/snippets.py
Improved the topsnippets command.
  • Added formatting to the output of the topsnippets command.
  • Removed unnecessary checks in the topsnippets command.
tux/cogs/utility/snippets.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@electron271 electron271 requested a review from Copilot April 9, 2025 05:34
@electron271 electron271 self-assigned this Apr 9, 2025
@electron271 electron271 added category: commands category: meta Relating to architecture, systems and critical functions type: enhancement priority: high labels Apr 9, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.

Files not reviewed (1)
  • prisma/schema/commands/snippets.prisma: Language not supported

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 @electron271 - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider extracting the permission check logic into a decorator to reduce code duplication.
  • The snippet alias functionality is a nice addition, but ensure that there are no potential infinite recursion issues.
Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 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 and I'll use the feedback to improve your reviews.

@electron271 electron271 merged commit 604c0db into main Apr 9, 2025
7 of 9 checks passed
@electron271 electron271 deleted the snippetaliases branch April 9, 2025 05:39
@sentry
Copy link

sentry bot commented Apr 9, 2025

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ PermissionLevelError: Missing required permission: Junior Mod or higher tux.utils.checks in predicate View Issue

Did you find this useful? React with a 👍 or 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: commands category: meta Relating to architecture, systems and critical functions priority: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants