Skip to content

Conversation

@meatsnails
Copy link
Collaborator

@meatsnails meatsnails commented Aug 28, 2024

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Other: (write here)

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)

image

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:

  • Introduce a bookmarking feature that allows users to bookmark messages by reacting with a bookmark emoji, which sends the message link and content to the user's direct messages.

Enhancements:

  • Reorganize the contributors section in the README file to update the order and presentation of contributors.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Aug 28, 2024

Reviewer's Guide by Sourcery

This 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

Change Details Files
Implement bookmarking functionality
  • Create a new Bookmarks cog
  • Add an event listener for reaction additions
  • Check for the 🔖 emoji reaction
  • Generate a message link for the bookmarked message
  • Send bookmarked message content, author, and link to user's DMs
  • Include attachment URLs if present in the bookmarked message
  • Handle potential errors when sending DMs
  • Set up the Bookmarks cog to be added to the bot
tux/cogs/services/bookmarks.py
Update README.md contributors section
  • Rearrange contributor entries
  • Remove some contributor entries
  • Add new contributor entries
README.md

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

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.

await user.send(
f"Bookmarked: {message_link}\nAuthor: {author_username}\nContent: {message_contents}",
)
except (discord.Forbidden, discord.HTTPException):
Copy link
Contributor

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.

Suggested change
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

message_contents = reaction.message.content
message_attachments = reaction.message.attachments
author_username = reaction.message.author.name
try:
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 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)

@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}"
Copy link
Contributor

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

Suggested change
message_link = f"https://discord.com/channels/{reaction.message.guild.id}/{reaction.message.channel.id}/{reaction.message.id}"
message_link = reaction.message.jump_url

@meatsnails
Copy link
Collaborator Author

forgot to mention this in the origin post but it has some issues with discord's message caching

@meatsnails
Copy link
Collaborator Author

updated with embeds at @kzndotsh's request should be all good for commit now

Copy link
Contributor

@teilorr teilorr left a 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

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
Copy link
Contributor

Choose a reason for hiding this comment

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

unnecessary variable

@meatsnails
Copy link
Collaborator Author

shout out to @teilorr for pointing out those fixes and issues

@@ -0,0 +1,56 @@
import discord
Copy link
Member

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

message_link = message.jump_url
message_contents = message.content
message_attachments = message.attachments
author_username = message.author.name
Copy link
Member

Choose a reason for hiding this comment

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

redundant variables

Copy link
Member

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

logger.error("Channel not found")
return

message = await channel.fetch_message(payload.message_id)
Copy link
Member

Choose a reason for hiding this comment

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

typechecking warnings

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])
Copy link
Member

Choose a reason for hiding this comment

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

typechecking errors

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}")
Copy link
Member

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

@meatsnails meatsnails closed this Aug 29, 2024
@meatsnails meatsnails mentioned this pull request Aug 29, 2024
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.

4 participants