-
-
Notifications
You must be signed in to change notification settings - Fork 41
Bookmarking messages #479
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bookmarking messages #479
Conversation
Reviewer's Guide by SourceryThis pull request implements a new bookmarking feature for the Tux Discord bot. The feature allows users to bookmark messages by reacting with a 🔖 emoji, which then sends the message content and link to the user's DMs. The implementation includes a new Bookmarks cog and updates to the README.md file. File-Level Changes
Tips
|
There was a problem hiding this 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 implementing a rate limit or cooldown mechanism to prevent potential abuse of the bookmarking feature.
- It might be beneficial to add an option for users to disable receiving bookmark messages in their DMs if they prefer not to use this feature.
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
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.
tux/cogs/services/bookmarks.py
Outdated
| await user.send( | ||
| f"Bookmarked: {message_link}\nAuthor: {author_username}\nContent: {message_contents}", | ||
| ) | ||
| except (discord.Forbidden, discord.HTTPException): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Provide feedback to the user on bookmark failure
When an error occurs during bookmarking, the user is not notified. Consider adding a way to inform the user about the failure, perhaps by reacting to the message with an error emoji.
| except (discord.Forbidden, discord.HTTPException): | |
| except (discord.Forbidden, discord.HTTPException): | |
| logger.error(f"An error occurred while bookmarking {message_link} for {user}") | |
| await message.add_reaction('❌') | |
| return |
tux/cogs/services/bookmarks.py
Outdated
| message_contents = reaction.message.content | ||
| message_attachments = reaction.message.attachments | ||
| author_username = reaction.message.author.name | ||
| try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Extract message construction logic into a separate method
The logic for constructing the bookmark message could be extracted into a separate method. This would improve readability and make the code more maintainable.
try:
bookmark_message = self.construct_bookmark_message(reaction.message)
tux/cogs/services/bookmarks.py
Outdated
| @commands.Cog.listener() | ||
| async def on_reaction_add(self, reaction: discord.Reaction, user: discord.User) -> None: | ||
| if str(reaction.emoji) == "🔖": | ||
| message_link = f"https://discord.com/channels/{reaction.message.guild.id}/{reaction.message.channel.id}/{reaction.message.id}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Use Discord's jump_url property instead of constructing the link manually
Instead of manually constructing the message link, consider using Discord's built-in jump_url property. This would be more idiomatic and potentially more robust: message_link = reaction.message.jump_url
| message_link = f"https://discord.com/channels/{reaction.message.guild.id}/{reaction.message.channel.id}/{reaction.message.id}" | |
| message_link = reaction.message.jump_url |
|
forgot to mention this in the origin post but it has some issues with discord's message caching |
|
updated with embeds at @kzndotsh's request should be all good for commit now |
teilorr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on_raw_reaction_add will fix those 'caching' issues
tux/cogs/services/bookmarks.py
Outdated
| message_link = f"https://discord.com/channels/{reaction.message.guild.id}/{reaction.message.channel.id}/{reaction.message.id}" | ||
| message_contents = reaction.message.content | ||
| message_attachments = reaction.message.attachments | ||
| author_username = reaction.message.author.name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary variable
|
shout out to @teilorr for pointing out those fixes and issues |
tux/cogs/services/bookmarks.py
Outdated
| @@ -0,0 +1,56 @@ | |||
| import discord | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this file to the utility cogs dir
tux/cogs/services/bookmarks.py
Outdated
| message_link = message.jump_url | ||
| message_contents = message.content | ||
| message_attachments = message.attachments | ||
| author_username = message.author.name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redundant variables
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ruff is also complaining about typechecking
tux/cogs/services/bookmarks.py
Outdated
| logger.error("Channel not found") | ||
| return | ||
|
|
||
| message = await channel.fetch_message(payload.message_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typechecking warnings
tux/cogs/services/bookmarks.py
Outdated
| embed.add_field(name="Jump to Message", value=f"[Click Here]({message_link})", inline=False) | ||
|
|
||
| if message_attachments: | ||
| attachments_info = "\n".join([attachment.url for attachment in message_attachments]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typechecking errors
tux/cogs/services/bookmarks.py
Outdated
| else: | ||
| logger.error(f"User not found for ID: {payload.user_id}") | ||
| except (discord.Forbidden, discord.HTTPException) as e: | ||
| logger.error(f"An error occurred while bookmarking {message_link} for {payload.user_id}: {e}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add some special handling for if the user has dms off, maybe like react also with like a error dms off emoji or something or send a message in chat for a bit then delete it
Description
Adds Bookmarking to tux whenever you react with 🔖 on a message in a server it gets linked and its contents forwarded to your dms
Type of Change
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 followed all of these guidelines.
How Has This Been Tested? (if applicable)
Please describe how you tested your code. e.g describe what commands you ran, what arguments, and any config stuff (if applicable)
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
Add a new bookmarking feature that enables users to bookmark messages by reacting with a bookmark emoji, sending the message details to their DMs. Update the README to reorganize the contributors section.
New Features:
Enhancements: