Skip to content

Conversation

@meatsnails
Copy link
Collaborator

@meatsnails meatsnails commented Aug 21, 2024

image

Summary by Sourcery

Enhance the snippet editing functionality by showing the previous content alongside the new content in the confirmation message when a snippet is edited.

Enhancements:

  • Display the previous content of a snippet alongside the new content when a snippet is edited.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Aug 21, 2024

Reviewer's Guide by Sourcery

This pull request enhances the snippet editing functionality by adding a before and after comparison when a snippet is edited. The changes are implemented in the edit_snippet method of the snippets cog.

File-Level Changes

Files Changes
tux/cogs/utility/snippets.py Added retrieval of the previous snippet content before editing
tux/cogs/utility/snippets.py Modified the success message to include both the previous and new content of the edited snippet
tux/cogs/utility/snippets.py Removed unnecessary comments about indentation

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

Overall Comments:

  • Consider optimizing by using the result of the first database query instead of querying twice for the same snippet.
  • For longer snippets, consider truncating the content displayed in the confirmation message to avoid potentially lengthy outputs.
Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟡 Security: 1 issue found
  • 🟢 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.

return

name = args[0]
snippet = await self.db.get_snippet_by_name_and_guild_id(name, ctx.guild.id)
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (performance): Consider retrieving the snippet once to improve performance

The snippet is currently retrieved twice from the database. Consider retrieving it once at the beginning of the function and using it for all subsequent operations. This would improve performance while maintaining code clarity.

Suggested change
snippet = await self.db.get_snippet_by_name_and_guild_id(name, ctx.guild.id)
snippet = await self.db.get_snippet_by_name_and_guild_id(name, ctx.guild.id)
if snippet:
previous_content = snippet.snippet_content
content = " ".join(args[1:])

await ctx.send("Snippet Edited.", delete_after=30, ephemeral=True) # Correct indentation
logger.info(f"{ctx.author} Edited a snippet with the name {name} and content {content}.") # Correct indentation
await ctx.send(f"Snippet Edited. {previous_content} -> {content}", delete_after=30, ephemeral=True)
logger.info(f"{ctx.author} Edited a snippet with the name {name} and content {content}.")
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Include previous content in log message for better auditing

For improved auditing, consider including both the previous and new content in the log message. This would provide a more complete record of the changes made to snippets.

Suggested change
logger.info(f"{ctx.author} Edited a snippet with the name {name} and content {content}.")
logger.info(f"{ctx.author} Edited snippet '{name}'. Old content: '{previous_content}', New content: '{content}'")


await ctx.send("Snippet Edited.", delete_after=30, ephemeral=True) # Correct indentation
logger.info(f"{ctx.author} Edited a snippet with the name {name} and content {content}.") # Correct indentation
await ctx.send(f"Snippet Edited. {previous_content} -> {content}", delete_after=30, ephemeral=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

🚨 suggestion (security): Consider the security implications of displaying full snippet content

While showing the previous and new content is informative, it could potentially expose sensitive information. Consider using a more generic message or truncating the content if it's too long to balance informativeness with security concerns.

Suggested change
await ctx.send(f"Snippet Edited. {previous_content} -> {content}", delete_after=30, ephemeral=True)
truncated_prev = (previous_content[:50] + '...') if len(previous_content) > 50 else previous_content
truncated_new = (content[:50] + '...') if len(content) > 50 else content
await ctx.send(f"Snippet Edited. '{truncated_prev}' -> '{truncated_new}'", delete_after=30, ephemeral=True)

@meatsnails
Copy link
Collaborator Author

i'll be changing this to embeds later on but currently this is what i doing for now

Copy link
Member

@electron271 electron271 left a comment

Choose a reason for hiding this comment

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

very spammy with large snippets, at least truncate each to 50 chars

@meatsnails
Copy link
Collaborator Author

very spammy with large snippets, at least truncate each to 50 chars

added that for now

@meatsnails
Copy link
Collaborator Author

very spammy with large snippets, at least truncate each to 50 chars

added that for now

as kaizen said ill prob add buttons to view the before and after once i get to adding embeding

@meatsnails meatsnails requested a review from electron271 August 21, 2024 22:17
@meatsnails meatsnails changed the title added simple little before and after when editing a snippet added simple little before and after when editing a snippet (unfinished) Aug 22, 2024
Copy link
Member

@electron271 electron271 left a comment

Choose a reason for hiding this comment

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

is this ready for merge?

@meatsnails
Copy link
Collaborator Author

kaizen wants me to add an embed and buttons for viewing the before and after before merging it so i marked it as unfinished

@electron271
Copy link
Member

ok

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.

2 participants