From 700bb40c49c380bd8bcfcac8e8449f229d8bf56e Mon Sep 17 00:00:00 2001 From: TargzBalls <102343489+targzballs@users.noreply.github.com> Date: Thu, 29 Aug 2024 00:34:17 -0500 Subject: [PATCH 01/37] Create bookmarks.py --- cogs/utility/bookmarks.py | 56 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 cogs/utility/bookmarks.py diff --git a/cogs/utility/bookmarks.py b/cogs/utility/bookmarks.py new file mode 100644 index 000000000..38ef58b37 --- /dev/null +++ b/cogs/utility/bookmarks.py @@ -0,0 +1,56 @@ +import discord +from discord.ext import commands +from loguru import logger + +from tux.utils.embeds import EmbedCreator + + +class Bookmarks(commands.Cog): + def __init__(self, bot: commands.Bot) -> None: + self.bot = bot + + @commands.Cog.listener() + async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> None: + if str(payload.emoji) == "🔖": + try: + channel = self.bot.get_channel(payload.channel_id) + if channel is None: + logger.error("Channel not found") + return + + message = await channel.fetch_message(payload.message_id) + if message is None: + logger.error("Message not found") + return + + embed = EmbedCreator.create_info_embed( + title="Message Bookmarked", + description=f"> {message.content}", + ) + embed.add_field(name="Author", value=message.author.name, inline=False) + embed.add_field(name="Jump to Message", value=f"[Click Here]({message.jump_url})", inline=False) + + if message.attachments: + attachments_info = "\n".join([attachment.url for attachment in message.attachments]) + embed.add_field(name="Attachments", value=attachments_info, inline=False) + + try: + user = self.bot.get_user(payload.user_id) + if user is not None: + await user.send(embed=embed) + await message.remove_reaction(payload.emoji, user) + else: + logger.error(f"User not found for ID: {payload.user_id}") + except (discord.Forbidden, discord.HTTPException): + logger.error(f"Cannot send a DM to {user.name}. They may have DMs turned off.") + await message.remove_reaction(payload.emoji, user) + temp_message = await channel.send( + f"{user.mention}, I couldn't send you a DM make sure your DMs are open for bookmarks to work", + ) + await temp_message.delete(delay=30) + except (discord.NotFound, discord.Forbidden, discord.HTTPException) as e: + logger.error(f"Failed to process the reaction: {e}") + + +async def setup(bot: commands.Bot) -> None: + await bot.add_cog(Bookmarks(bot)) From b9c797a7f2a45f96f92a1f876ea7b75835917b5c Mon Sep 17 00:00:00 2001 From: cherryl1k <102343489+cherryl1k@users.noreply.github.com> Date: Mon, 9 Jun 2025 18:48:53 -0500 Subject: [PATCH 02/37] wip changes --- config/settings.yml.example | 8 ++++++ tux/cogs/services/bookmarks.py | 46 ++++++++++++++++++++++++++-------- tux/utils/config.py | 4 +++ 3 files changed, 47 insertions(+), 11 deletions(-) diff --git a/config/settings.yml.example b/config/settings.yml.example index 8857e7814..b56c30f9c 100644 --- a/config/settings.yml.example +++ b/config/settings.yml.example @@ -97,3 +97,11 @@ GIF_LIMITER: # Limits the amount of gifs a user can send in a channel "123456789012345": 2 GIF_LIMITS_CHANNEL: "123456789012345": 3 + +BOOKMARK_EMOJIS: + ADD_BOOKMARK: # Unicode Emojis or Custom Server Emoji IDs + - "🔖" + # Custom Emoji example + # - 1274504955163709525 + REMOVE_BOOKMARK: # Unicode Emojis or Custom Server Emoji IDs (not reccomended) + - "🗑️" diff --git a/tux/cogs/services/bookmarks.py b/tux/cogs/services/bookmarks.py index fdedf2c7c..6d9e8102c 100644 --- a/tux/cogs/services/bookmarks.py +++ b/tux/cogs/services/bookmarks.py @@ -6,6 +6,7 @@ from tux.bot import Tux from tux.ui.embeds import EmbedCreator +from tux.utils.config import CONFIG from tux.utils.constants import CONST @@ -13,6 +14,16 @@ class Bookmarks(commands.Cog): def __init__(self, bot: Tux) -> None: self.bot = bot + self.valid_emojis: list[int | str] = CONFIG.ADD_BOOKMARK + CONFIG.REMOVE_BOOKMARK + self.valid_add_emojis: list[int | str] = CONFIG.ADD_BOOKMARK + self.valid_remove_emojis: list[int | str] = CONFIG.REMOVE_BOOKMARK + + def _is_valid_emoji(self, emoji: discord.PartialEmoji, valid_list: list[int | str]) -> bool: + # Helper for checking if an emoji is in the list in "settings.yml -> BOOKMARK_EMOJIS" + if emoji.id is not None: + return emoji.id in valid_list + return emoji.name in valid_list + @commands.Cog.listener() async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> None: """ @@ -27,8 +38,13 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> ------- None """ + if not self._is_valid_emoji(payload.emoji, self.valid_emojis): + return - if str(payload.emoji) != "🔖": + # Get the user who reacted to the message + user = self.bot.get_user(payload.user_id) + if user is None: + logger.error(f"User not found for ID: {payload.user_id}") return # Fetch the channel where the reaction was added @@ -48,19 +64,21 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> logger.error(f"Failed to fetch message: {fetch_error}") return - # Create an embed for the bookmarked message - embed = self._create_bookmark_embed(message) + # check for what to do + if self._is_valid_emoji(payload.emoji, self.valid_add_emojis): + # Create an embed for the bookmarked message + embed = await self._create_bookmark_embed(message) - # Get the user who reacted to the message - user = self.bot.get_user(payload.user_id) - if user is None: - logger.error(f"User not found for ID: {payload.user_id}") - return + # Send the bookmarked message to the user + await self._send_bookmark(user, message, embed, payload.emoji) - # Send the bookmarked message to the user - await self._send_bookmark(user, message, embed, payload.emoji) + elif self._is_valid_emoji(payload.emoji, self.valid_remove_emojis): + await self._delete_bookmark(message, user) + else: + logger.debug("Somehow you managed to get bast the first valid emoji check then failed the 2nd good job?") + return - def _create_bookmark_embed( + async def _create_bookmark_embed( self, message: discord.Message, ) -> discord.Embed: @@ -84,6 +102,12 @@ def _create_bookmark_embed( return embed + async def _delete_bookmark(self, message: discord.Message, user: discord.User) -> None: + logger.debug("you got to the delte function") + if message.author is not self.bot.user: + logger.debug("not tux message") + return + @staticmethod async def _send_bookmark( user: discord.User, diff --git a/tux/utils/config.py b/tux/utils/config.py index 8eaed2e6e..97a59b6b9 100644 --- a/tux/utils/config.py +++ b/tux/utils/config.py @@ -135,5 +135,9 @@ def BOT_TOKEN(self) -> str: # noqa: N802 LIMIT_TO_ROLE_IDS: Final[bool] = config["SNIPPETS"]["LIMIT_TO_ROLE_IDS"] ACCESS_ROLE_IDS: Final[list[int]] = config["SNIPPETS"]["ACCESS_ROLE_IDS"] + # Bookmark reactions + ADD_BOOKMARK: Final[list[int | str]] = config["BOOKMARK_EMOJIS"]["ADD_BOOKMARK"] + REMOVE_BOOKMARK: Final[list[int | str]] = config["BOOKMARK_EMOJIS"]["REMOVE_BOOKMARK"] + CONFIG = Config() From 56bebaf4831d5e7c2067a162df740192f654229d Mon Sep 17 00:00:00 2001 From: cherryl1k <102343489+cherryl1k@users.noreply.github.com> Date: Thu, 19 Jun 2025 12:33:27 -0500 Subject: [PATCH 03/37] Added removing bookmarks from the bot's DMs --- tux/cogs/services/bookmarks.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tux/cogs/services/bookmarks.py b/tux/cogs/services/bookmarks.py index 6d9e8102c..44a726ee5 100644 --- a/tux/cogs/services/bookmarks.py +++ b/tux/cogs/services/bookmarks.py @@ -75,7 +75,7 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> elif self._is_valid_emoji(payload.emoji, self.valid_remove_emojis): await self._delete_bookmark(message, user) else: - logger.debug("Somehow you managed to get bast the first valid emoji check then failed the 2nd good job?") + logger.error("How did you fail the 2nd check but passed the first?") return async def _create_bookmark_embed( @@ -103,10 +103,9 @@ async def _create_bookmark_embed( return embed async def _delete_bookmark(self, message: discord.Message, user: discord.User) -> None: - logger.debug("you got to the delte function") if message.author is not self.bot.user: - logger.debug("not tux message") return + await message.delete() @staticmethod async def _send_bookmark( From 217c36411165508c33743cfcadc97c3ba3e56b5b Mon Sep 17 00:00:00 2001 From: electron271 <66094410+electron271@users.noreply.github.com> Date: Thu, 19 Jun 2025 14:08:52 -0500 Subject: [PATCH 04/37] fix(bookmarks): improve emoji validation and error handling for user and channel fetching --- config/settings.yml.example | 7 +++---- tux/cogs/services/bookmarks.py | 34 ++++++++++++++++++++++++++-------- tux/cogs/utility/poll.py | 18 +++++++++++------- 3 files changed, 40 insertions(+), 19 deletions(-) diff --git a/config/settings.yml.example b/config/settings.yml.example index 719032fa6..4433f9eb7 100644 --- a/config/settings.yml.example +++ b/config/settings.yml.example @@ -116,9 +116,8 @@ GIF_LIMITER: # Limits the amount of gifs a user can send in a channel "123456789012345": 3 BOOKMARK_EMOJIS: - ADD_BOOKMARK: # Unicode Emojis or Custom Server Emoji IDs + ADD_BOOKMARK: - "🔖" - # Custom Emoji example - # - 1274504955163709525 - REMOVE_BOOKMARK: # Unicode Emojis or Custom Server Emoji IDs (not reccomended) + #- 123456789012345 # Custom emoji example, replace with emoji id + REMOVE_BOOKMARK: # Do not use custom emojis for this. - "🗑️" diff --git a/tux/cogs/services/bookmarks.py b/tux/cogs/services/bookmarks.py index 44a726ee5..4b958cea9 100644 --- a/tux/cogs/services/bookmarks.py +++ b/tux/cogs/services/bookmarks.py @@ -20,9 +20,7 @@ def __init__(self, bot: Tux) -> None: def _is_valid_emoji(self, emoji: discord.PartialEmoji, valid_list: list[int | str]) -> bool: # Helper for checking if an emoji is in the list in "settings.yml -> BOOKMARK_EMOJIS" - if emoji.id is not None: - return emoji.id in valid_list - return emoji.name in valid_list + return emoji.name in valid_list if emoji.id is None else emoji.id in valid_list @commands.Cog.listener() async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> None: @@ -44,14 +42,26 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> # Get the user who reacted to the message user = self.bot.get_user(payload.user_id) if user is None: - logger.error(f"User not found for ID: {payload.user_id}") - return + try: + user = await self.bot.fetch_user(payload.user_id) + except discord.NotFound: + logger.error(f"User not found for ID: {payload.user_id}") + return + except (discord.Forbidden, discord.HTTPException) as fetch_error: + logger.error(f"Failed to fetch user: {fetch_error}") + return # Fetch the channel where the reaction was added channel = self.bot.get_channel(payload.channel_id) if channel is None: - logger.error(f"Channel not found for ID: {payload.channel_id}") - return + try: + channel = await self.bot.fetch_channel(payload.channel_id) + except discord.NotFound: + logger.error(f"Channel not found for ID: {payload.channel_id}") + return + except (discord.Forbidden, discord.HTTPException) as fetch_error: + logger.error(f"Failed to fetch channel: {fetch_error}") + return channel = cast(discord.TextChannel | discord.Thread, channel) # Fetch the message that was reacted to @@ -75,7 +85,9 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> elif self._is_valid_emoji(payload.emoji, self.valid_remove_emojis): await self._delete_bookmark(message, user) else: - logger.error("How did you fail the 2nd check but passed the first?") + logger.error( + "First emoji validation check passed but second emoji validation check failed. How the fuck did you get here?", + ) return async def _create_bookmark_embed( @@ -96,6 +108,12 @@ async def _create_bookmark_embed( embed.add_field(name="Jump to Message", value=f"[Click Here]({message.jump_url})", inline=False) + embed.add_field( + name="Delete Bookmark", + value=f"React with {CONFIG.REMOVE_BOOKMARK[0]} to delete this bookmark.", + inline=False, + ) + if message.attachments: attachments_info = "\n".join([attachment.url for attachment in message.attachments]) embed.add_field(name="Attachments", value=attachments_info, inline=False) diff --git a/tux/cogs/utility/poll.py b/tux/cogs/utility/poll.py index fb75a2982..0affb1565 100644 --- a/tux/cogs/utility/poll.py +++ b/tux/cogs/utility/poll.py @@ -1,3 +1,5 @@ +from typing import cast + import discord from discord import app_commands from discord.ext import commands @@ -74,13 +76,15 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> # get reaction from payload.message_id, payload.channel_id, payload.guild_id, payload.emoji channel = self.bot.get_channel(payload.channel_id) if channel is None: - logger.error(f"Channel with ID {payload.channel_id} not found.") - return - if isinstance(channel, discord.ForumChannel | discord.CategoryChannel | discord.abc.PrivateChannel): - logger.error( - f"Channel with ID {payload.channel_id} is not a compatible channel type. How the fuck did you get here?", - ) - return + try: + channel = await self.bot.fetch_channel(payload.channel_id) + except discord.NotFound: + logger.error(f"Channel not found for ID: {payload.channel_id}") + return + except (discord.Forbidden, discord.HTTPException) as fetch_error: + logger.error(f"Failed to fetch channel: {fetch_error}") + return + channel = cast(discord.TextChannel | discord.Thread, channel) message = await channel.fetch_message(payload.message_id) # Lookup the reaction object for this event From b8a4072005a1f22efa7ec8d40dc468bd9051e2e1 Mon Sep 17 00:00:00 2001 From: cherryl1k <102343489+cherryl1k@users.noreply.github.com> Date: Thu, 19 Jun 2025 14:32:38 -0500 Subject: [PATCH 05/37] added eletrons changes and fixed a warning --- config/settings.yml.example | 7 +++---- tux/cogs/services/bookmarks.py | 30 +++++++++++++++++++++++------- tux/cogs/utility/poll.py | 18 +++++++++++------- 3 files changed, 37 insertions(+), 18 deletions(-) diff --git a/config/settings.yml.example b/config/settings.yml.example index 719032fa6..4433f9eb7 100644 --- a/config/settings.yml.example +++ b/config/settings.yml.example @@ -116,9 +116,8 @@ GIF_LIMITER: # Limits the amount of gifs a user can send in a channel "123456789012345": 3 BOOKMARK_EMOJIS: - ADD_BOOKMARK: # Unicode Emojis or Custom Server Emoji IDs + ADD_BOOKMARK: - "🔖" - # Custom Emoji example - # - 1274504955163709525 - REMOVE_BOOKMARK: # Unicode Emojis or Custom Server Emoji IDs (not reccomended) + #- 123456789012345 # Custom emoji example, replace with emoji id + REMOVE_BOOKMARK: # Do not use custom emojis for this. - "🗑️" diff --git a/tux/cogs/services/bookmarks.py b/tux/cogs/services/bookmarks.py index 44a726ee5..1fd1b7762 100644 --- a/tux/cogs/services/bookmarks.py +++ b/tux/cogs/services/bookmarks.py @@ -20,9 +20,7 @@ def __init__(self, bot: Tux) -> None: def _is_valid_emoji(self, emoji: discord.PartialEmoji, valid_list: list[int | str]) -> bool: # Helper for checking if an emoji is in the list in "settings.yml -> BOOKMARK_EMOJIS" - if emoji.id is not None: - return emoji.id in valid_list - return emoji.name in valid_list + return emoji.name in valid_list if emoji.id is None else emoji.id in valid_list @commands.Cog.listener() async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> None: @@ -44,14 +42,24 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> # Get the user who reacted to the message user = self.bot.get_user(payload.user_id) if user is None: - logger.error(f"User not found for ID: {payload.user_id}") + try: + user = await self.bot.fetch_user(payload.user_id) + except discord.NotFound: + logger.error(f"User not found for ID: {payload.user_id}") + except (discord.Forbidden, discord.HTTPException) as fetch_error: + logger.error(f"Failed to fetch user: {fetch_error}") return - # Fetch the channel where the reaction was added channel = self.bot.get_channel(payload.channel_id) if channel is None: - logger.error(f"Channel not found for ID: {payload.channel_id}") + try: + channel = await self.bot.fetch_channel(payload.channel_id) + except discord.NotFound: + logger.error(f"Channel not found for ID: {payload.channel_id}") + except (discord.Forbidden, discord.HTTPException) as fetch_error: + logger.error(f"Failed to fetch channel: {fetch_error}") return + channel = cast(discord.TextChannel | discord.Thread, channel) # Fetch the message that was reacted to @@ -75,7 +83,9 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> elif self._is_valid_emoji(payload.emoji, self.valid_remove_emojis): await self._delete_bookmark(message, user) else: - logger.error("How did you fail the 2nd check but passed the first?") + logger.error( + "First emoji validation check passed but second emoji validation check failed. How the fuck did you get here?", + ) return async def _create_bookmark_embed( @@ -96,6 +106,12 @@ async def _create_bookmark_embed( embed.add_field(name="Jump to Message", value=f"[Click Here]({message.jump_url})", inline=False) + embed.add_field( + name="Delete Bookmark", + value=f"React with {CONFIG.REMOVE_BOOKMARK[0]} to delete this bookmark.", + inline=False, + ) + if message.attachments: attachments_info = "\n".join([attachment.url for attachment in message.attachments]) embed.add_field(name="Attachments", value=attachments_info, inline=False) diff --git a/tux/cogs/utility/poll.py b/tux/cogs/utility/poll.py index fb75a2982..0affb1565 100644 --- a/tux/cogs/utility/poll.py +++ b/tux/cogs/utility/poll.py @@ -1,3 +1,5 @@ +from typing import cast + import discord from discord import app_commands from discord.ext import commands @@ -74,13 +76,15 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> # get reaction from payload.message_id, payload.channel_id, payload.guild_id, payload.emoji channel = self.bot.get_channel(payload.channel_id) if channel is None: - logger.error(f"Channel with ID {payload.channel_id} not found.") - return - if isinstance(channel, discord.ForumChannel | discord.CategoryChannel | discord.abc.PrivateChannel): - logger.error( - f"Channel with ID {payload.channel_id} is not a compatible channel type. How the fuck did you get here?", - ) - return + try: + channel = await self.bot.fetch_channel(payload.channel_id) + except discord.NotFound: + logger.error(f"Channel not found for ID: {payload.channel_id}") + return + except (discord.Forbidden, discord.HTTPException) as fetch_error: + logger.error(f"Failed to fetch channel: {fetch_error}") + return + channel = cast(discord.TextChannel | discord.Thread, channel) message = await channel.fetch_message(payload.message_id) # Lookup the reaction object for this event From 34798e9edf40de7b223068740a5ea443e6240dae Mon Sep 17 00:00:00 2001 From: cherryl1k <102343489+cherryl1k@users.noreply.github.com> Date: Thu, 19 Jun 2025 14:38:53 -0500 Subject: [PATCH 06/37] i think i fixed whatever the hell git just did --- tux/cogs/services/bookmarks.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/tux/cogs/services/bookmarks.py b/tux/cogs/services/bookmarks.py index 70b0df1fa..1fd1b7762 100644 --- a/tux/cogs/services/bookmarks.py +++ b/tux/cogs/services/bookmarks.py @@ -21,7 +21,6 @@ def __init__(self, bot: Tux) -> None: def _is_valid_emoji(self, emoji: discord.PartialEmoji, valid_list: list[int | str]) -> bool: # Helper for checking if an emoji is in the list in "settings.yml -> BOOKMARK_EMOJIS" return emoji.name in valid_list if emoji.id is None else emoji.id in valid_list - return emoji.name in valid_list if emoji.id is None else emoji.id in valid_list @commands.Cog.listener() async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> None: @@ -84,9 +83,6 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> elif self._is_valid_emoji(payload.emoji, self.valid_remove_emojis): await self._delete_bookmark(message, user) else: - logger.error( - "First emoji validation check passed but second emoji validation check failed. How the fuck did you get here?", - ) logger.error( "First emoji validation check passed but second emoji validation check failed. How the fuck did you get here?", ) @@ -116,12 +112,6 @@ async def _create_bookmark_embed( inline=False, ) - embed.add_field( - name="Delete Bookmark", - value=f"React with {CONFIG.REMOVE_BOOKMARK[0]} to delete this bookmark.", - inline=False, - ) - if message.attachments: attachments_info = "\n".join([attachment.url for attachment in message.attachments]) embed.add_field(name="Attachments", value=attachments_info, inline=False) From ba2c381f135f8e094d5eca0babc195be00d1fe42 Mon Sep 17 00:00:00 2001 From: cherryl1k <102343489+cherryl1k@users.noreply.github.com> Date: Fri, 20 Jun 2025 12:11:09 -0500 Subject: [PATCH 07/37] chore(wip): still working on debugging --- config/settings.yml.example | 7 ------- tux/cogs/services/bookmarks.py | 21 ++++++++------------- tux/utils/config.py | 4 ---- tux/utils/constants.py | 4 ++++ 4 files changed, 12 insertions(+), 24 deletions(-) diff --git a/config/settings.yml.example b/config/settings.yml.example index 4433f9eb7..111ecf375 100644 --- a/config/settings.yml.example +++ b/config/settings.yml.example @@ -114,10 +114,3 @@ GIF_LIMITER: # Limits the amount of gifs a user can send in a channel "123456789012345": 2 GIF_LIMITS_CHANNEL: "123456789012345": 3 - -BOOKMARK_EMOJIS: - ADD_BOOKMARK: - - "🔖" - #- 123456789012345 # Custom emoji example, replace with emoji id - REMOVE_BOOKMARK: # Do not use custom emojis for this. - - "🗑️" diff --git a/tux/cogs/services/bookmarks.py b/tux/cogs/services/bookmarks.py index 1fd1b7762..80c74a04e 100644 --- a/tux/cogs/services/bookmarks.py +++ b/tux/cogs/services/bookmarks.py @@ -6,7 +6,6 @@ from tux.bot import Tux from tux.ui.embeds import EmbedCreator -from tux.utils.config import CONFIG from tux.utils.constants import CONST @@ -14,13 +13,15 @@ class Bookmarks(commands.Cog): def __init__(self, bot: Tux) -> None: self.bot = bot - self.valid_emojis: list[int | str] = CONFIG.ADD_BOOKMARK + CONFIG.REMOVE_BOOKMARK - self.valid_add_emojis: list[int | str] = CONFIG.ADD_BOOKMARK - self.valid_remove_emojis: list[int | str] = CONFIG.REMOVE_BOOKMARK + self.valid_add_emojis = CONST.ADD_BOOKMARK + self.valid_remove_emojis = CONST.REMOVE_BOOKMARK + self.valid_emojis = CONST.ADD_BOOKMARK + CONST.REMOVE_BOOKMARK def _is_valid_emoji(self, emoji: discord.PartialEmoji, valid_list: list[int | str]) -> bool: # Helper for checking if an emoji is in the list in "settings.yml -> BOOKMARK_EMOJIS" - return emoji.name in valid_list if emoji.id is None else emoji.id in valid_list + if emoji.id is not None: + return emoji.id in valid_list + return emoji.name in valid_list @commands.Cog.listener() async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> None: @@ -105,13 +106,6 @@ async def _create_bookmark_embed( embed.add_field(name="Author", value=message.author.name, inline=False) embed.add_field(name="Jump to Message", value=f"[Click Here]({message.jump_url})", inline=False) - - embed.add_field( - name="Delete Bookmark", - value=f"React with {CONFIG.REMOVE_BOOKMARK[0]} to delete this bookmark.", - inline=False, - ) - if message.attachments: attachments_info = "\n".join([attachment.url for attachment in message.attachments]) embed.add_field(name="Attachments", value=attachments_info, inline=False) @@ -146,7 +140,8 @@ async def _send_bookmark( """ try: - await user.send(embed=embed) + dm_message = await user.send(embed=embed) + await dm_message.add_reaction(CONST.REMOVE_BOOKMARK) except (discord.Forbidden, discord.HTTPException) as dm_error: logger.error(f"Cannot send a DM to {user.name}: {dm_error}") diff --git a/tux/utils/config.py b/tux/utils/config.py index 2394cee43..dd3cc7fc3 100644 --- a/tux/utils/config.py +++ b/tux/utils/config.py @@ -152,9 +152,5 @@ def BOT_TOKEN(self) -> str: # noqa: N802 LIMIT_TO_ROLE_IDS: Final[bool] = config["SNIPPETS"]["LIMIT_TO_ROLE_IDS"] ACCESS_ROLE_IDS: Final[list[int]] = config["SNIPPETS"]["ACCESS_ROLE_IDS"] - # Bookmark reactions - ADD_BOOKMARK: Final[list[int | str]] = config["BOOKMARK_EMOJIS"]["ADD_BOOKMARK"] - REMOVE_BOOKMARK: Final[list[int | str]] = config["BOOKMARK_EMOJIS"]["REMOVE_BOOKMARK"] - CONFIG = Config() diff --git a/tux/utils/constants.py b/tux/utils/constants.py index 166673c2b..f1f2a94b8 100644 --- a/tux/utils/constants.py +++ b/tux/utils/constants.py @@ -73,5 +73,9 @@ class Constants: EIGHT_BALL_QUESTION_LENGTH_LIMIT = 120 EIGHT_BALL_RESPONSE_WRAP_WIDTH = 30 + # Bookmark constants + ADD_BOOKMARK = "🔖" + REMOVE_BOOKMARK = "🗑️" + CONST = Constants() From 1c5f20e497a85842aa1b3172e9a337bc6a4a737a Mon Sep 17 00:00:00 2001 From: cherryl1k <102343489+cherryl1k@users.noreply.github.com> Date: Mon, 9 Jun 2025 18:48:53 -0500 Subject: [PATCH 08/37] wip changes --- config/settings.yml.example | 8 ++++++ tux/cogs/services/bookmarks.py | 46 ++++++++++++++++++++++++++-------- tux/utils/config.py | 4 +++ 3 files changed, 47 insertions(+), 11 deletions(-) diff --git a/config/settings.yml.example b/config/settings.yml.example index 111ecf375..719032fa6 100644 --- a/config/settings.yml.example +++ b/config/settings.yml.example @@ -114,3 +114,11 @@ GIF_LIMITER: # Limits the amount of gifs a user can send in a channel "123456789012345": 2 GIF_LIMITS_CHANNEL: "123456789012345": 3 + +BOOKMARK_EMOJIS: + ADD_BOOKMARK: # Unicode Emojis or Custom Server Emoji IDs + - "🔖" + # Custom Emoji example + # - 1274504955163709525 + REMOVE_BOOKMARK: # Unicode Emojis or Custom Server Emoji IDs (not reccomended) + - "🗑️" diff --git a/tux/cogs/services/bookmarks.py b/tux/cogs/services/bookmarks.py index fdedf2c7c..6d9e8102c 100644 --- a/tux/cogs/services/bookmarks.py +++ b/tux/cogs/services/bookmarks.py @@ -6,6 +6,7 @@ from tux.bot import Tux from tux.ui.embeds import EmbedCreator +from tux.utils.config import CONFIG from tux.utils.constants import CONST @@ -13,6 +14,16 @@ class Bookmarks(commands.Cog): def __init__(self, bot: Tux) -> None: self.bot = bot + self.valid_emojis: list[int | str] = CONFIG.ADD_BOOKMARK + CONFIG.REMOVE_BOOKMARK + self.valid_add_emojis: list[int | str] = CONFIG.ADD_BOOKMARK + self.valid_remove_emojis: list[int | str] = CONFIG.REMOVE_BOOKMARK + + def _is_valid_emoji(self, emoji: discord.PartialEmoji, valid_list: list[int | str]) -> bool: + # Helper for checking if an emoji is in the list in "settings.yml -> BOOKMARK_EMOJIS" + if emoji.id is not None: + return emoji.id in valid_list + return emoji.name in valid_list + @commands.Cog.listener() async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> None: """ @@ -27,8 +38,13 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> ------- None """ + if not self._is_valid_emoji(payload.emoji, self.valid_emojis): + return - if str(payload.emoji) != "🔖": + # Get the user who reacted to the message + user = self.bot.get_user(payload.user_id) + if user is None: + logger.error(f"User not found for ID: {payload.user_id}") return # Fetch the channel where the reaction was added @@ -48,19 +64,21 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> logger.error(f"Failed to fetch message: {fetch_error}") return - # Create an embed for the bookmarked message - embed = self._create_bookmark_embed(message) + # check for what to do + if self._is_valid_emoji(payload.emoji, self.valid_add_emojis): + # Create an embed for the bookmarked message + embed = await self._create_bookmark_embed(message) - # Get the user who reacted to the message - user = self.bot.get_user(payload.user_id) - if user is None: - logger.error(f"User not found for ID: {payload.user_id}") - return + # Send the bookmarked message to the user + await self._send_bookmark(user, message, embed, payload.emoji) - # Send the bookmarked message to the user - await self._send_bookmark(user, message, embed, payload.emoji) + elif self._is_valid_emoji(payload.emoji, self.valid_remove_emojis): + await self._delete_bookmark(message, user) + else: + logger.debug("Somehow you managed to get bast the first valid emoji check then failed the 2nd good job?") + return - def _create_bookmark_embed( + async def _create_bookmark_embed( self, message: discord.Message, ) -> discord.Embed: @@ -84,6 +102,12 @@ def _create_bookmark_embed( return embed + async def _delete_bookmark(self, message: discord.Message, user: discord.User) -> None: + logger.debug("you got to the delte function") + if message.author is not self.bot.user: + logger.debug("not tux message") + return + @staticmethod async def _send_bookmark( user: discord.User, diff --git a/tux/utils/config.py b/tux/utils/config.py index dd3cc7fc3..2394cee43 100644 --- a/tux/utils/config.py +++ b/tux/utils/config.py @@ -152,5 +152,9 @@ def BOT_TOKEN(self) -> str: # noqa: N802 LIMIT_TO_ROLE_IDS: Final[bool] = config["SNIPPETS"]["LIMIT_TO_ROLE_IDS"] ACCESS_ROLE_IDS: Final[list[int]] = config["SNIPPETS"]["ACCESS_ROLE_IDS"] + # Bookmark reactions + ADD_BOOKMARK: Final[list[int | str]] = config["BOOKMARK_EMOJIS"]["ADD_BOOKMARK"] + REMOVE_BOOKMARK: Final[list[int | str]] = config["BOOKMARK_EMOJIS"]["REMOVE_BOOKMARK"] + CONFIG = Config() From bdb6103acfc26538fea98cf8502caa75981cd5c6 Mon Sep 17 00:00:00 2001 From: cherryl1k <102343489+cherryl1k@users.noreply.github.com> Date: Thu, 19 Jun 2025 12:33:27 -0500 Subject: [PATCH 09/37] Added removing bookmarks from the bot's DMs --- tux/cogs/services/bookmarks.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tux/cogs/services/bookmarks.py b/tux/cogs/services/bookmarks.py index 6d9e8102c..44a726ee5 100644 --- a/tux/cogs/services/bookmarks.py +++ b/tux/cogs/services/bookmarks.py @@ -75,7 +75,7 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> elif self._is_valid_emoji(payload.emoji, self.valid_remove_emojis): await self._delete_bookmark(message, user) else: - logger.debug("Somehow you managed to get bast the first valid emoji check then failed the 2nd good job?") + logger.error("How did you fail the 2nd check but passed the first?") return async def _create_bookmark_embed( @@ -103,10 +103,9 @@ async def _create_bookmark_embed( return embed async def _delete_bookmark(self, message: discord.Message, user: discord.User) -> None: - logger.debug("you got to the delte function") if message.author is not self.bot.user: - logger.debug("not tux message") return + await message.delete() @staticmethod async def _send_bookmark( From 66f4df9bc85ca8da04d38e8f5189422bad01483b Mon Sep 17 00:00:00 2001 From: cherryl1k <102343489+cherryl1k@users.noreply.github.com> Date: Thu, 19 Jun 2025 14:32:38 -0500 Subject: [PATCH 10/37] added eletrons changes and fixed a warning --- config/settings.yml.example | 7 +++---- tux/cogs/services/bookmarks.py | 30 +++++++++++++++++++++++------- tux/cogs/utility/poll.py | 18 +++++++++++------- 3 files changed, 37 insertions(+), 18 deletions(-) diff --git a/config/settings.yml.example b/config/settings.yml.example index 719032fa6..4433f9eb7 100644 --- a/config/settings.yml.example +++ b/config/settings.yml.example @@ -116,9 +116,8 @@ GIF_LIMITER: # Limits the amount of gifs a user can send in a channel "123456789012345": 3 BOOKMARK_EMOJIS: - ADD_BOOKMARK: # Unicode Emojis or Custom Server Emoji IDs + ADD_BOOKMARK: - "🔖" - # Custom Emoji example - # - 1274504955163709525 - REMOVE_BOOKMARK: # Unicode Emojis or Custom Server Emoji IDs (not reccomended) + #- 123456789012345 # Custom emoji example, replace with emoji id + REMOVE_BOOKMARK: # Do not use custom emojis for this. - "🗑️" diff --git a/tux/cogs/services/bookmarks.py b/tux/cogs/services/bookmarks.py index 44a726ee5..1fd1b7762 100644 --- a/tux/cogs/services/bookmarks.py +++ b/tux/cogs/services/bookmarks.py @@ -20,9 +20,7 @@ def __init__(self, bot: Tux) -> None: def _is_valid_emoji(self, emoji: discord.PartialEmoji, valid_list: list[int | str]) -> bool: # Helper for checking if an emoji is in the list in "settings.yml -> BOOKMARK_EMOJIS" - if emoji.id is not None: - return emoji.id in valid_list - return emoji.name in valid_list + return emoji.name in valid_list if emoji.id is None else emoji.id in valid_list @commands.Cog.listener() async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> None: @@ -44,14 +42,24 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> # Get the user who reacted to the message user = self.bot.get_user(payload.user_id) if user is None: - logger.error(f"User not found for ID: {payload.user_id}") + try: + user = await self.bot.fetch_user(payload.user_id) + except discord.NotFound: + logger.error(f"User not found for ID: {payload.user_id}") + except (discord.Forbidden, discord.HTTPException) as fetch_error: + logger.error(f"Failed to fetch user: {fetch_error}") return - # Fetch the channel where the reaction was added channel = self.bot.get_channel(payload.channel_id) if channel is None: - logger.error(f"Channel not found for ID: {payload.channel_id}") + try: + channel = await self.bot.fetch_channel(payload.channel_id) + except discord.NotFound: + logger.error(f"Channel not found for ID: {payload.channel_id}") + except (discord.Forbidden, discord.HTTPException) as fetch_error: + logger.error(f"Failed to fetch channel: {fetch_error}") return + channel = cast(discord.TextChannel | discord.Thread, channel) # Fetch the message that was reacted to @@ -75,7 +83,9 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> elif self._is_valid_emoji(payload.emoji, self.valid_remove_emojis): await self._delete_bookmark(message, user) else: - logger.error("How did you fail the 2nd check but passed the first?") + logger.error( + "First emoji validation check passed but second emoji validation check failed. How the fuck did you get here?", + ) return async def _create_bookmark_embed( @@ -96,6 +106,12 @@ async def _create_bookmark_embed( embed.add_field(name="Jump to Message", value=f"[Click Here]({message.jump_url})", inline=False) + embed.add_field( + name="Delete Bookmark", + value=f"React with {CONFIG.REMOVE_BOOKMARK[0]} to delete this bookmark.", + inline=False, + ) + if message.attachments: attachments_info = "\n".join([attachment.url for attachment in message.attachments]) embed.add_field(name="Attachments", value=attachments_info, inline=False) diff --git a/tux/cogs/utility/poll.py b/tux/cogs/utility/poll.py index fb75a2982..0affb1565 100644 --- a/tux/cogs/utility/poll.py +++ b/tux/cogs/utility/poll.py @@ -1,3 +1,5 @@ +from typing import cast + import discord from discord import app_commands from discord.ext import commands @@ -74,13 +76,15 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> # get reaction from payload.message_id, payload.channel_id, payload.guild_id, payload.emoji channel = self.bot.get_channel(payload.channel_id) if channel is None: - logger.error(f"Channel with ID {payload.channel_id} not found.") - return - if isinstance(channel, discord.ForumChannel | discord.CategoryChannel | discord.abc.PrivateChannel): - logger.error( - f"Channel with ID {payload.channel_id} is not a compatible channel type. How the fuck did you get here?", - ) - return + try: + channel = await self.bot.fetch_channel(payload.channel_id) + except discord.NotFound: + logger.error(f"Channel not found for ID: {payload.channel_id}") + return + except (discord.Forbidden, discord.HTTPException) as fetch_error: + logger.error(f"Failed to fetch channel: {fetch_error}") + return + channel = cast(discord.TextChannel | discord.Thread, channel) message = await channel.fetch_message(payload.message_id) # Lookup the reaction object for this event From b5dcbb7359b49a243ebb97d23bdab21a1e7bb530 Mon Sep 17 00:00:00 2001 From: electron271 <66094410+electron271@users.noreply.github.com> Date: Thu, 19 Jun 2025 14:08:52 -0500 Subject: [PATCH 11/37] fix(bookmarks): improve emoji validation and error handling for user and channel fetching --- tux/cogs/services/bookmarks.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tux/cogs/services/bookmarks.py b/tux/cogs/services/bookmarks.py index 1fd1b7762..f4f59093d 100644 --- a/tux/cogs/services/bookmarks.py +++ b/tux/cogs/services/bookmarks.py @@ -46,9 +46,17 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> user = await self.bot.fetch_user(payload.user_id) except discord.NotFound: logger.error(f"User not found for ID: {payload.user_id}") +<<<<<<< HEAD except (discord.Forbidden, discord.HTTPException) as fetch_error: logger.error(f"Failed to fetch user: {fetch_error}") return +======= + return + except (discord.Forbidden, discord.HTTPException) as fetch_error: + logger.error(f"Failed to fetch user: {fetch_error}") + return + +>>>>>>> 217c364 (fix(bookmarks): improve emoji validation and error handling for user and channel fetching) # Fetch the channel where the reaction was added channel = self.bot.get_channel(payload.channel_id) if channel is None: @@ -56,10 +64,17 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> channel = await self.bot.fetch_channel(payload.channel_id) except discord.NotFound: logger.error(f"Channel not found for ID: {payload.channel_id}") +<<<<<<< HEAD except (discord.Forbidden, discord.HTTPException) as fetch_error: logger.error(f"Failed to fetch channel: {fetch_error}") return +======= + return + except (discord.Forbidden, discord.HTTPException) as fetch_error: + logger.error(f"Failed to fetch channel: {fetch_error}") + return +>>>>>>> 217c364 (fix(bookmarks): improve emoji validation and error handling for user and channel fetching) channel = cast(discord.TextChannel | discord.Thread, channel) # Fetch the message that was reacted to From 2ce131a0bea1d70e247c597b57e19370f2f2db0e Mon Sep 17 00:00:00 2001 From: cherryl1k <102343489+cherryl1k@users.noreply.github.com> Date: Fri, 20 Jun 2025 12:11:09 -0500 Subject: [PATCH 12/37] chore(wip): still working on debugging --- config/settings.yml.example | 7 ------- tux/cogs/services/bookmarks.py | 21 ++++++++------------- tux/utils/config.py | 4 ---- tux/utils/constants.py | 4 ++++ 4 files changed, 12 insertions(+), 24 deletions(-) diff --git a/config/settings.yml.example b/config/settings.yml.example index 4433f9eb7..111ecf375 100644 --- a/config/settings.yml.example +++ b/config/settings.yml.example @@ -114,10 +114,3 @@ GIF_LIMITER: # Limits the amount of gifs a user can send in a channel "123456789012345": 2 GIF_LIMITS_CHANNEL: "123456789012345": 3 - -BOOKMARK_EMOJIS: - ADD_BOOKMARK: - - "🔖" - #- 123456789012345 # Custom emoji example, replace with emoji id - REMOVE_BOOKMARK: # Do not use custom emojis for this. - - "🗑️" diff --git a/tux/cogs/services/bookmarks.py b/tux/cogs/services/bookmarks.py index f4f59093d..35f8b9f1d 100644 --- a/tux/cogs/services/bookmarks.py +++ b/tux/cogs/services/bookmarks.py @@ -6,7 +6,6 @@ from tux.bot import Tux from tux.ui.embeds import EmbedCreator -from tux.utils.config import CONFIG from tux.utils.constants import CONST @@ -14,13 +13,15 @@ class Bookmarks(commands.Cog): def __init__(self, bot: Tux) -> None: self.bot = bot - self.valid_emojis: list[int | str] = CONFIG.ADD_BOOKMARK + CONFIG.REMOVE_BOOKMARK - self.valid_add_emojis: list[int | str] = CONFIG.ADD_BOOKMARK - self.valid_remove_emojis: list[int | str] = CONFIG.REMOVE_BOOKMARK + self.valid_add_emojis = CONST.ADD_BOOKMARK + self.valid_remove_emojis = CONST.REMOVE_BOOKMARK + self.valid_emojis = CONST.ADD_BOOKMARK + CONST.REMOVE_BOOKMARK def _is_valid_emoji(self, emoji: discord.PartialEmoji, valid_list: list[int | str]) -> bool: # Helper for checking if an emoji is in the list in "settings.yml -> BOOKMARK_EMOJIS" - return emoji.name in valid_list if emoji.id is None else emoji.id in valid_list + if emoji.id is not None: + return emoji.id in valid_list + return emoji.name in valid_list @commands.Cog.listener() async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> None: @@ -120,13 +121,6 @@ async def _create_bookmark_embed( embed.add_field(name="Author", value=message.author.name, inline=False) embed.add_field(name="Jump to Message", value=f"[Click Here]({message.jump_url})", inline=False) - - embed.add_field( - name="Delete Bookmark", - value=f"React with {CONFIG.REMOVE_BOOKMARK[0]} to delete this bookmark.", - inline=False, - ) - if message.attachments: attachments_info = "\n".join([attachment.url for attachment in message.attachments]) embed.add_field(name="Attachments", value=attachments_info, inline=False) @@ -161,7 +155,8 @@ async def _send_bookmark( """ try: - await user.send(embed=embed) + dm_message = await user.send(embed=embed) + await dm_message.add_reaction(CONST.REMOVE_BOOKMARK) except (discord.Forbidden, discord.HTTPException) as dm_error: logger.error(f"Cannot send a DM to {user.name}: {dm_error}") diff --git a/tux/utils/config.py b/tux/utils/config.py index 2394cee43..dd3cc7fc3 100644 --- a/tux/utils/config.py +++ b/tux/utils/config.py @@ -152,9 +152,5 @@ def BOT_TOKEN(self) -> str: # noqa: N802 LIMIT_TO_ROLE_IDS: Final[bool] = config["SNIPPETS"]["LIMIT_TO_ROLE_IDS"] ACCESS_ROLE_IDS: Final[list[int]] = config["SNIPPETS"]["ACCESS_ROLE_IDS"] - # Bookmark reactions - ADD_BOOKMARK: Final[list[int | str]] = config["BOOKMARK_EMOJIS"]["ADD_BOOKMARK"] - REMOVE_BOOKMARK: Final[list[int | str]] = config["BOOKMARK_EMOJIS"]["REMOVE_BOOKMARK"] - CONFIG = Config() diff --git a/tux/utils/constants.py b/tux/utils/constants.py index 166673c2b..f1f2a94b8 100644 --- a/tux/utils/constants.py +++ b/tux/utils/constants.py @@ -73,5 +73,9 @@ class Constants: EIGHT_BALL_QUESTION_LENGTH_LIMIT = 120 EIGHT_BALL_RESPONSE_WRAP_WIDTH = 30 + # Bookmark constants + ADD_BOOKMARK = "🔖" + REMOVE_BOOKMARK = "🗑️" + CONST = Constants() From aacfee8b0380bb50fff2652c39459461e29aad01 Mon Sep 17 00:00:00 2001 From: cherryl1k <102343489+cherryl1k@users.noreply.github.com> Date: Mon, 9 Jun 2025 18:48:53 -0500 Subject: [PATCH 13/37] wip changes --- config/settings.yml.example | 8 ++++++ tux/cogs/services/bookmarks.py | 46 ++++++++++++++++++++++++++-------- tux/utils/config.py | 4 +++ 3 files changed, 47 insertions(+), 11 deletions(-) diff --git a/config/settings.yml.example b/config/settings.yml.example index 111ecf375..719032fa6 100644 --- a/config/settings.yml.example +++ b/config/settings.yml.example @@ -114,3 +114,11 @@ GIF_LIMITER: # Limits the amount of gifs a user can send in a channel "123456789012345": 2 GIF_LIMITS_CHANNEL: "123456789012345": 3 + +BOOKMARK_EMOJIS: + ADD_BOOKMARK: # Unicode Emojis or Custom Server Emoji IDs + - "🔖" + # Custom Emoji example + # - 1274504955163709525 + REMOVE_BOOKMARK: # Unicode Emojis or Custom Server Emoji IDs (not reccomended) + - "🗑️" diff --git a/tux/cogs/services/bookmarks.py b/tux/cogs/services/bookmarks.py index fdedf2c7c..6d9e8102c 100644 --- a/tux/cogs/services/bookmarks.py +++ b/tux/cogs/services/bookmarks.py @@ -6,6 +6,7 @@ from tux.bot import Tux from tux.ui.embeds import EmbedCreator +from tux.utils.config import CONFIG from tux.utils.constants import CONST @@ -13,6 +14,16 @@ class Bookmarks(commands.Cog): def __init__(self, bot: Tux) -> None: self.bot = bot + self.valid_emojis: list[int | str] = CONFIG.ADD_BOOKMARK + CONFIG.REMOVE_BOOKMARK + self.valid_add_emojis: list[int | str] = CONFIG.ADD_BOOKMARK + self.valid_remove_emojis: list[int | str] = CONFIG.REMOVE_BOOKMARK + + def _is_valid_emoji(self, emoji: discord.PartialEmoji, valid_list: list[int | str]) -> bool: + # Helper for checking if an emoji is in the list in "settings.yml -> BOOKMARK_EMOJIS" + if emoji.id is not None: + return emoji.id in valid_list + return emoji.name in valid_list + @commands.Cog.listener() async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> None: """ @@ -27,8 +38,13 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> ------- None """ + if not self._is_valid_emoji(payload.emoji, self.valid_emojis): + return - if str(payload.emoji) != "🔖": + # Get the user who reacted to the message + user = self.bot.get_user(payload.user_id) + if user is None: + logger.error(f"User not found for ID: {payload.user_id}") return # Fetch the channel where the reaction was added @@ -48,19 +64,21 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> logger.error(f"Failed to fetch message: {fetch_error}") return - # Create an embed for the bookmarked message - embed = self._create_bookmark_embed(message) + # check for what to do + if self._is_valid_emoji(payload.emoji, self.valid_add_emojis): + # Create an embed for the bookmarked message + embed = await self._create_bookmark_embed(message) - # Get the user who reacted to the message - user = self.bot.get_user(payload.user_id) - if user is None: - logger.error(f"User not found for ID: {payload.user_id}") - return + # Send the bookmarked message to the user + await self._send_bookmark(user, message, embed, payload.emoji) - # Send the bookmarked message to the user - await self._send_bookmark(user, message, embed, payload.emoji) + elif self._is_valid_emoji(payload.emoji, self.valid_remove_emojis): + await self._delete_bookmark(message, user) + else: + logger.debug("Somehow you managed to get bast the first valid emoji check then failed the 2nd good job?") + return - def _create_bookmark_embed( + async def _create_bookmark_embed( self, message: discord.Message, ) -> discord.Embed: @@ -84,6 +102,12 @@ def _create_bookmark_embed( return embed + async def _delete_bookmark(self, message: discord.Message, user: discord.User) -> None: + logger.debug("you got to the delte function") + if message.author is not self.bot.user: + logger.debug("not tux message") + return + @staticmethod async def _send_bookmark( user: discord.User, diff --git a/tux/utils/config.py b/tux/utils/config.py index dd3cc7fc3..2394cee43 100644 --- a/tux/utils/config.py +++ b/tux/utils/config.py @@ -152,5 +152,9 @@ def BOT_TOKEN(self) -> str: # noqa: N802 LIMIT_TO_ROLE_IDS: Final[bool] = config["SNIPPETS"]["LIMIT_TO_ROLE_IDS"] ACCESS_ROLE_IDS: Final[list[int]] = config["SNIPPETS"]["ACCESS_ROLE_IDS"] + # Bookmark reactions + ADD_BOOKMARK: Final[list[int | str]] = config["BOOKMARK_EMOJIS"]["ADD_BOOKMARK"] + REMOVE_BOOKMARK: Final[list[int | str]] = config["BOOKMARK_EMOJIS"]["REMOVE_BOOKMARK"] + CONFIG = Config() From b7cf0f48ab2fd5cf30c56f2278da86e25af63f31 Mon Sep 17 00:00:00 2001 From: cherryl1k <102343489+cherryl1k@users.noreply.github.com> Date: Thu, 19 Jun 2025 12:33:27 -0500 Subject: [PATCH 14/37] Added removing bookmarks from the bot's DMs --- tux/cogs/services/bookmarks.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tux/cogs/services/bookmarks.py b/tux/cogs/services/bookmarks.py index 6d9e8102c..44a726ee5 100644 --- a/tux/cogs/services/bookmarks.py +++ b/tux/cogs/services/bookmarks.py @@ -75,7 +75,7 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> elif self._is_valid_emoji(payload.emoji, self.valid_remove_emojis): await self._delete_bookmark(message, user) else: - logger.debug("Somehow you managed to get bast the first valid emoji check then failed the 2nd good job?") + logger.error("How did you fail the 2nd check but passed the first?") return async def _create_bookmark_embed( @@ -103,10 +103,9 @@ async def _create_bookmark_embed( return embed async def _delete_bookmark(self, message: discord.Message, user: discord.User) -> None: - logger.debug("you got to the delte function") if message.author is not self.bot.user: - logger.debug("not tux message") return + await message.delete() @staticmethod async def _send_bookmark( From 67110f5fd19979c0cb5b6465472283043f11cf2b Mon Sep 17 00:00:00 2001 From: cherryl1k <102343489+cherryl1k@users.noreply.github.com> Date: Thu, 19 Jun 2025 14:32:38 -0500 Subject: [PATCH 15/37] added eletrons changes and fixed a warning --- config/settings.yml.example | 7 +++---- tux/cogs/services/bookmarks.py | 30 +++++++++++++++++++++++------- tux/cogs/utility/poll.py | 18 +++++++++++------- 3 files changed, 37 insertions(+), 18 deletions(-) diff --git a/config/settings.yml.example b/config/settings.yml.example index 719032fa6..4433f9eb7 100644 --- a/config/settings.yml.example +++ b/config/settings.yml.example @@ -116,9 +116,8 @@ GIF_LIMITER: # Limits the amount of gifs a user can send in a channel "123456789012345": 3 BOOKMARK_EMOJIS: - ADD_BOOKMARK: # Unicode Emojis or Custom Server Emoji IDs + ADD_BOOKMARK: - "🔖" - # Custom Emoji example - # - 1274504955163709525 - REMOVE_BOOKMARK: # Unicode Emojis or Custom Server Emoji IDs (not reccomended) + #- 123456789012345 # Custom emoji example, replace with emoji id + REMOVE_BOOKMARK: # Do not use custom emojis for this. - "🗑️" diff --git a/tux/cogs/services/bookmarks.py b/tux/cogs/services/bookmarks.py index 44a726ee5..1fd1b7762 100644 --- a/tux/cogs/services/bookmarks.py +++ b/tux/cogs/services/bookmarks.py @@ -20,9 +20,7 @@ def __init__(self, bot: Tux) -> None: def _is_valid_emoji(self, emoji: discord.PartialEmoji, valid_list: list[int | str]) -> bool: # Helper for checking if an emoji is in the list in "settings.yml -> BOOKMARK_EMOJIS" - if emoji.id is not None: - return emoji.id in valid_list - return emoji.name in valid_list + return emoji.name in valid_list if emoji.id is None else emoji.id in valid_list @commands.Cog.listener() async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> None: @@ -44,14 +42,24 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> # Get the user who reacted to the message user = self.bot.get_user(payload.user_id) if user is None: - logger.error(f"User not found for ID: {payload.user_id}") + try: + user = await self.bot.fetch_user(payload.user_id) + except discord.NotFound: + logger.error(f"User not found for ID: {payload.user_id}") + except (discord.Forbidden, discord.HTTPException) as fetch_error: + logger.error(f"Failed to fetch user: {fetch_error}") return - # Fetch the channel where the reaction was added channel = self.bot.get_channel(payload.channel_id) if channel is None: - logger.error(f"Channel not found for ID: {payload.channel_id}") + try: + channel = await self.bot.fetch_channel(payload.channel_id) + except discord.NotFound: + logger.error(f"Channel not found for ID: {payload.channel_id}") + except (discord.Forbidden, discord.HTTPException) as fetch_error: + logger.error(f"Failed to fetch channel: {fetch_error}") return + channel = cast(discord.TextChannel | discord.Thread, channel) # Fetch the message that was reacted to @@ -75,7 +83,9 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> elif self._is_valid_emoji(payload.emoji, self.valid_remove_emojis): await self._delete_bookmark(message, user) else: - logger.error("How did you fail the 2nd check but passed the first?") + logger.error( + "First emoji validation check passed but second emoji validation check failed. How the fuck did you get here?", + ) return async def _create_bookmark_embed( @@ -96,6 +106,12 @@ async def _create_bookmark_embed( embed.add_field(name="Jump to Message", value=f"[Click Here]({message.jump_url})", inline=False) + embed.add_field( + name="Delete Bookmark", + value=f"React with {CONFIG.REMOVE_BOOKMARK[0]} to delete this bookmark.", + inline=False, + ) + if message.attachments: attachments_info = "\n".join([attachment.url for attachment in message.attachments]) embed.add_field(name="Attachments", value=attachments_info, inline=False) diff --git a/tux/cogs/utility/poll.py b/tux/cogs/utility/poll.py index fb75a2982..0affb1565 100644 --- a/tux/cogs/utility/poll.py +++ b/tux/cogs/utility/poll.py @@ -1,3 +1,5 @@ +from typing import cast + import discord from discord import app_commands from discord.ext import commands @@ -74,13 +76,15 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> # get reaction from payload.message_id, payload.channel_id, payload.guild_id, payload.emoji channel = self.bot.get_channel(payload.channel_id) if channel is None: - logger.error(f"Channel with ID {payload.channel_id} not found.") - return - if isinstance(channel, discord.ForumChannel | discord.CategoryChannel | discord.abc.PrivateChannel): - logger.error( - f"Channel with ID {payload.channel_id} is not a compatible channel type. How the fuck did you get here?", - ) - return + try: + channel = await self.bot.fetch_channel(payload.channel_id) + except discord.NotFound: + logger.error(f"Channel not found for ID: {payload.channel_id}") + return + except (discord.Forbidden, discord.HTTPException) as fetch_error: + logger.error(f"Failed to fetch channel: {fetch_error}") + return + channel = cast(discord.TextChannel | discord.Thread, channel) message = await channel.fetch_message(payload.message_id) # Lookup the reaction object for this event From 5c959c7645e087c27f17ac4ffe4c2f8e904a249e Mon Sep 17 00:00:00 2001 From: electron271 <66094410+electron271@users.noreply.github.com> Date: Thu, 19 Jun 2025 14:08:52 -0500 Subject: [PATCH 16/37] fix(bookmarks): improve emoji validation and error handling for user and channel fetching --- tux/cogs/services/bookmarks.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tux/cogs/services/bookmarks.py b/tux/cogs/services/bookmarks.py index 1fd1b7762..f4f59093d 100644 --- a/tux/cogs/services/bookmarks.py +++ b/tux/cogs/services/bookmarks.py @@ -46,9 +46,17 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> user = await self.bot.fetch_user(payload.user_id) except discord.NotFound: logger.error(f"User not found for ID: {payload.user_id}") +<<<<<<< HEAD except (discord.Forbidden, discord.HTTPException) as fetch_error: logger.error(f"Failed to fetch user: {fetch_error}") return +======= + return + except (discord.Forbidden, discord.HTTPException) as fetch_error: + logger.error(f"Failed to fetch user: {fetch_error}") + return + +>>>>>>> 217c364 (fix(bookmarks): improve emoji validation and error handling for user and channel fetching) # Fetch the channel where the reaction was added channel = self.bot.get_channel(payload.channel_id) if channel is None: @@ -56,10 +64,17 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> channel = await self.bot.fetch_channel(payload.channel_id) except discord.NotFound: logger.error(f"Channel not found for ID: {payload.channel_id}") +<<<<<<< HEAD except (discord.Forbidden, discord.HTTPException) as fetch_error: logger.error(f"Failed to fetch channel: {fetch_error}") return +======= + return + except (discord.Forbidden, discord.HTTPException) as fetch_error: + logger.error(f"Failed to fetch channel: {fetch_error}") + return +>>>>>>> 217c364 (fix(bookmarks): improve emoji validation and error handling for user and channel fetching) channel = cast(discord.TextChannel | discord.Thread, channel) # Fetch the message that was reacted to From f1e4c72e9ff595b094473417b66d5b8076340286 Mon Sep 17 00:00:00 2001 From: cherryl1k <102343489+cherryl1k@users.noreply.github.com> Date: Fri, 20 Jun 2025 12:11:09 -0500 Subject: [PATCH 17/37] chore(wip): still working on debugging --- config/settings.yml.example | 7 ------- tux/cogs/services/bookmarks.py | 21 ++++++++------------- tux/utils/config.py | 4 ---- tux/utils/constants.py | 4 ++++ 4 files changed, 12 insertions(+), 24 deletions(-) diff --git a/config/settings.yml.example b/config/settings.yml.example index 4433f9eb7..111ecf375 100644 --- a/config/settings.yml.example +++ b/config/settings.yml.example @@ -114,10 +114,3 @@ GIF_LIMITER: # Limits the amount of gifs a user can send in a channel "123456789012345": 2 GIF_LIMITS_CHANNEL: "123456789012345": 3 - -BOOKMARK_EMOJIS: - ADD_BOOKMARK: - - "🔖" - #- 123456789012345 # Custom emoji example, replace with emoji id - REMOVE_BOOKMARK: # Do not use custom emojis for this. - - "🗑️" diff --git a/tux/cogs/services/bookmarks.py b/tux/cogs/services/bookmarks.py index f4f59093d..35f8b9f1d 100644 --- a/tux/cogs/services/bookmarks.py +++ b/tux/cogs/services/bookmarks.py @@ -6,7 +6,6 @@ from tux.bot import Tux from tux.ui.embeds import EmbedCreator -from tux.utils.config import CONFIG from tux.utils.constants import CONST @@ -14,13 +13,15 @@ class Bookmarks(commands.Cog): def __init__(self, bot: Tux) -> None: self.bot = bot - self.valid_emojis: list[int | str] = CONFIG.ADD_BOOKMARK + CONFIG.REMOVE_BOOKMARK - self.valid_add_emojis: list[int | str] = CONFIG.ADD_BOOKMARK - self.valid_remove_emojis: list[int | str] = CONFIG.REMOVE_BOOKMARK + self.valid_add_emojis = CONST.ADD_BOOKMARK + self.valid_remove_emojis = CONST.REMOVE_BOOKMARK + self.valid_emojis = CONST.ADD_BOOKMARK + CONST.REMOVE_BOOKMARK def _is_valid_emoji(self, emoji: discord.PartialEmoji, valid_list: list[int | str]) -> bool: # Helper for checking if an emoji is in the list in "settings.yml -> BOOKMARK_EMOJIS" - return emoji.name in valid_list if emoji.id is None else emoji.id in valid_list + if emoji.id is not None: + return emoji.id in valid_list + return emoji.name in valid_list @commands.Cog.listener() async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> None: @@ -120,13 +121,6 @@ async def _create_bookmark_embed( embed.add_field(name="Author", value=message.author.name, inline=False) embed.add_field(name="Jump to Message", value=f"[Click Here]({message.jump_url})", inline=False) - - embed.add_field( - name="Delete Bookmark", - value=f"React with {CONFIG.REMOVE_BOOKMARK[0]} to delete this bookmark.", - inline=False, - ) - if message.attachments: attachments_info = "\n".join([attachment.url for attachment in message.attachments]) embed.add_field(name="Attachments", value=attachments_info, inline=False) @@ -161,7 +155,8 @@ async def _send_bookmark( """ try: - await user.send(embed=embed) + dm_message = await user.send(embed=embed) + await dm_message.add_reaction(CONST.REMOVE_BOOKMARK) except (discord.Forbidden, discord.HTTPException) as dm_error: logger.error(f"Cannot send a DM to {user.name}: {dm_error}") diff --git a/tux/utils/config.py b/tux/utils/config.py index 2394cee43..dd3cc7fc3 100644 --- a/tux/utils/config.py +++ b/tux/utils/config.py @@ -152,9 +152,5 @@ def BOT_TOKEN(self) -> str: # noqa: N802 LIMIT_TO_ROLE_IDS: Final[bool] = config["SNIPPETS"]["LIMIT_TO_ROLE_IDS"] ACCESS_ROLE_IDS: Final[list[int]] = config["SNIPPETS"]["ACCESS_ROLE_IDS"] - # Bookmark reactions - ADD_BOOKMARK: Final[list[int | str]] = config["BOOKMARK_EMOJIS"]["ADD_BOOKMARK"] - REMOVE_BOOKMARK: Final[list[int | str]] = config["BOOKMARK_EMOJIS"]["REMOVE_BOOKMARK"] - CONFIG = Config() diff --git a/tux/utils/constants.py b/tux/utils/constants.py index 166673c2b..f1f2a94b8 100644 --- a/tux/utils/constants.py +++ b/tux/utils/constants.py @@ -73,5 +73,9 @@ class Constants: EIGHT_BALL_QUESTION_LENGTH_LIMIT = 120 EIGHT_BALL_RESPONSE_WRAP_WIDTH = 30 + # Bookmark constants + ADD_BOOKMARK = "🔖" + REMOVE_BOOKMARK = "🗑️" + CONST = Constants() From 627c5bb9621c474df79eabc3d42c13f119f54183 Mon Sep 17 00:00:00 2001 From: cherryl1k <102343489+cherryl1k@users.noreply.github.com> Date: Mon, 9 Jun 2025 18:48:53 -0500 Subject: [PATCH 18/37] wip changes --- config/settings.yml.example | 8 ++++++++ tux/cogs/services/bookmarks.py | 27 +++++++++++++++++++++++++++ tux/utils/config.py | 4 ++++ 3 files changed, 39 insertions(+) diff --git a/config/settings.yml.example b/config/settings.yml.example index 111ecf375..719032fa6 100644 --- a/config/settings.yml.example +++ b/config/settings.yml.example @@ -114,3 +114,11 @@ GIF_LIMITER: # Limits the amount of gifs a user can send in a channel "123456789012345": 2 GIF_LIMITS_CHANNEL: "123456789012345": 3 + +BOOKMARK_EMOJIS: + ADD_BOOKMARK: # Unicode Emojis or Custom Server Emoji IDs + - "🔖" + # Custom Emoji example + # - 1274504955163709525 + REMOVE_BOOKMARK: # Unicode Emojis or Custom Server Emoji IDs (not reccomended) + - "🗑️" diff --git a/tux/cogs/services/bookmarks.py b/tux/cogs/services/bookmarks.py index 35f8b9f1d..964c0f9e2 100644 --- a/tux/cogs/services/bookmarks.py +++ b/tux/cogs/services/bookmarks.py @@ -6,6 +6,7 @@ from tux.bot import Tux from tux.ui.embeds import EmbedCreator +from tux.utils.config import CONFIG from tux.utils.constants import CONST @@ -13,9 +14,15 @@ class Bookmarks(commands.Cog): def __init__(self, bot: Tux) -> None: self.bot = bot +<<<<<<< HEAD self.valid_add_emojis = CONST.ADD_BOOKMARK self.valid_remove_emojis = CONST.REMOVE_BOOKMARK self.valid_emojis = CONST.ADD_BOOKMARK + CONST.REMOVE_BOOKMARK +======= + self.valid_emojis: list[int | str] = CONFIG.ADD_BOOKMARK + CONFIG.REMOVE_BOOKMARK + self.valid_add_emojis: list[int | str] = CONFIG.ADD_BOOKMARK + self.valid_remove_emojis: list[int | str] = CONFIG.REMOVE_BOOKMARK +>>>>>>> b9c797a (wip changes) def _is_valid_emoji(self, emoji: discord.PartialEmoji, valid_list: list[int | str]) -> bool: # Helper for checking if an emoji is in the list in "settings.yml -> BOOKMARK_EMOJIS" @@ -38,6 +45,15 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> None """ if not self._is_valid_emoji(payload.emoji, self.valid_emojis): +<<<<<<< HEAD +======= + return + + # Get the user who reacted to the message + user = self.bot.get_user(payload.user_id) + if user is None: + logger.error(f"User not found for ID: {payload.user_id}") +>>>>>>> b9c797a (wip changes) return # Get the user who reacted to the message @@ -99,9 +115,13 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> elif self._is_valid_emoji(payload.emoji, self.valid_remove_emojis): await self._delete_bookmark(message, user) else: +<<<<<<< HEAD logger.error( "First emoji validation check passed but second emoji validation check failed. How the fuck did you get here?", ) +======= + logger.debug("Somehow you managed to get bast the first valid emoji check then failed the 2nd good job?") +>>>>>>> b9c797a (wip changes) return async def _create_bookmark_embed( @@ -128,9 +148,16 @@ async def _create_bookmark_embed( return embed async def _delete_bookmark(self, message: discord.Message, user: discord.User) -> None: +<<<<<<< HEAD if message.author is not self.bot.user: return await message.delete() +======= + logger.debug("you got to the delte function") + if message.author is not self.bot.user: + logger.debug("not tux message") + return +>>>>>>> b9c797a (wip changes) @staticmethod async def _send_bookmark( diff --git a/tux/utils/config.py b/tux/utils/config.py index dd3cc7fc3..2394cee43 100644 --- a/tux/utils/config.py +++ b/tux/utils/config.py @@ -152,5 +152,9 @@ def BOT_TOKEN(self) -> str: # noqa: N802 LIMIT_TO_ROLE_IDS: Final[bool] = config["SNIPPETS"]["LIMIT_TO_ROLE_IDS"] ACCESS_ROLE_IDS: Final[list[int]] = config["SNIPPETS"]["ACCESS_ROLE_IDS"] + # Bookmark reactions + ADD_BOOKMARK: Final[list[int | str]] = config["BOOKMARK_EMOJIS"]["ADD_BOOKMARK"] + REMOVE_BOOKMARK: Final[list[int | str]] = config["BOOKMARK_EMOJIS"]["REMOVE_BOOKMARK"] + CONFIG = Config() From 000bc72b4347bb43eff70f9987fb5faf722d8067 Mon Sep 17 00:00:00 2001 From: cherryl1k <102343489+cherryl1k@users.noreply.github.com> Date: Thu, 19 Jun 2025 12:33:27 -0500 Subject: [PATCH 19/37] Added removing bookmarks from the bot's DMs --- tux/cogs/services/bookmarks.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tux/cogs/services/bookmarks.py b/tux/cogs/services/bookmarks.py index 964c0f9e2..a4bc5e87e 100644 --- a/tux/cogs/services/bookmarks.py +++ b/tux/cogs/services/bookmarks.py @@ -115,6 +115,7 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> elif self._is_valid_emoji(payload.emoji, self.valid_remove_emojis): await self._delete_bookmark(message, user) else: +<<<<<<< HEAD <<<<<<< HEAD logger.error( "First emoji validation check passed but second emoji validation check failed. How the fuck did you get here?", @@ -122,6 +123,9 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> ======= logger.debug("Somehow you managed to get bast the first valid emoji check then failed the 2nd good job?") >>>>>>> b9c797a (wip changes) +======= + logger.error("How did you fail the 2nd check but passed the first?") +>>>>>>> 56bebaf (Added removing bookmarks from the bot's DMs) return async def _create_bookmark_embed( @@ -148,16 +152,22 @@ async def _create_bookmark_embed( return embed async def _delete_bookmark(self, message: discord.Message, user: discord.User) -> None: +<<<<<<< HEAD <<<<<<< HEAD if message.author is not self.bot.user: return await message.delete() ======= logger.debug("you got to the delte function") +======= +>>>>>>> 56bebaf (Added removing bookmarks from the bot's DMs) if message.author is not self.bot.user: - logger.debug("not tux message") return +<<<<<<< HEAD >>>>>>> b9c797a (wip changes) +======= + await message.delete() +>>>>>>> 56bebaf (Added removing bookmarks from the bot's DMs) @staticmethod async def _send_bookmark( From dc15ffefbd343117ecc972339521ab55238d827c Mon Sep 17 00:00:00 2001 From: cherryl1k <102343489+cherryl1k@users.noreply.github.com> Date: Thu, 19 Jun 2025 14:32:38 -0500 Subject: [PATCH 20/37] added eletrons changes and fixed a warning --- config/settings.yml.example | 7 +++---- tux/cogs/services/bookmarks.py | 36 +++++++++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/config/settings.yml.example b/config/settings.yml.example index 719032fa6..4433f9eb7 100644 --- a/config/settings.yml.example +++ b/config/settings.yml.example @@ -116,9 +116,8 @@ GIF_LIMITER: # Limits the amount of gifs a user can send in a channel "123456789012345": 3 BOOKMARK_EMOJIS: - ADD_BOOKMARK: # Unicode Emojis or Custom Server Emoji IDs + ADD_BOOKMARK: - "🔖" - # Custom Emoji example - # - 1274504955163709525 - REMOVE_BOOKMARK: # Unicode Emojis or Custom Server Emoji IDs (not reccomended) + #- 123456789012345 # Custom emoji example, replace with emoji id + REMOVE_BOOKMARK: # Do not use custom emojis for this. - "🗑️" diff --git a/tux/cogs/services/bookmarks.py b/tux/cogs/services/bookmarks.py index a4bc5e87e..67c4ead25 100644 --- a/tux/cogs/services/bookmarks.py +++ b/tux/cogs/services/bookmarks.py @@ -26,9 +26,7 @@ def __init__(self, bot: Tux) -> None: def _is_valid_emoji(self, emoji: discord.PartialEmoji, valid_list: list[int | str]) -> bool: # Helper for checking if an emoji is in the list in "settings.yml -> BOOKMARK_EMOJIS" - if emoji.id is not None: - return emoji.id in valid_list - return emoji.name in valid_list + return emoji.name in valid_list if emoji.id is None else emoji.id in valid_list @commands.Cog.listener() async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> None: @@ -52,6 +50,7 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> # Get the user who reacted to the message user = self.bot.get_user(payload.user_id) if user is None: +<<<<<<< HEAD logger.error(f"User not found for ID: {payload.user_id}") >>>>>>> b9c797a (wip changes) return @@ -74,6 +73,15 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> return >>>>>>> 217c364 (fix(bookmarks): improve emoji validation and error handling for user and channel fetching) +======= + try: + user = await self.bot.fetch_user(payload.user_id) + except discord.NotFound: + logger.error(f"User not found for ID: {payload.user_id}") + except (discord.Forbidden, discord.HTTPException) as fetch_error: + logger.error(f"Failed to fetch user: {fetch_error}") + return +>>>>>>> b8a4072 (added eletrons changes and fixed a warning) # Fetch the channel where the reaction was added channel = self.bot.get_channel(payload.channel_id) if channel is None: @@ -82,16 +90,22 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> except discord.NotFound: logger.error(f"Channel not found for ID: {payload.channel_id}") <<<<<<< HEAD +<<<<<<< HEAD +======= +>>>>>>> b8a4072 (added eletrons changes and fixed a warning) except (discord.Forbidden, discord.HTTPException) as fetch_error: logger.error(f"Failed to fetch channel: {fetch_error}") return +<<<<<<< HEAD ======= return except (discord.Forbidden, discord.HTTPException) as fetch_error: logger.error(f"Failed to fetch channel: {fetch_error}") return >>>>>>> 217c364 (fix(bookmarks): improve emoji validation and error handling for user and channel fetching) +======= +>>>>>>> b8a4072 (added eletrons changes and fixed a warning) channel = cast(discord.TextChannel | discord.Thread, channel) # Fetch the message that was reacted to @@ -116,6 +130,7 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> await self._delete_bookmark(message, user) else: <<<<<<< HEAD +<<<<<<< HEAD <<<<<<< HEAD logger.error( "First emoji validation check passed but second emoji validation check failed. How the fuck did you get here?", @@ -126,6 +141,11 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> ======= logger.error("How did you fail the 2nd check but passed the first?") >>>>>>> 56bebaf (Added removing bookmarks from the bot's DMs) +======= + logger.error( + "First emoji validation check passed but second emoji validation check failed. How the fuck did you get here?", + ) +>>>>>>> b8a4072 (added eletrons changes and fixed a warning) return async def _create_bookmark_embed( @@ -145,6 +165,16 @@ async def _create_bookmark_embed( embed.add_field(name="Author", value=message.author.name, inline=False) embed.add_field(name="Jump to Message", value=f"[Click Here]({message.jump_url})", inline=False) +<<<<<<< HEAD +======= + + embed.add_field( + name="Delete Bookmark", + value=f"React with {CONFIG.REMOVE_BOOKMARK[0]} to delete this bookmark.", + inline=False, + ) + +>>>>>>> b8a4072 (added eletrons changes and fixed a warning) if message.attachments: attachments_info = "\n".join([attachment.url for attachment in message.attachments]) embed.add_field(name="Attachments", value=attachments_info, inline=False) From 38f9809e66cc72ca5e183658abc57e6a0b78cb22 Mon Sep 17 00:00:00 2001 From: electron271 <66094410+electron271@users.noreply.github.com> Date: Thu, 19 Jun 2025 14:08:52 -0500 Subject: [PATCH 21/37] fix(bookmarks): improve emoji validation and error handling for user and channel fetching --- tux/cogs/services/bookmarks.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tux/cogs/services/bookmarks.py b/tux/cogs/services/bookmarks.py index 67c4ead25..53fb90282 100644 --- a/tux/cogs/services/bookmarks.py +++ b/tux/cogs/services/bookmarks.py @@ -50,10 +50,21 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> # Get the user who reacted to the message user = self.bot.get_user(payload.user_id) if user is None: +<<<<<<< HEAD <<<<<<< HEAD logger.error(f"User not found for ID: {payload.user_id}") >>>>>>> b9c797a (wip changes) return +======= + try: + user = await self.bot.fetch_user(payload.user_id) + except discord.NotFound: + logger.error(f"User not found for ID: {payload.user_id}") + return + except (discord.Forbidden, discord.HTTPException) as fetch_error: + logger.error(f"Failed to fetch user: {fetch_error}") + return +>>>>>>> 217c364 (fix(bookmarks): improve emoji validation and error handling for user and channel fetching) # Get the user who reacted to the message user = self.bot.get_user(payload.user_id) @@ -91,6 +102,7 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> logger.error(f"Channel not found for ID: {payload.channel_id}") <<<<<<< HEAD <<<<<<< HEAD +<<<<<<< HEAD ======= >>>>>>> b8a4072 (added eletrons changes and fixed a warning) except (discord.Forbidden, discord.HTTPException) as fetch_error: @@ -99,13 +111,18 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> <<<<<<< HEAD ======= +======= +>>>>>>> 217c364 (fix(bookmarks): improve emoji validation and error handling for user and channel fetching) return except (discord.Forbidden, discord.HTTPException) as fetch_error: logger.error(f"Failed to fetch channel: {fetch_error}") return +<<<<<<< HEAD >>>>>>> 217c364 (fix(bookmarks): improve emoji validation and error handling for user and channel fetching) ======= >>>>>>> b8a4072 (added eletrons changes and fixed a warning) +======= +>>>>>>> 217c364 (fix(bookmarks): improve emoji validation and error handling for user and channel fetching) channel = cast(discord.TextChannel | discord.Thread, channel) # Fetch the message that was reacted to @@ -131,6 +148,7 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> else: <<<<<<< HEAD <<<<<<< HEAD +<<<<<<< HEAD <<<<<<< HEAD logger.error( "First emoji validation check passed but second emoji validation check failed. How the fuck did you get here?", @@ -146,6 +164,11 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> "First emoji validation check passed but second emoji validation check failed. How the fuck did you get here?", ) >>>>>>> b8a4072 (added eletrons changes and fixed a warning) +======= + logger.error( + "First emoji validation check passed but second emoji validation check failed. How the fuck did you get here?", + ) +>>>>>>> 217c364 (fix(bookmarks): improve emoji validation and error handling for user and channel fetching) return async def _create_bookmark_embed( @@ -174,7 +197,10 @@ async def _create_bookmark_embed( inline=False, ) +<<<<<<< HEAD >>>>>>> b8a4072 (added eletrons changes and fixed a warning) +======= +>>>>>>> 217c364 (fix(bookmarks): improve emoji validation and error handling for user and channel fetching) if message.attachments: attachments_info = "\n".join([attachment.url for attachment in message.attachments]) embed.add_field(name="Attachments", value=attachments_info, inline=False) From fc562039f7246deac24412df9cfb9ccf53b48e78 Mon Sep 17 00:00:00 2001 From: cherryl1k <102343489+cherryl1k@users.noreply.github.com> Date: Thu, 19 Jun 2025 14:38:53 -0500 Subject: [PATCH 22/37] i think i fixed whatever the hell git just did --- tux/cogs/services/bookmarks.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tux/cogs/services/bookmarks.py b/tux/cogs/services/bookmarks.py index 53fb90282..ec6a48731 100644 --- a/tux/cogs/services/bookmarks.py +++ b/tux/cogs/services/bookmarks.py @@ -153,6 +153,7 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> logger.error( "First emoji validation check passed but second emoji validation check failed. How the fuck did you get here?", ) +<<<<<<< HEAD ======= logger.debug("Somehow you managed to get bast the first valid emoji check then failed the 2nd good job?") >>>>>>> b9c797a (wip changes) @@ -169,6 +170,8 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> "First emoji validation check passed but second emoji validation check failed. How the fuck did you get here?", ) >>>>>>> 217c364 (fix(bookmarks): improve emoji validation and error handling for user and channel fetching) +======= +>>>>>>> 34798e9 (i think i fixed whatever the hell git just did) return async def _create_bookmark_embed( @@ -197,10 +200,13 @@ async def _create_bookmark_embed( inline=False, ) +<<<<<<< HEAD <<<<<<< HEAD >>>>>>> b8a4072 (added eletrons changes and fixed a warning) ======= >>>>>>> 217c364 (fix(bookmarks): improve emoji validation and error handling for user and channel fetching) +======= +>>>>>>> 34798e9 (i think i fixed whatever the hell git just did) if message.attachments: attachments_info = "\n".join([attachment.url for attachment in message.attachments]) embed.add_field(name="Attachments", value=attachments_info, inline=False) From 8477862ffb97c5f35d62a34576abe0ea596b891b Mon Sep 17 00:00:00 2001 From: cherryl1k <102343489+cherryl1k@users.noreply.github.com> Date: Fri, 20 Jun 2025 12:11:09 -0500 Subject: [PATCH 23/37] chore(wip): still working on debugging --- config/settings.yml.example | 7 ------- tux/cogs/services/bookmarks.py | 14 ++++++++++++-- tux/utils/config.py | 4 ---- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/config/settings.yml.example b/config/settings.yml.example index 4433f9eb7..111ecf375 100644 --- a/config/settings.yml.example +++ b/config/settings.yml.example @@ -114,10 +114,3 @@ GIF_LIMITER: # Limits the amount of gifs a user can send in a channel "123456789012345": 2 GIF_LIMITS_CHANNEL: "123456789012345": 3 - -BOOKMARK_EMOJIS: - ADD_BOOKMARK: - - "🔖" - #- 123456789012345 # Custom emoji example, replace with emoji id - REMOVE_BOOKMARK: # Do not use custom emojis for this. - - "🗑️" diff --git a/tux/cogs/services/bookmarks.py b/tux/cogs/services/bookmarks.py index ec6a48731..2c6a74922 100644 --- a/tux/cogs/services/bookmarks.py +++ b/tux/cogs/services/bookmarks.py @@ -6,7 +6,6 @@ from tux.bot import Tux from tux.ui.embeds import EmbedCreator -from tux.utils.config import CONFIG from tux.utils.constants import CONST @@ -14,6 +13,7 @@ class Bookmarks(commands.Cog): def __init__(self, bot: Tux) -> None: self.bot = bot +<<<<<<< HEAD <<<<<<< HEAD self.valid_add_emojis = CONST.ADD_BOOKMARK self.valid_remove_emojis = CONST.REMOVE_BOOKMARK @@ -23,10 +23,17 @@ def __init__(self, bot: Tux) -> None: self.valid_add_emojis: list[int | str] = CONFIG.ADD_BOOKMARK self.valid_remove_emojis: list[int | str] = CONFIG.REMOVE_BOOKMARK >>>>>>> b9c797a (wip changes) +======= + self.valid_add_emojis = CONST.ADD_BOOKMARK + self.valid_remove_emojis = CONST.REMOVE_BOOKMARK + self.valid_emojis = CONST.ADD_BOOKMARK + CONST.REMOVE_BOOKMARK +>>>>>>> ba2c381 (chore(wip): still working on debugging) def _is_valid_emoji(self, emoji: discord.PartialEmoji, valid_list: list[int | str]) -> bool: # Helper for checking if an emoji is in the list in "settings.yml -> BOOKMARK_EMOJIS" - return emoji.name in valid_list if emoji.id is None else emoji.id in valid_list + if emoji.id is not None: + return emoji.id in valid_list + return emoji.name in valid_list @commands.Cog.listener() async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> None: @@ -192,6 +199,7 @@ async def _create_bookmark_embed( embed.add_field(name="Jump to Message", value=f"[Click Here]({message.jump_url})", inline=False) <<<<<<< HEAD +<<<<<<< HEAD ======= embed.add_field( @@ -207,6 +215,8 @@ async def _create_bookmark_embed( >>>>>>> 217c364 (fix(bookmarks): improve emoji validation and error handling for user and channel fetching) ======= >>>>>>> 34798e9 (i think i fixed whatever the hell git just did) +======= +>>>>>>> ba2c381 (chore(wip): still working on debugging) if message.attachments: attachments_info = "\n".join([attachment.url for attachment in message.attachments]) embed.add_field(name="Attachments", value=attachments_info, inline=False) diff --git a/tux/utils/config.py b/tux/utils/config.py index 2394cee43..dd3cc7fc3 100644 --- a/tux/utils/config.py +++ b/tux/utils/config.py @@ -152,9 +152,5 @@ def BOT_TOKEN(self) -> str: # noqa: N802 LIMIT_TO_ROLE_IDS: Final[bool] = config["SNIPPETS"]["LIMIT_TO_ROLE_IDS"] ACCESS_ROLE_IDS: Final[list[int]] = config["SNIPPETS"]["ACCESS_ROLE_IDS"] - # Bookmark reactions - ADD_BOOKMARK: Final[list[int | str]] = config["BOOKMARK_EMOJIS"]["ADD_BOOKMARK"] - REMOVE_BOOKMARK: Final[list[int | str]] = config["BOOKMARK_EMOJIS"]["REMOVE_BOOKMARK"] - CONFIG = Config() From 36a5db626de8325f2073c94d5f66d7d2f9de8f09 Mon Sep 17 00:00:00 2001 From: cherryl1k <102343489+cherryl1k@users.noreply.github.com> Date: Fri, 20 Jun 2025 12:55:25 -0500 Subject: [PATCH 24/37] chore(wip): still working on debugging --- tux/cogs/services/bookmarks.py | 124 --------------------------------- 1 file changed, 124 deletions(-) diff --git a/tux/cogs/services/bookmarks.py b/tux/cogs/services/bookmarks.py index 2c6a74922..80c74a04e 100644 --- a/tux/cogs/services/bookmarks.py +++ b/tux/cogs/services/bookmarks.py @@ -13,21 +13,9 @@ class Bookmarks(commands.Cog): def __init__(self, bot: Tux) -> None: self.bot = bot -<<<<<<< HEAD -<<<<<<< HEAD self.valid_add_emojis = CONST.ADD_BOOKMARK self.valid_remove_emojis = CONST.REMOVE_BOOKMARK self.valid_emojis = CONST.ADD_BOOKMARK + CONST.REMOVE_BOOKMARK -======= - self.valid_emojis: list[int | str] = CONFIG.ADD_BOOKMARK + CONFIG.REMOVE_BOOKMARK - self.valid_add_emojis: list[int | str] = CONFIG.ADD_BOOKMARK - self.valid_remove_emojis: list[int | str] = CONFIG.REMOVE_BOOKMARK ->>>>>>> b9c797a (wip changes) -======= - self.valid_add_emojis = CONST.ADD_BOOKMARK - self.valid_remove_emojis = CONST.REMOVE_BOOKMARK - self.valid_emojis = CONST.ADD_BOOKMARK + CONST.REMOVE_BOOKMARK ->>>>>>> ba2c381 (chore(wip): still working on debugging) def _is_valid_emoji(self, emoji: discord.PartialEmoji, valid_list: list[int | str]) -> bool: # Helper for checking if an emoji is in the list in "settings.yml -> BOOKMARK_EMOJIS" @@ -50,48 +38,11 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> None """ if not self._is_valid_emoji(payload.emoji, self.valid_emojis): -<<<<<<< HEAD -======= return # Get the user who reacted to the message user = self.bot.get_user(payload.user_id) if user is None: -<<<<<<< HEAD -<<<<<<< HEAD - logger.error(f"User not found for ID: {payload.user_id}") ->>>>>>> b9c797a (wip changes) - return -======= - try: - user = await self.bot.fetch_user(payload.user_id) - except discord.NotFound: - logger.error(f"User not found for ID: {payload.user_id}") - return - except (discord.Forbidden, discord.HTTPException) as fetch_error: - logger.error(f"Failed to fetch user: {fetch_error}") - return ->>>>>>> 217c364 (fix(bookmarks): improve emoji validation and error handling for user and channel fetching) - - # Get the user who reacted to the message - user = self.bot.get_user(payload.user_id) - if user is None: - try: - user = await self.bot.fetch_user(payload.user_id) - except discord.NotFound: - logger.error(f"User not found for ID: {payload.user_id}") -<<<<<<< HEAD - except (discord.Forbidden, discord.HTTPException) as fetch_error: - logger.error(f"Failed to fetch user: {fetch_error}") - return -======= - return - except (discord.Forbidden, discord.HTTPException) as fetch_error: - logger.error(f"Failed to fetch user: {fetch_error}") - return - ->>>>>>> 217c364 (fix(bookmarks): improve emoji validation and error handling for user and channel fetching) -======= try: user = await self.bot.fetch_user(payload.user_id) except discord.NotFound: @@ -99,7 +50,6 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> except (discord.Forbidden, discord.HTTPException) as fetch_error: logger.error(f"Failed to fetch user: {fetch_error}") return ->>>>>>> b8a4072 (added eletrons changes and fixed a warning) # Fetch the channel where the reaction was added channel = self.bot.get_channel(payload.channel_id) if channel is None: @@ -107,29 +57,10 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> channel = await self.bot.fetch_channel(payload.channel_id) except discord.NotFound: logger.error(f"Channel not found for ID: {payload.channel_id}") -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -======= ->>>>>>> b8a4072 (added eletrons changes and fixed a warning) except (discord.Forbidden, discord.HTTPException) as fetch_error: logger.error(f"Failed to fetch channel: {fetch_error}") return -<<<<<<< HEAD -======= -======= ->>>>>>> 217c364 (fix(bookmarks): improve emoji validation and error handling for user and channel fetching) - return - except (discord.Forbidden, discord.HTTPException) as fetch_error: - logger.error(f"Failed to fetch channel: {fetch_error}") - return -<<<<<<< HEAD ->>>>>>> 217c364 (fix(bookmarks): improve emoji validation and error handling for user and channel fetching) -======= ->>>>>>> b8a4072 (added eletrons changes and fixed a warning) -======= ->>>>>>> 217c364 (fix(bookmarks): improve emoji validation and error handling for user and channel fetching) channel = cast(discord.TextChannel | discord.Thread, channel) # Fetch the message that was reacted to @@ -153,32 +84,9 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> elif self._is_valid_emoji(payload.emoji, self.valid_remove_emojis): await self._delete_bookmark(message, user) else: -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - logger.error( - "First emoji validation check passed but second emoji validation check failed. How the fuck did you get here?", - ) -<<<<<<< HEAD -======= - logger.debug("Somehow you managed to get bast the first valid emoji check then failed the 2nd good job?") ->>>>>>> b9c797a (wip changes) -======= - logger.error("How did you fail the 2nd check but passed the first?") ->>>>>>> 56bebaf (Added removing bookmarks from the bot's DMs) -======= logger.error( "First emoji validation check passed but second emoji validation check failed. How the fuck did you get here?", ) ->>>>>>> b8a4072 (added eletrons changes and fixed a warning) -======= - logger.error( - "First emoji validation check passed but second emoji validation check failed. How the fuck did you get here?", - ) ->>>>>>> 217c364 (fix(bookmarks): improve emoji validation and error handling for user and channel fetching) -======= ->>>>>>> 34798e9 (i think i fixed whatever the hell git just did) return async def _create_bookmark_embed( @@ -198,25 +106,6 @@ async def _create_bookmark_embed( embed.add_field(name="Author", value=message.author.name, inline=False) embed.add_field(name="Jump to Message", value=f"[Click Here]({message.jump_url})", inline=False) -<<<<<<< HEAD -<<<<<<< HEAD -======= - - embed.add_field( - name="Delete Bookmark", - value=f"React with {CONFIG.REMOVE_BOOKMARK[0]} to delete this bookmark.", - inline=False, - ) - -<<<<<<< HEAD -<<<<<<< HEAD ->>>>>>> b8a4072 (added eletrons changes and fixed a warning) -======= ->>>>>>> 217c364 (fix(bookmarks): improve emoji validation and error handling for user and channel fetching) -======= ->>>>>>> 34798e9 (i think i fixed whatever the hell git just did) -======= ->>>>>>> ba2c381 (chore(wip): still working on debugging) if message.attachments: attachments_info = "\n".join([attachment.url for attachment in message.attachments]) embed.add_field(name="Attachments", value=attachments_info, inline=False) @@ -224,22 +113,9 @@ async def _create_bookmark_embed( return embed async def _delete_bookmark(self, message: discord.Message, user: discord.User) -> None: -<<<<<<< HEAD -<<<<<<< HEAD - if message.author is not self.bot.user: - return - await message.delete() -======= - logger.debug("you got to the delte function") -======= ->>>>>>> 56bebaf (Added removing bookmarks from the bot's DMs) if message.author is not self.bot.user: return -<<<<<<< HEAD ->>>>>>> b9c797a (wip changes) -======= await message.delete() ->>>>>>> 56bebaf (Added removing bookmarks from the bot's DMs) @staticmethod async def _send_bookmark( From db0d5717adfe70e5784e73b589dad202feabd1e4 Mon Sep 17 00:00:00 2001 From: cherryl1k <102343489+cherryl1k@users.noreply.github.com> Date: Fri, 20 Jun 2025 13:58:31 -0500 Subject: [PATCH 25/37] feat:(bookmarks) cleaned up removing bookmarks --- tux/cogs/services/bookmarks.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tux/cogs/services/bookmarks.py b/tux/cogs/services/bookmarks.py index 80c74a04e..2404a0248 100644 --- a/tux/cogs/services/bookmarks.py +++ b/tux/cogs/services/bookmarks.py @@ -17,11 +17,11 @@ def __init__(self, bot: Tux) -> None: self.valid_remove_emojis = CONST.REMOVE_BOOKMARK self.valid_emojis = CONST.ADD_BOOKMARK + CONST.REMOVE_BOOKMARK - def _is_valid_emoji(self, emoji: discord.PartialEmoji, valid_list: list[int | str]) -> bool: - # Helper for checking if an emoji is in the list in "settings.yml -> BOOKMARK_EMOJIS" - if emoji.id is not None: - return emoji.id in valid_list - return emoji.name in valid_list + # The linter wants to change this but it breaks when it does that + def _is_valid_emoji(self, emoji: discord.PartialEmoji, valid_list: str) -> bool: + if emoji.name in valid_list: # noqa: SIM103 + return True + return False @commands.Cog.listener() async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> None: @@ -81,7 +81,7 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> # Send the bookmarked message to the user await self._send_bookmark(user, message, embed, payload.emoji) - elif self._is_valid_emoji(payload.emoji, self.valid_remove_emojis): + elif self._is_valid_emoji(payload.emoji, self.valid_remove_emojis) and user is not self.bot.user: await self._delete_bookmark(message, user) else: logger.error( @@ -109,7 +109,6 @@ async def _create_bookmark_embed( if message.attachments: attachments_info = "\n".join([attachment.url for attachment in message.attachments]) embed.add_field(name="Attachments", value=attachments_info, inline=False) - return embed async def _delete_bookmark(self, message: discord.Message, user: discord.User) -> None: From 8ceef67faaf0aa5951de4f504f5eff1a7f774761 Mon Sep 17 00:00:00 2001 From: cherryl1k <102343489+cherryl1k@users.noreply.github.com> Date: Fri, 20 Jun 2025 14:07:53 -0500 Subject: [PATCH 26/37] fix:(bookmarks) removed redundent error check --- tux/cogs/services/bookmarks.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tux/cogs/services/bookmarks.py b/tux/cogs/services/bookmarks.py index 2404a0248..806e8377a 100644 --- a/tux/cogs/services/bookmarks.py +++ b/tux/cogs/services/bookmarks.py @@ -84,9 +84,6 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> elif self._is_valid_emoji(payload.emoji, self.valid_remove_emojis) and user is not self.bot.user: await self._delete_bookmark(message, user) else: - logger.error( - "First emoji validation check passed but second emoji validation check failed. How the fuck did you get here?", - ) return async def _create_bookmark_embed( From 502cc5d3796f8d40aa6646e3207ad5291140f010 Mon Sep 17 00:00:00 2001 From: kzndotsh Date: Fri, 20 Jun 2025 23:06:44 -0400 Subject: [PATCH 27/37] chore: update Python version from 3.13.2 to 3.13.5 in documentation Update the Python version in the CONTRIBUTING.md and DOCKER.md files to 3.13.5. This ensures that the documentation reflects the latest stable version of Python being used in the project, which may include important bug fixes and improvements. Keeping the Python version up-to-date helps maintain compatibility and security across development and production environments. --- .github/CONTRIBUTING.md | 4 ++-- DOCKER.md | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 5efde12c4..4a5f91291 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -63,11 +63,11 @@ Follow these steps to set up your local development environment. For more compre 2. **Install Dependencies with Poetry** - Ensure Poetry is installed and configured to use the correct Python version (e.g., 3.13.2). + Ensure Poetry is installed and configured to use the correct Python version (e.g., 3.13.5). ```bash # Create a virtual environment - poetry env use 3.13.2 + poetry env use 3.13.5 # Install project dependencies and dev tools poetry install diff --git a/DOCKER.md b/DOCKER.md index 449243f7e..f2977ac1d 100644 --- a/DOCKER.md +++ b/DOCKER.md @@ -168,10 +168,10 @@ All tests validate against configurable thresholds: ### **Multi-Stage Dockerfile** ```dockerfile -FROM python:3.13.2-slim AS base # Common runtime base +FROM python:3.13.5-slim AS base # Common runtime base FROM base AS build # Build dependencies & tools FROM build AS dev # Development environment -FROM python:3.13.2-slim AS production # Minimal production runtime +FROM python:3.13.5-slim AS production # Minimal production runtime ``` ### **Key Features** @@ -523,7 +523,7 @@ docker system df docker images # Manual image restoration if needed -docker pull python:3.13.2-slim +docker pull python:3.13.5-slim docker pull ubuntu:22.04 ``` From d7542e072b0cad5149ccb848eadb2cdb24829e6c Mon Sep 17 00:00:00 2001 From: TargzBalls <102343489+targzballs@users.noreply.github.com> Date: Thu, 29 Aug 2024 00:34:17 -0500 Subject: [PATCH 28/37] Create bookmarks.py --- cogs/utility/bookmarks.py | 56 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 cogs/utility/bookmarks.py diff --git a/cogs/utility/bookmarks.py b/cogs/utility/bookmarks.py new file mode 100644 index 000000000..38ef58b37 --- /dev/null +++ b/cogs/utility/bookmarks.py @@ -0,0 +1,56 @@ +import discord +from discord.ext import commands +from loguru import logger + +from tux.utils.embeds import EmbedCreator + + +class Bookmarks(commands.Cog): + def __init__(self, bot: commands.Bot) -> None: + self.bot = bot + + @commands.Cog.listener() + async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> None: + if str(payload.emoji) == "🔖": + try: + channel = self.bot.get_channel(payload.channel_id) + if channel is None: + logger.error("Channel not found") + return + + message = await channel.fetch_message(payload.message_id) + if message is None: + logger.error("Message not found") + return + + embed = EmbedCreator.create_info_embed( + title="Message Bookmarked", + description=f"> {message.content}", + ) + embed.add_field(name="Author", value=message.author.name, inline=False) + embed.add_field(name="Jump to Message", value=f"[Click Here]({message.jump_url})", inline=False) + + if message.attachments: + attachments_info = "\n".join([attachment.url for attachment in message.attachments]) + embed.add_field(name="Attachments", value=attachments_info, inline=False) + + try: + user = self.bot.get_user(payload.user_id) + if user is not None: + await user.send(embed=embed) + await message.remove_reaction(payload.emoji, user) + else: + logger.error(f"User not found for ID: {payload.user_id}") + except (discord.Forbidden, discord.HTTPException): + logger.error(f"Cannot send a DM to {user.name}. They may have DMs turned off.") + await message.remove_reaction(payload.emoji, user) + temp_message = await channel.send( + f"{user.mention}, I couldn't send you a DM make sure your DMs are open for bookmarks to work", + ) + await temp_message.delete(delay=30) + except (discord.NotFound, discord.Forbidden, discord.HTTPException) as e: + logger.error(f"Failed to process the reaction: {e}") + + +async def setup(bot: commands.Bot) -> None: + await bot.add_cog(Bookmarks(bot)) From c5e51acb425d980dff1d00998628aa9a3203d255 Mon Sep 17 00:00:00 2001 From: cherryl1k <102343489+cherryl1k@users.noreply.github.com> Date: Mon, 9 Jun 2025 18:48:53 -0500 Subject: [PATCH 29/37] wip changes --- config/settings.yml.example | 8 ++++++++ tux/cogs/services/bookmarks.py | 27 +++++++++++++++++++++++++++ tux/utils/config.py | 4 ++++ 3 files changed, 39 insertions(+) diff --git a/config/settings.yml.example b/config/settings.yml.example index 111ecf375..719032fa6 100644 --- a/config/settings.yml.example +++ b/config/settings.yml.example @@ -114,3 +114,11 @@ GIF_LIMITER: # Limits the amount of gifs a user can send in a channel "123456789012345": 2 GIF_LIMITS_CHANNEL: "123456789012345": 3 + +BOOKMARK_EMOJIS: + ADD_BOOKMARK: # Unicode Emojis or Custom Server Emoji IDs + - "🔖" + # Custom Emoji example + # - 1274504955163709525 + REMOVE_BOOKMARK: # Unicode Emojis or Custom Server Emoji IDs (not reccomended) + - "🗑️" diff --git a/tux/cogs/services/bookmarks.py b/tux/cogs/services/bookmarks.py index 80c74a04e..c6a836888 100644 --- a/tux/cogs/services/bookmarks.py +++ b/tux/cogs/services/bookmarks.py @@ -6,6 +6,7 @@ from tux.bot import Tux from tux.ui.embeds import EmbedCreator +from tux.utils.config import CONFIG from tux.utils.constants import CONST @@ -13,9 +14,15 @@ class Bookmarks(commands.Cog): def __init__(self, bot: Tux) -> None: self.bot = bot +<<<<<<< HEAD self.valid_add_emojis = CONST.ADD_BOOKMARK self.valid_remove_emojis = CONST.REMOVE_BOOKMARK self.valid_emojis = CONST.ADD_BOOKMARK + CONST.REMOVE_BOOKMARK +======= + self.valid_emojis: list[int | str] = CONFIG.ADD_BOOKMARK + CONFIG.REMOVE_BOOKMARK + self.valid_add_emojis: list[int | str] = CONFIG.ADD_BOOKMARK + self.valid_remove_emojis: list[int | str] = CONFIG.REMOVE_BOOKMARK +>>>>>>> b9c797a (wip changes) def _is_valid_emoji(self, emoji: discord.PartialEmoji, valid_list: list[int | str]) -> bool: # Helper for checking if an emoji is in the list in "settings.yml -> BOOKMARK_EMOJIS" @@ -38,6 +45,15 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> None """ if not self._is_valid_emoji(payload.emoji, self.valid_emojis): +<<<<<<< HEAD +======= + return + + # Get the user who reacted to the message + user = self.bot.get_user(payload.user_id) + if user is None: + logger.error(f"User not found for ID: {payload.user_id}") +>>>>>>> b9c797a (wip changes) return # Get the user who reacted to the message @@ -84,9 +100,13 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> elif self._is_valid_emoji(payload.emoji, self.valid_remove_emojis): await self._delete_bookmark(message, user) else: +<<<<<<< HEAD logger.error( "First emoji validation check passed but second emoji validation check failed. How the fuck did you get here?", ) +======= + logger.debug("Somehow you managed to get bast the first valid emoji check then failed the 2nd good job?") +>>>>>>> b9c797a (wip changes) return async def _create_bookmark_embed( @@ -113,9 +133,16 @@ async def _create_bookmark_embed( return embed async def _delete_bookmark(self, message: discord.Message, user: discord.User) -> None: +<<<<<<< HEAD if message.author is not self.bot.user: return await message.delete() +======= + logger.debug("you got to the delte function") + if message.author is not self.bot.user: + logger.debug("not tux message") + return +>>>>>>> b9c797a (wip changes) @staticmethod async def _send_bookmark( diff --git a/tux/utils/config.py b/tux/utils/config.py index dd3cc7fc3..2394cee43 100644 --- a/tux/utils/config.py +++ b/tux/utils/config.py @@ -152,5 +152,9 @@ def BOT_TOKEN(self) -> str: # noqa: N802 LIMIT_TO_ROLE_IDS: Final[bool] = config["SNIPPETS"]["LIMIT_TO_ROLE_IDS"] ACCESS_ROLE_IDS: Final[list[int]] = config["SNIPPETS"]["ACCESS_ROLE_IDS"] + # Bookmark reactions + ADD_BOOKMARK: Final[list[int | str]] = config["BOOKMARK_EMOJIS"]["ADD_BOOKMARK"] + REMOVE_BOOKMARK: Final[list[int | str]] = config["BOOKMARK_EMOJIS"]["REMOVE_BOOKMARK"] + CONFIG = Config() From 18e4e343adebdfd862973a4d623a08697659b7c3 Mon Sep 17 00:00:00 2001 From: cherryl1k <102343489+cherryl1k@users.noreply.github.com> Date: Thu, 19 Jun 2025 12:33:27 -0500 Subject: [PATCH 30/37] Added removing bookmarks from the bot's DMs --- tux/cogs/services/bookmarks.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tux/cogs/services/bookmarks.py b/tux/cogs/services/bookmarks.py index c6a836888..bf0d8af59 100644 --- a/tux/cogs/services/bookmarks.py +++ b/tux/cogs/services/bookmarks.py @@ -100,6 +100,7 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> elif self._is_valid_emoji(payload.emoji, self.valid_remove_emojis): await self._delete_bookmark(message, user) else: +<<<<<<< HEAD <<<<<<< HEAD logger.error( "First emoji validation check passed but second emoji validation check failed. How the fuck did you get here?", @@ -107,6 +108,9 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> ======= logger.debug("Somehow you managed to get bast the first valid emoji check then failed the 2nd good job?") >>>>>>> b9c797a (wip changes) +======= + logger.error("How did you fail the 2nd check but passed the first?") +>>>>>>> 56bebaf (Added removing bookmarks from the bot's DMs) return async def _create_bookmark_embed( @@ -133,16 +137,22 @@ async def _create_bookmark_embed( return embed async def _delete_bookmark(self, message: discord.Message, user: discord.User) -> None: +<<<<<<< HEAD <<<<<<< HEAD if message.author is not self.bot.user: return await message.delete() ======= logger.debug("you got to the delte function") +======= +>>>>>>> 56bebaf (Added removing bookmarks from the bot's DMs) if message.author is not self.bot.user: - logger.debug("not tux message") return +<<<<<<< HEAD >>>>>>> b9c797a (wip changes) +======= + await message.delete() +>>>>>>> 56bebaf (Added removing bookmarks from the bot's DMs) @staticmethod async def _send_bookmark( From bc36aba9bbae2bce14c9ca98f848f7599a3f5dc0 Mon Sep 17 00:00:00 2001 From: cherryl1k <102343489+cherryl1k@users.noreply.github.com> Date: Thu, 19 Jun 2025 14:32:38 -0500 Subject: [PATCH 31/37] added eletrons changes and fixed a warning --- config/settings.yml.example | 7 ++-- tux/cogs/services/bookmarks.py | 59 ++++++++++++++++++++++++++++++++-- 2 files changed, 59 insertions(+), 7 deletions(-) diff --git a/config/settings.yml.example b/config/settings.yml.example index 719032fa6..4433f9eb7 100644 --- a/config/settings.yml.example +++ b/config/settings.yml.example @@ -116,9 +116,8 @@ GIF_LIMITER: # Limits the amount of gifs a user can send in a channel "123456789012345": 3 BOOKMARK_EMOJIS: - ADD_BOOKMARK: # Unicode Emojis or Custom Server Emoji IDs + ADD_BOOKMARK: - "🔖" - # Custom Emoji example - # - 1274504955163709525 - REMOVE_BOOKMARK: # Unicode Emojis or Custom Server Emoji IDs (not reccomended) + #- 123456789012345 # Custom emoji example, replace with emoji id + REMOVE_BOOKMARK: # Do not use custom emojis for this. - "🗑️" diff --git a/tux/cogs/services/bookmarks.py b/tux/cogs/services/bookmarks.py index bf0d8af59..c2f798294 100644 --- a/tux/cogs/services/bookmarks.py +++ b/tux/cogs/services/bookmarks.py @@ -26,9 +26,7 @@ def __init__(self, bot: Tux) -> None: def _is_valid_emoji(self, emoji: discord.PartialEmoji, valid_list: list[int | str]) -> bool: # Helper for checking if an emoji is in the list in "settings.yml -> BOOKMARK_EMOJIS" - if emoji.id is not None: - return emoji.id in valid_list - return emoji.name in valid_list + return emoji.name in valid_list if emoji.id is None else emoji.id in valid_list @commands.Cog.listener() async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> None: @@ -52,6 +50,7 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> # Get the user who reacted to the message user = self.bot.get_user(payload.user_id) if user is None: +<<<<<<< HEAD logger.error(f"User not found for ID: {payload.user_id}") >>>>>>> b9c797a (wip changes) return @@ -66,6 +65,25 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> except (discord.Forbidden, discord.HTTPException) as fetch_error: logger.error(f"Failed to fetch user: {fetch_error}") return +<<<<<<< HEAD +======= +======= + return + except (discord.Forbidden, discord.HTTPException) as fetch_error: + logger.error(f"Failed to fetch user: {fetch_error}") + return + +>>>>>>> 217c364 (fix(bookmarks): improve emoji validation and error handling for user and channel fetching) +======= + try: + user = await self.bot.fetch_user(payload.user_id) + except discord.NotFound: + logger.error(f"User not found for ID: {payload.user_id}") + except (discord.Forbidden, discord.HTTPException) as fetch_error: + logger.error(f"Failed to fetch user: {fetch_error}") + return +>>>>>>> b8a4072 (added eletrons changes and fixed a warning) +>>>>>>> dc15ffe (added eletrons changes and fixed a warning) # Fetch the channel where the reaction was added channel = self.bot.get_channel(payload.channel_id) if channel is None: @@ -73,10 +91,29 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> channel = await self.bot.fetch_channel(payload.channel_id) except discord.NotFound: logger.error(f"Channel not found for ID: {payload.channel_id}") +<<<<<<< HEAD +======= +<<<<<<< HEAD +<<<<<<< HEAD +======= +>>>>>>> b8a4072 (added eletrons changes and fixed a warning) +>>>>>>> dc15ffe (added eletrons changes and fixed a warning) except (discord.Forbidden, discord.HTTPException) as fetch_error: logger.error(f"Failed to fetch channel: {fetch_error}") return +<<<<<<< HEAD +======= +<<<<<<< HEAD +======= + return + except (discord.Forbidden, discord.HTTPException) as fetch_error: + logger.error(f"Failed to fetch channel: {fetch_error}") + return +>>>>>>> 217c364 (fix(bookmarks): improve emoji validation and error handling for user and channel fetching) +======= +>>>>>>> b8a4072 (added eletrons changes and fixed a warning) +>>>>>>> dc15ffe (added eletrons changes and fixed a warning) channel = cast(discord.TextChannel | discord.Thread, channel) # Fetch the message that was reacted to @@ -101,6 +138,7 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> await self._delete_bookmark(message, user) else: <<<<<<< HEAD +<<<<<<< HEAD <<<<<<< HEAD logger.error( "First emoji validation check passed but second emoji validation check failed. How the fuck did you get here?", @@ -111,6 +149,11 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> ======= logger.error("How did you fail the 2nd check but passed the first?") >>>>>>> 56bebaf (Added removing bookmarks from the bot's DMs) +======= + logger.error( + "First emoji validation check passed but second emoji validation check failed. How the fuck did you get here?", + ) +>>>>>>> b8a4072 (added eletrons changes and fixed a warning) return async def _create_bookmark_embed( @@ -130,6 +173,16 @@ async def _create_bookmark_embed( embed.add_field(name="Author", value=message.author.name, inline=False) embed.add_field(name="Jump to Message", value=f"[Click Here]({message.jump_url})", inline=False) +<<<<<<< HEAD +======= + + embed.add_field( + name="Delete Bookmark", + value=f"React with {CONFIG.REMOVE_BOOKMARK[0]} to delete this bookmark.", + inline=False, + ) + +>>>>>>> b8a4072 (added eletrons changes and fixed a warning) if message.attachments: attachments_info = "\n".join([attachment.url for attachment in message.attachments]) embed.add_field(name="Attachments", value=attachments_info, inline=False) From 23ace84ced7e05598474864e71c30baa0927866a Mon Sep 17 00:00:00 2001 From: electron271 <66094410+electron271@users.noreply.github.com> Date: Thu, 19 Jun 2025 14:08:52 -0500 Subject: [PATCH 32/37] fix(bookmarks): improve emoji validation and error handling for user and channel fetching --- tux/cogs/services/bookmarks.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tux/cogs/services/bookmarks.py b/tux/cogs/services/bookmarks.py index c2f798294..0223173d6 100644 --- a/tux/cogs/services/bookmarks.py +++ b/tux/cogs/services/bookmarks.py @@ -50,10 +50,21 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> # Get the user who reacted to the message user = self.bot.get_user(payload.user_id) if user is None: +<<<<<<< HEAD <<<<<<< HEAD logger.error(f"User not found for ID: {payload.user_id}") >>>>>>> b9c797a (wip changes) return +======= + try: + user = await self.bot.fetch_user(payload.user_id) + except discord.NotFound: + logger.error(f"User not found for ID: {payload.user_id}") + return + except (discord.Forbidden, discord.HTTPException) as fetch_error: + logger.error(f"Failed to fetch user: {fetch_error}") + return +>>>>>>> 217c364 (fix(bookmarks): improve emoji validation and error handling for user and channel fetching) # Get the user who reacted to the message user = self.bot.get_user(payload.user_id) @@ -95,6 +106,7 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> ======= <<<<<<< HEAD <<<<<<< HEAD +<<<<<<< HEAD ======= >>>>>>> b8a4072 (added eletrons changes and fixed a warning) >>>>>>> dc15ffe (added eletrons changes and fixed a warning) @@ -105,15 +117,26 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> <<<<<<< HEAD ======= <<<<<<< HEAD +<<<<<<< HEAD +======= +======= ======= +>>>>>>> 217c364 (fix(bookmarks): improve emoji validation and error handling for user and channel fetching) +>>>>>>> 38f9809 (fix(bookmarks): improve emoji validation and error handling for user and channel fetching) return except (discord.Forbidden, discord.HTTPException) as fetch_error: logger.error(f"Failed to fetch channel: {fetch_error}") return +<<<<<<< HEAD >>>>>>> 217c364 (fix(bookmarks): improve emoji validation and error handling for user and channel fetching) ======= >>>>>>> b8a4072 (added eletrons changes and fixed a warning) +<<<<<<< HEAD >>>>>>> dc15ffe (added eletrons changes and fixed a warning) +======= +======= +>>>>>>> 217c364 (fix(bookmarks): improve emoji validation and error handling for user and channel fetching) +>>>>>>> 38f9809 (fix(bookmarks): improve emoji validation and error handling for user and channel fetching) channel = cast(discord.TextChannel | discord.Thread, channel) # Fetch the message that was reacted to @@ -139,6 +162,7 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> else: <<<<<<< HEAD <<<<<<< HEAD +<<<<<<< HEAD <<<<<<< HEAD logger.error( "First emoji validation check passed but second emoji validation check failed. How the fuck did you get here?", @@ -154,6 +178,11 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> "First emoji validation check passed but second emoji validation check failed. How the fuck did you get here?", ) >>>>>>> b8a4072 (added eletrons changes and fixed a warning) +======= + logger.error( + "First emoji validation check passed but second emoji validation check failed. How the fuck did you get here?", + ) +>>>>>>> 217c364 (fix(bookmarks): improve emoji validation and error handling for user and channel fetching) return async def _create_bookmark_embed( @@ -182,7 +211,10 @@ async def _create_bookmark_embed( inline=False, ) +<<<<<<< HEAD >>>>>>> b8a4072 (added eletrons changes and fixed a warning) +======= +>>>>>>> 217c364 (fix(bookmarks): improve emoji validation and error handling for user and channel fetching) if message.attachments: attachments_info = "\n".join([attachment.url for attachment in message.attachments]) embed.add_field(name="Attachments", value=attachments_info, inline=False) From e8c16a05de8a77d07bffafb4aa1c185899a36fde Mon Sep 17 00:00:00 2001 From: cherryl1k <102343489+cherryl1k@users.noreply.github.com> Date: Thu, 19 Jun 2025 14:38:53 -0500 Subject: [PATCH 33/37] i think i fixed whatever the hell git just did --- tux/cogs/services/bookmarks.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tux/cogs/services/bookmarks.py b/tux/cogs/services/bookmarks.py index 0223173d6..6aee9202a 100644 --- a/tux/cogs/services/bookmarks.py +++ b/tux/cogs/services/bookmarks.py @@ -167,6 +167,7 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> logger.error( "First emoji validation check passed but second emoji validation check failed. How the fuck did you get here?", ) +<<<<<<< HEAD ======= logger.debug("Somehow you managed to get bast the first valid emoji check then failed the 2nd good job?") >>>>>>> b9c797a (wip changes) @@ -183,6 +184,8 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> "First emoji validation check passed but second emoji validation check failed. How the fuck did you get here?", ) >>>>>>> 217c364 (fix(bookmarks): improve emoji validation and error handling for user and channel fetching) +======= +>>>>>>> 34798e9 (i think i fixed whatever the hell git just did) return async def _create_bookmark_embed( @@ -211,10 +214,13 @@ async def _create_bookmark_embed( inline=False, ) +<<<<<<< HEAD <<<<<<< HEAD >>>>>>> b8a4072 (added eletrons changes and fixed a warning) ======= >>>>>>> 217c364 (fix(bookmarks): improve emoji validation and error handling for user and channel fetching) +======= +>>>>>>> 34798e9 (i think i fixed whatever the hell git just did) if message.attachments: attachments_info = "\n".join([attachment.url for attachment in message.attachments]) embed.add_field(name="Attachments", value=attachments_info, inline=False) From 0a672c6fbda225573d0f1e63bc0ce815b8d1121e Mon Sep 17 00:00:00 2001 From: cherryl1k <102343489+cherryl1k@users.noreply.github.com> Date: Fri, 20 Jun 2025 12:11:09 -0500 Subject: [PATCH 34/37] chore(wip): still working on debugging --- config/settings.yml.example | 7 ------- tux/cogs/services/bookmarks.py | 14 ++++++++++++-- tux/utils/config.py | 4 ---- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/config/settings.yml.example b/config/settings.yml.example index 4433f9eb7..111ecf375 100644 --- a/config/settings.yml.example +++ b/config/settings.yml.example @@ -114,10 +114,3 @@ GIF_LIMITER: # Limits the amount of gifs a user can send in a channel "123456789012345": 2 GIF_LIMITS_CHANNEL: "123456789012345": 3 - -BOOKMARK_EMOJIS: - ADD_BOOKMARK: - - "🔖" - #- 123456789012345 # Custom emoji example, replace with emoji id - REMOVE_BOOKMARK: # Do not use custom emojis for this. - - "🗑️" diff --git a/tux/cogs/services/bookmarks.py b/tux/cogs/services/bookmarks.py index 6aee9202a..d3ff23f70 100644 --- a/tux/cogs/services/bookmarks.py +++ b/tux/cogs/services/bookmarks.py @@ -6,7 +6,6 @@ from tux.bot import Tux from tux.ui.embeds import EmbedCreator -from tux.utils.config import CONFIG from tux.utils.constants import CONST @@ -14,6 +13,7 @@ class Bookmarks(commands.Cog): def __init__(self, bot: Tux) -> None: self.bot = bot +<<<<<<< HEAD <<<<<<< HEAD self.valid_add_emojis = CONST.ADD_BOOKMARK self.valid_remove_emojis = CONST.REMOVE_BOOKMARK @@ -23,10 +23,17 @@ def __init__(self, bot: Tux) -> None: self.valid_add_emojis: list[int | str] = CONFIG.ADD_BOOKMARK self.valid_remove_emojis: list[int | str] = CONFIG.REMOVE_BOOKMARK >>>>>>> b9c797a (wip changes) +======= + self.valid_add_emojis = CONST.ADD_BOOKMARK + self.valid_remove_emojis = CONST.REMOVE_BOOKMARK + self.valid_emojis = CONST.ADD_BOOKMARK + CONST.REMOVE_BOOKMARK +>>>>>>> ba2c381 (chore(wip): still working on debugging) def _is_valid_emoji(self, emoji: discord.PartialEmoji, valid_list: list[int | str]) -> bool: # Helper for checking if an emoji is in the list in "settings.yml -> BOOKMARK_EMOJIS" - return emoji.name in valid_list if emoji.id is None else emoji.id in valid_list + if emoji.id is not None: + return emoji.id in valid_list + return emoji.name in valid_list @commands.Cog.listener() async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> None: @@ -206,6 +213,7 @@ async def _create_bookmark_embed( embed.add_field(name="Jump to Message", value=f"[Click Here]({message.jump_url})", inline=False) <<<<<<< HEAD +<<<<<<< HEAD ======= embed.add_field( @@ -221,6 +229,8 @@ async def _create_bookmark_embed( >>>>>>> 217c364 (fix(bookmarks): improve emoji validation and error handling for user and channel fetching) ======= >>>>>>> 34798e9 (i think i fixed whatever the hell git just did) +======= +>>>>>>> ba2c381 (chore(wip): still working on debugging) if message.attachments: attachments_info = "\n".join([attachment.url for attachment in message.attachments]) embed.add_field(name="Attachments", value=attachments_info, inline=False) diff --git a/tux/utils/config.py b/tux/utils/config.py index 2394cee43..dd3cc7fc3 100644 --- a/tux/utils/config.py +++ b/tux/utils/config.py @@ -152,9 +152,5 @@ def BOT_TOKEN(self) -> str: # noqa: N802 LIMIT_TO_ROLE_IDS: Final[bool] = config["SNIPPETS"]["LIMIT_TO_ROLE_IDS"] ACCESS_ROLE_IDS: Final[list[int]] = config["SNIPPETS"]["ACCESS_ROLE_IDS"] - # Bookmark reactions - ADD_BOOKMARK: Final[list[int | str]] = config["BOOKMARK_EMOJIS"]["ADD_BOOKMARK"] - REMOVE_BOOKMARK: Final[list[int | str]] = config["BOOKMARK_EMOJIS"]["REMOVE_BOOKMARK"] - CONFIG = Config() From fbe4d0f31a8746997e3de2e611c3b999ebe96bfa Mon Sep 17 00:00:00 2001 From: cherryl1k <102343489+cherryl1k@users.noreply.github.com> Date: Fri, 20 Jun 2025 12:55:25 -0500 Subject: [PATCH 35/37] chore(wip): still working on debugging --- tux/cogs/services/bookmarks.py | 81 +++++----------------------------- 1 file changed, 12 insertions(+), 69 deletions(-) diff --git a/tux/cogs/services/bookmarks.py b/tux/cogs/services/bookmarks.py index d3ff23f70..a7fc9a990 100644 --- a/tux/cogs/services/bookmarks.py +++ b/tux/cogs/services/bookmarks.py @@ -13,21 +13,9 @@ class Bookmarks(commands.Cog): def __init__(self, bot: Tux) -> None: self.bot = bot -<<<<<<< HEAD -<<<<<<< HEAD - self.valid_add_emojis = CONST.ADD_BOOKMARK - self.valid_remove_emojis = CONST.REMOVE_BOOKMARK - self.valid_emojis = CONST.ADD_BOOKMARK + CONST.REMOVE_BOOKMARK -======= - self.valid_emojis: list[int | str] = CONFIG.ADD_BOOKMARK + CONFIG.REMOVE_BOOKMARK - self.valid_add_emojis: list[int | str] = CONFIG.ADD_BOOKMARK - self.valid_remove_emojis: list[int | str] = CONFIG.REMOVE_BOOKMARK ->>>>>>> b9c797a (wip changes) -======= self.valid_add_emojis = CONST.ADD_BOOKMARK self.valid_remove_emojis = CONST.REMOVE_BOOKMARK self.valid_emojis = CONST.ADD_BOOKMARK + CONST.REMOVE_BOOKMARK ->>>>>>> ba2c381 (chore(wip): still working on debugging) def _is_valid_emoji(self, emoji: discord.PartialEmoji, valid_list: list[int | str]) -> bool: # Helper for checking if an emoji is in the list in "settings.yml -> BOOKMARK_EMOJIS" @@ -50,14 +38,13 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> None """ if not self._is_valid_emoji(payload.emoji, self.valid_emojis): -<<<<<<< HEAD -======= return # Get the user who reacted to the message user = self.bot.get_user(payload.user_id) if user is None: <<<<<<< HEAD +<<<<<<< HEAD <<<<<<< HEAD logger.error(f"User not found for ID: {payload.user_id}") >>>>>>> b9c797a (wip changes) @@ -93,6 +80,8 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> >>>>>>> 217c364 (fix(bookmarks): improve emoji validation and error handling for user and channel fetching) ======= +======= +>>>>>>> 36a5db6 (chore(wip): still working on debugging) try: user = await self.bot.fetch_user(payload.user_id) except discord.NotFound: @@ -100,8 +89,11 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> except (discord.Forbidden, discord.HTTPException) as fetch_error: logger.error(f"Failed to fetch user: {fetch_error}") return +<<<<<<< HEAD >>>>>>> b8a4072 (added eletrons changes and fixed a warning) >>>>>>> dc15ffe (added eletrons changes and fixed a warning) +======= +>>>>>>> 36a5db6 (chore(wip): still working on debugging) # Fetch the channel where the reaction was added channel = self.bot.get_channel(payload.channel_id) if channel is None: @@ -110,6 +102,7 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> except discord.NotFound: logger.error(f"Channel not found for ID: {payload.channel_id}") <<<<<<< HEAD +<<<<<<< HEAD ======= <<<<<<< HEAD <<<<<<< HEAD @@ -117,10 +110,13 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> ======= >>>>>>> b8a4072 (added eletrons changes and fixed a warning) >>>>>>> dc15ffe (added eletrons changes and fixed a warning) +======= +>>>>>>> 36a5db6 (chore(wip): still working on debugging) except (discord.Forbidden, discord.HTTPException) as fetch_error: logger.error(f"Failed to fetch channel: {fetch_error}") return +<<<<<<< HEAD <<<<<<< HEAD ======= <<<<<<< HEAD @@ -144,6 +140,8 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> ======= >>>>>>> 217c364 (fix(bookmarks): improve emoji validation and error handling for user and channel fetching) >>>>>>> 38f9809 (fix(bookmarks): improve emoji validation and error handling for user and channel fetching) +======= +>>>>>>> 36a5db6 (chore(wip): still working on debugging) channel = cast(discord.TextChannel | discord.Thread, channel) # Fetch the message that was reacted to @@ -167,32 +165,9 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> elif self._is_valid_emoji(payload.emoji, self.valid_remove_emojis): await self._delete_bookmark(message, user) else: -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - logger.error( - "First emoji validation check passed but second emoji validation check failed. How the fuck did you get here?", - ) -<<<<<<< HEAD -======= - logger.debug("Somehow you managed to get bast the first valid emoji check then failed the 2nd good job?") ->>>>>>> b9c797a (wip changes) -======= - logger.error("How did you fail the 2nd check but passed the first?") ->>>>>>> 56bebaf (Added removing bookmarks from the bot's DMs) -======= logger.error( "First emoji validation check passed but second emoji validation check failed. How the fuck did you get here?", ) ->>>>>>> b8a4072 (added eletrons changes and fixed a warning) -======= - logger.error( - "First emoji validation check passed but second emoji validation check failed. How the fuck did you get here?", - ) ->>>>>>> 217c364 (fix(bookmarks): improve emoji validation and error handling for user and channel fetching) -======= ->>>>>>> 34798e9 (i think i fixed whatever the hell git just did) return async def _create_bookmark_embed( @@ -212,25 +187,6 @@ async def _create_bookmark_embed( embed.add_field(name="Author", value=message.author.name, inline=False) embed.add_field(name="Jump to Message", value=f"[Click Here]({message.jump_url})", inline=False) -<<<<<<< HEAD -<<<<<<< HEAD -======= - - embed.add_field( - name="Delete Bookmark", - value=f"React with {CONFIG.REMOVE_BOOKMARK[0]} to delete this bookmark.", - inline=False, - ) - -<<<<<<< HEAD -<<<<<<< HEAD ->>>>>>> b8a4072 (added eletrons changes and fixed a warning) -======= ->>>>>>> 217c364 (fix(bookmarks): improve emoji validation and error handling for user and channel fetching) -======= ->>>>>>> 34798e9 (i think i fixed whatever the hell git just did) -======= ->>>>>>> ba2c381 (chore(wip): still working on debugging) if message.attachments: attachments_info = "\n".join([attachment.url for attachment in message.attachments]) embed.add_field(name="Attachments", value=attachments_info, inline=False) @@ -238,22 +194,9 @@ async def _create_bookmark_embed( return embed async def _delete_bookmark(self, message: discord.Message, user: discord.User) -> None: -<<<<<<< HEAD -<<<<<<< HEAD if message.author is not self.bot.user: return await message.delete() -======= - logger.debug("you got to the delte function") -======= ->>>>>>> 56bebaf (Added removing bookmarks from the bot's DMs) - if message.author is not self.bot.user: - return -<<<<<<< HEAD ->>>>>>> b9c797a (wip changes) -======= - await message.delete() ->>>>>>> 56bebaf (Added removing bookmarks from the bot's DMs) @staticmethod async def _send_bookmark( From 47f5a9b29e6778a047330c09463be2369e2e2246 Mon Sep 17 00:00:00 2001 From: cherryl1k <102343489+cherryl1k@users.noreply.github.com> Date: Fri, 20 Jun 2025 13:58:31 -0500 Subject: [PATCH 36/37] feat:(bookmarks) cleaned up removing bookmarks --- tux/cogs/services/bookmarks.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tux/cogs/services/bookmarks.py b/tux/cogs/services/bookmarks.py index a7fc9a990..1e042c3c8 100644 --- a/tux/cogs/services/bookmarks.py +++ b/tux/cogs/services/bookmarks.py @@ -17,11 +17,11 @@ def __init__(self, bot: Tux) -> None: self.valid_remove_emojis = CONST.REMOVE_BOOKMARK self.valid_emojis = CONST.ADD_BOOKMARK + CONST.REMOVE_BOOKMARK - def _is_valid_emoji(self, emoji: discord.PartialEmoji, valid_list: list[int | str]) -> bool: - # Helper for checking if an emoji is in the list in "settings.yml -> BOOKMARK_EMOJIS" - if emoji.id is not None: - return emoji.id in valid_list - return emoji.name in valid_list + # The linter wants to change this but it breaks when it does that + def _is_valid_emoji(self, emoji: discord.PartialEmoji, valid_list: str) -> bool: + if emoji.name in valid_list: # noqa: SIM103 + return True + return False @commands.Cog.listener() async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> None: @@ -162,7 +162,7 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> # Send the bookmarked message to the user await self._send_bookmark(user, message, embed, payload.emoji) - elif self._is_valid_emoji(payload.emoji, self.valid_remove_emojis): + elif self._is_valid_emoji(payload.emoji, self.valid_remove_emojis) and user is not self.bot.user: await self._delete_bookmark(message, user) else: logger.error( @@ -190,7 +190,6 @@ async def _create_bookmark_embed( if message.attachments: attachments_info = "\n".join([attachment.url for attachment in message.attachments]) embed.add_field(name="Attachments", value=attachments_info, inline=False) - return embed async def _delete_bookmark(self, message: discord.Message, user: discord.User) -> None: From 9a3f537e9fed9d8bb9b8a31d4e7a5c6dd8c0b467 Mon Sep 17 00:00:00 2001 From: cherryl1k <102343489+cherryl1k@users.noreply.github.com> Date: Fri, 20 Jun 2025 14:07:53 -0500 Subject: [PATCH 37/37] fix:(bookmarks) removed redundent error check --- tux/cogs/services/bookmarks.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tux/cogs/services/bookmarks.py b/tux/cogs/services/bookmarks.py index 1e042c3c8..8c927d243 100644 --- a/tux/cogs/services/bookmarks.py +++ b/tux/cogs/services/bookmarks.py @@ -165,9 +165,6 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> elif self._is_valid_emoji(payload.emoji, self.valid_remove_emojis) and user is not self.bot.user: await self._delete_bookmark(message, user) else: - logger.error( - "First emoji validation check passed but second emoji validation check failed. How the fuck did you get here?", - ) return async def _create_bookmark_embed(