From de8b1418ad30f550e0830a8db1ca1b00e6046768 Mon Sep 17 00:00:00 2001 From: achyu-dev Date: Thu, 25 Sep 2025 18:56:35 +0000 Subject: [PATCH 1/6] updated with latest githooks etc --- cogs/events/general.py | 192 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 190 insertions(+), 2 deletions(-) diff --git a/cogs/events/general.py b/cogs/events/general.py index 6c0a0ed..571f6f1 100644 --- a/cogs/events/general.py +++ b/cogs/events/general.py @@ -87,7 +87,9 @@ async def on_member_join(self, member: discord.Member) -> None: just_joined = self.client.config.just_joined_role await bot_logs.send(f"{member.mention} Joined!!") - link_record = await self.client.link_collection.find_one({"userId": str(member.id)}) + link_record = await self.client.link_collection.find_one( + {"userId": str(member.id)} + ) roles_to_add = [just_joined] should_delete_link = bool(link_record and not link_record.get("linkedAt")) @@ -146,9 +148,195 @@ async def on_message(self, message: discord.Message) -> None: @commands.Cog.listener() async def on_message_delete(self, message: discord.Message) -> None: - if message.author.bot: + if message.author.bot and message.author.id != self.client.user.id: + # Only process if it's an anon message + if not (message.embeds and message.embeds[0].title == "Anon Message"): + return + # Ignore all other bots return + print("Testing......") + + # Check if this is a reply to an anon message + if message.reference and message.reference.message_id: + await self._handle_anon_reply_deletion(message) + + # Handle ghost ping detection + await self._handle_ghost_ping_detection(message) + + async def _handle_anon_reply_deletion(self, message: discord.Message) -> None: + """Handle deletion of replies to anon messages.""" + try: + replied_message = await message.channel.fetch_message(message.reference.message_id) + + if not self._is_anon_message(replied_message): + return + + original_sender_id = await self._find_original_anon_sender(replied_message) + if not original_sender_id: + return + + current_sender_id = await self._get_current_message_sender_id(message) + + # If we found the original sender and they're different from current sender + if original_sender_id != current_sender_id: + await self._notify_original_sender(message, original_sender_id, current_sender_id) + + except (discord.NotFound, discord.Forbidden, discord.HTTPException): + # Could not fetch the replied message + pass + + def _is_anon_message(self, message: discord.Message) -> bool: + """Check if a message is an anon message.""" + return (message.author == self.client.user and + message.embeds and + message.embeds[0].title == "Anon Message") + + async def _find_original_anon_sender(self, replied_message: discord.Message) -> str | None: + """Find the original sender of an anon message.""" + anon_cog = self.client.get_cog("SlashAnon") + if not (anon_cog and hasattr(anon_cog, "anon_cache")): + return None + + for user_id, messages in anon_cog.anon_cache.items(): + if any(str(replied_message.id) == msg["message_id"] for msg in messages): + return user_id + return None + + async def _get_current_message_sender_id(self, message: discord.Message) -> str | None: + """Get the sender ID of the current message if it's anon.""" + is_current_anon = self._is_anon_message(message) + print(f"is_current_anon: {is_current_anon}") + + if not is_current_anon: + return None + + anon_cog = self.client.get_cog("SlashAnon") + if not (anon_cog and hasattr(anon_cog, "anon_cache")): + return None + + for user_id, messages in anon_cog.anon_cache.items(): + if any(str(message.id) == msg["message_id"] for msg in messages): + return user_id + return None + + async def _notify_original_sender( + self, + message: discord.Message, + original_sender_id: str, + current_sender_id: str | None + ) -> None: + """Notify the original anon sender about a reply.""" + try: + original_sender = await self.client.fetch_user(int(original_sender_id)) + if not original_sender: + return + + if not await self._should_notify_user(original_sender_id): + return + + is_current_anon = current_sender_id is not None + reply_type = "anon user" if is_current_anon else message.author.display_name + print(f"reply_type: {reply_type}") + + embed = self._create_reply_notification_embed(message, reply_type, is_current_anon) + view = await self._create_notification_toggle_view(original_sender) + + await original_sender.send(embed=embed, view=view) + + except (discord.Forbidden, discord.HTTPException, discord.NotFound): + # Could not send DM to user + pass + + async def _should_notify_user(self, user_id: str) -> bool: + """Check if user should receive notifications.""" + link_record = await self.client.link_collection.find_one({"userId": user_id}) + return not link_record or link_record.get("anon_notifications", True) + + def _create_reply_notification_embed( + self, + message: discord.Message, + reply_type: str, + is_current_anon: bool + ) -> discord.Embed: + """Create the notification embed for reply notifications.""" + description = ( + f"An {reply_type} replied to your anon message" + if is_current_anon + else f"{reply_type} replied to your anon message" + ) + + embed = discord.Embed( + title="Reply to Your Anon Message", + description=description, + color=discord.Color.blue() + ) + embed.add_field( + name="Jump to Reply", + value=f"[Click here to view the reply]({message.jump_url})", + inline=False + ) + embed.set_footer(text="PESU Bot") + embed.timestamp = discord.utils.utcnow() + return embed + + async def _create_notification_toggle_view(self, original_sender: discord.User) -> discord.ui.View: + """Create the view with notification toggle button.""" + link_record = await self.client.link_collection.find_one({"userId": str(original_sender.id)}) + is_subscribed = link_record.get("anon_notifications", True) if link_record else True + + print(f"link_record: {link_record}") + print(f"is_subscribed: {is_subscribed}") + print(f"Button label: {'Unsubscribe from notifications' if is_subscribed else 'Subscribe to notifications'}") + + view = discord.ui.View() + toggle_button = discord.ui.Button( + label="Unsubscribe from notifications" if is_subscribed else "Subscribe to notifications", + style=discord.ButtonStyle.secondary if is_subscribed else discord.ButtonStyle.primary, + custom_id=f"toggle_anon_notifications_{original_sender.id}", + ) + + async def toggle_callback(interaction: discord.Interaction) -> None: + await self._handle_notification_toggle(interaction, original_sender) + + toggle_button.callback = toggle_callback + view.add_item(toggle_button) + return view + + async def _handle_notification_toggle( + self, + interaction: discord.Interaction, + original_sender: discord.User + ) -> None: + """Handle the notification toggle button callback.""" + if interaction.user.id != original_sender.id: + return + + # Check current status + current_record = await self.client.db["anon_notifications"].find_one( + {"userId": str(original_sender.id)} + ) + + currently_subscribed = not (current_record and not current_record.get("subscribed")) + + # Toggle status + new_status = not currently_subscribed + await self.client.link_collection.update_one( + {"userId": str(original_sender.id)}, + {"$set": {"anon_notifications": new_status}}, + ) + + message = ( + "✅ You have been subscribed to anon reply notifications." + if new_status + else "❌ You have been unsubscribed from anon reply notifications." + ) + + await interaction.response.send_message(message, ephemeral=True) + print(f"Toggled subscription for user {original_sender.id} to {new_status}") + + async def _handle_ghost_ping_detection(self, message: discord.Message) -> None: + """Handle ghost ping detection for deleted messages.""" mentions = message.mentions role_mentions = message.role_mentions From 51426c3ef21f1bd37c9b2525f36463f4bc7387a0 Mon Sep 17 00:00:00 2001 From: achyu-dev Date: Thu, 25 Sep 2025 19:19:37 +0000 Subject: [PATCH 2/6] minor ruff format --- cogs/events/general.py | 38 ++++++++------------------------------ 1 file changed, 8 insertions(+), 30 deletions(-) diff --git a/cogs/events/general.py b/cogs/events/general.py index 571f6f1..a27dc36 100644 --- a/cogs/events/general.py +++ b/cogs/events/general.py @@ -87,9 +87,7 @@ async def on_member_join(self, member: discord.Member) -> None: just_joined = self.client.config.just_joined_role await bot_logs.send(f"{member.mention} Joined!!") - link_record = await self.client.link_collection.find_one( - {"userId": str(member.id)} - ) + link_record = await self.client.link_collection.find_one({"userId": str(member.id)}) roles_to_add = [just_joined] should_delete_link = bool(link_record and not link_record.get("linkedAt")) @@ -188,9 +186,7 @@ async def _handle_anon_reply_deletion(self, message: discord.Message) -> None: def _is_anon_message(self, message: discord.Message) -> bool: """Check if a message is an anon message.""" - return (message.author == self.client.user and - message.embeds and - message.embeds[0].title == "Anon Message") + return message.author == self.client.user and message.embeds and message.embeds[0].title == "Anon Message" async def _find_original_anon_sender(self, replied_message: discord.Message) -> str | None: """Find the original sender of an anon message.""" @@ -221,10 +217,7 @@ async def _get_current_message_sender_id(self, message: discord.Message) -> str return None async def _notify_original_sender( - self, - message: discord.Message, - original_sender_id: str, - current_sender_id: str | None + self, message: discord.Message, original_sender_id: str, current_sender_id: str | None ) -> None: """Notify the original anon sender about a reply.""" try: @@ -254,10 +247,7 @@ async def _should_notify_user(self, user_id: str) -> bool: return not link_record or link_record.get("anon_notifications", True) def _create_reply_notification_embed( - self, - message: discord.Message, - reply_type: str, - is_current_anon: bool + self, message: discord.Message, reply_type: str, is_current_anon: bool ) -> discord.Embed: """Create the notification embed for reply notifications.""" description = ( @@ -266,16 +256,8 @@ def _create_reply_notification_embed( else f"{reply_type} replied to your anon message" ) - embed = discord.Embed( - title="Reply to Your Anon Message", - description=description, - color=discord.Color.blue() - ) - embed.add_field( - name="Jump to Reply", - value=f"[Click here to view the reply]({message.jump_url})", - inline=False - ) + embed = discord.Embed(title="Reply to Your Anon Message", description=description, color=discord.Color.blue()) + embed.add_field(name="Jump to Reply", value=f"[Click here to view the reply]({message.jump_url})", inline=False) embed.set_footer(text="PESU Bot") embed.timestamp = discord.utils.utcnow() return embed @@ -304,18 +286,14 @@ async def toggle_callback(interaction: discord.Interaction) -> None: return view async def _handle_notification_toggle( - self, - interaction: discord.Interaction, - original_sender: discord.User + self, interaction: discord.Interaction, original_sender: discord.User ) -> None: """Handle the notification toggle button callback.""" if interaction.user.id != original_sender.id: return # Check current status - current_record = await self.client.db["anon_notifications"].find_one( - {"userId": str(original_sender.id)} - ) + current_record = await self.client.db["anon_notifications"].find_one({"userId": str(original_sender.id)}) currently_subscribed = not (current_record and not current_record.get("subscribed")) From edf79d3d8e2a89bf028f3e26c4e205a14875f01a Mon Sep 17 00:00:00 2001 From: achyu-dev Date: Mon, 29 Sep 2025 18:18:15 +0530 Subject: [PATCH 3/6] updated the logic of anon notifications --- cogs/events/general.py | 265 ++++++++++++++++++++--------------------- 1 file changed, 131 insertions(+), 134 deletions(-) diff --git a/cogs/events/general.py b/cogs/events/general.py index a27dc36..7b8cf66 100644 --- a/cogs/events/general.py +++ b/cogs/events/general.py @@ -127,194 +127,191 @@ async def on_member_remove(self, member: discord.Member) -> None: @commands.Cog.listener() async def on_message(self, message: discord.Message) -> None: - if message.author.bot: - return - - if os.getenv("APP_ENV") == "prod" and random.random() <= 0.2: # 20% chance and prod deployment - # Special EC Campus keyword patterns. Only check for words, not internal matches - patterns = [r"\becc\b", r"\bec campus\b", r"\bec\b"] - # Normalize message content to handle case insensitive matches - content = message.content.lower() - # Check for matches - if any(re.search(pattern, content) for pattern in patterns): - gif_url = "https://tenor.com/view/pes-pes-college-pesu-pes-univercity-pes-rr-gif-26661455" - reply_text = "Did someone mention EC Campus? 👀" - async with message.channel.typing(): - await asyncio.sleep(1) - await message.reply(reply_text) - await message.channel.send(gif_url) - - @commands.Cog.listener() - async def on_message_delete(self, message: discord.Message) -> None: + """ + Thin wrapper listener that delegates real work to helper methods to keep complexity low. + """ + # If it's an anon bot message from any bot that's not us, only process if it's an anon message. if message.author.bot and message.author.id != self.client.user.id: - # Only process if it's an anon message if not (message.embeds and message.embeds[0].title == "Anon Message"): return - # Ignore all other bots + # if it is an anon message (bot message with embed), fall through — other handlers may act on it + # (original logic only continued when it was an anon message) return - print("Testing......") - - # Check if this is a reply to an anon message + # Try to handle reply-to-anon flows (separate helper to reduce complexity) if message.reference and message.reference.message_id: - await self._handle_anon_reply_deletion(message) - - # Handle ghost ping detection - await self._handle_ghost_ping_detection(message) + try: + await self._process_reply_to_anon(message) + except (discord.NotFound, discord.Forbidden, discord.HTTPException): + # Could not fetch the replied message or other discord errors — ignore as before + pass - async def _handle_anon_reply_deletion(self, message: discord.Message) -> None: - """Handle deletion of replies to anon messages.""" + # Handle EC Campus keyword check separately try: - replied_message = await message.channel.fetch_message(message.reference.message_id) - - if not self._is_anon_message(replied_message): - return - - original_sender_id = await self._find_original_anon_sender(replied_message) - if not original_sender_id: - return - - current_sender_id = await self._get_current_message_sender_id(message) - - # If we found the original sender and they're different from current sender - if original_sender_id != current_sender_id: - await self._notify_original_sender(message, original_sender_id, current_sender_id) - - except (discord.NotFound, discord.Forbidden, discord.HTTPException): - # Could not fetch the replied message + await self._maybe_handle_ec_campus_keyword(message) + except Exception: + # Don't let a non-critical error here bubble up and break other things pass - def _is_anon_message(self, message: discord.Message) -> bool: - """Check if a message is an anon message.""" - return message.author == self.client.user and message.embeds and message.embeds[0].title == "Anon Message" + # End of on_message + return + + async def _process_reply_to_anon(self, message: discord.Message) -> None: + """ + Handle replies to anon messages and DM the original anon sender if appropriate. + This is extracted from on_message to reduce the complexity of the listener. + """ + replied_message = await message.channel.fetch_message(message.reference.message_id) + if not self._is_anon_message(replied_message): + return - async def _find_original_anon_sender(self, replied_message: discord.Message) -> str | None: - """Find the original sender of an anon message.""" anon_cog = self.client.get_cog("SlashAnon") - if not (anon_cog and hasattr(anon_cog, "anon_cache")): - return None + if not anon_cog or not hasattr(anon_cog, "anon_cache"): + return - for user_id, messages in anon_cog.anon_cache.items(): - if any(str(replied_message.id) == msg["message_id"] for msg in messages): - return user_id - return None + original_sender_id = self._find_sender_id(anon_cog, replied_message.id) + current_sender_id, is_current_anon = await self._identify_current_sender(anon_cog, message) - async def _get_current_message_sender_id(self, message: discord.Message) -> str | None: - """Get the sender ID of the current message if it's anon.""" - is_current_anon = self._is_anon_message(message) - print(f"is_current_anon: {is_current_anon}") + if not (original_sender_id and current_sender_id and original_sender_id != current_sender_id): + return - if not is_current_anon: - return None + await self._notify_original_sender(original_sender_id, current_sender_id, message, is_current_anon) - anon_cog = self.client.get_cog("SlashAnon") - if not (anon_cog and hasattr(anon_cog, "anon_cache")): - return None + # ---------- helpers for _process_reply_to_anon ---------- + @staticmethod + def _is_anon_message(msg: discord.Message) -> bool: + return msg.author.bot and msg.embeds and msg.embeds[0].title == "Anon Message" + + @staticmethod + def _find_sender_id(anon_cog: commands.Cog, target_message_id: int | str) -> str | None: for user_id, messages in anon_cog.anon_cache.items(): - if any(str(message.id) == msg["message_id"] for msg in messages): + if any(str(target_message_id) == msg["message_id"] for msg in messages): return user_id return None + async def _identify_current_sender( + self, anon_cog: commands.Cog, message: discord.Message + ) -> tuple[str | None, bool]: + """Return (sender_id, is_current_anon).""" + is_current_anon = self._is_anon_message(message) and message.author == self.client.user + if is_current_anon: + for user_id, messages in anon_cog.anon_cache.items(): + if any(str(message.id) == msg["message_id"] for msg in messages): + return user_id, True + return None, True + return str(message.author.id), False + async def _notify_original_sender( - self, message: discord.Message, original_sender_id: str, current_sender_id: str | None + self, + original_sender_id: str, + current_sender_id: str, + message: discord.Message, + is_current_anon: bool, ) -> None: - """Notify the original anon sender about a reply.""" + """Build embed, button, and DM the original anon sender.""" try: original_sender = await self.client.fetch_user(int(original_sender_id)) - if not original_sender: - return - - if not await self._should_notify_user(original_sender_id): - return - - is_current_anon = current_sender_id is not None - reply_type = "anon user" if is_current_anon else message.author.display_name - print(f"reply_type: {reply_type}") - - embed = self._create_reply_notification_embed(message, reply_type, is_current_anon) - view = await self._create_notification_toggle_view(original_sender) + except (discord.NotFound, discord.Forbidden, discord.HTTPException): + return + if not original_sender: + return - await original_sender.send(embed=embed, view=view) + link_record = await self.client.link_collection.find_one({"userId": str(original_sender.id)}) + if link_record and link_record.get("anon_notifications", True) is False: + return - except (discord.Forbidden, discord.HTTPException, discord.NotFound): - # Could not send DM to user - pass + reply_type = "anon user" if is_current_anon else message.author.display_name - async def _should_notify_user(self, user_id: str) -> bool: - """Check if user should receive notifications.""" - link_record = await self.client.link_collection.find_one({"userId": user_id}) - return not link_record or link_record.get("anon_notifications", True) - - def _create_reply_notification_embed( - self, message: discord.Message, reply_type: str, is_current_anon: bool - ) -> discord.Embed: - """Create the notification embed for reply notifications.""" - description = ( - f"An {reply_type} replied to your anon message" + embed = discord.Embed( + title="Reply to Your Anon Message", + description=f"An {reply_type} replied to your anon message" if is_current_anon - else f"{reply_type} replied to your anon message" + else f"{reply_type} replied to your anon message", + color=discord.Color.blue(), + ) + embed.add_field( + name="Jump to Reply", + value=f"[Click here to view the reply]({message.jump_url})", + inline=False, ) - - embed = discord.Embed(title="Reply to Your Anon Message", description=description, color=discord.Color.blue()) - embed.add_field(name="Jump to Reply", value=f"[Click here to view the reply]({message.jump_url})", inline=False) embed.set_footer(text="PESU Bot") embed.timestamp = discord.utils.utcnow() - return embed - async def _create_notification_toggle_view(self, original_sender: discord.User) -> discord.ui.View: - """Create the view with notification toggle button.""" - link_record = await self.client.link_collection.find_one({"userId": str(original_sender.id)}) is_subscribed = link_record.get("anon_notifications", True) if link_record else True + view = self._make_toggle_view(original_sender.id, is_subscribed) - print(f"link_record: {link_record}") - print(f"is_subscribed: {is_subscribed}") - print(f"Button label: {'Unsubscribe from notifications' if is_subscribed else 'Subscribe to notifications'}") + try: + await original_sender.send(embed=embed, view=view) + except (discord.Forbidden, discord.HTTPException, discord.NotFound): + pass + def _make_toggle_view(self, user_id: int, is_subscribed: bool) -> discord.ui.View: + """Create the subscribe/unsubscribe button view.""" view = discord.ui.View() toggle_button = discord.ui.Button( label="Unsubscribe from notifications" if is_subscribed else "Subscribe to notifications", style=discord.ButtonStyle.secondary if is_subscribed else discord.ButtonStyle.primary, - custom_id=f"toggle_anon_notifications_{original_sender.id}", + custom_id=f"toggle_anon_notifications_{user_id}", ) async def toggle_callback(interaction: discord.Interaction) -> None: - await self._handle_notification_toggle(interaction, original_sender) + if interaction.user.id != user_id: + await interaction.response.send_message("You can't toggle someone else's subscription.", ephemeral=True) + return + + current_record = await self.client.link_collection.find_one({"userId": str(user_id)}) + currently_subscribed = current_record.get("anon_notifications", True) if current_record else True + + new_status = not currently_subscribed + await self.client.link_collection.update_one( + {"userId": str(user_id)}, + {"$set": {"anon_notifications": new_status}}, + upsert=True, + ) + + if new_status: + await interaction.response.send_message( + "✅ You have been subscribed to anon reply notifications.", ephemeral=True + ) + else: + await interaction.response.send_message( + "❌ You have been unsubscribed from anon reply notifications.", ephemeral=True + ) toggle_button.callback = toggle_callback view.add_item(toggle_button) return view - async def _handle_notification_toggle( - self, interaction: discord.Interaction, original_sender: discord.User - ) -> None: - """Handle the notification toggle button callback.""" - if interaction.user.id != original_sender.id: + async def _maybe_handle_ec_campus_keyword(self, message: discord.Message) -> None: + """ + Handle the EC Campus keyword check (20% random chance in prod) extracted out to reduce complexity. + """ + if os.getenv("APP_ENV") != "prod": return - # Check current status - current_record = await self.client.db["anon_notifications"].find_one({"userId": str(original_sender.id)}) - - currently_subscribed = not (current_record and not current_record.get("subscribed")) + if random.random() > 0.2: + return - # Toggle status - new_status = not currently_subscribed - await self.client.link_collection.update_one( - {"userId": str(original_sender.id)}, - {"$set": {"anon_notifications": new_status}}, - ) + # Only check text content + content = (message.content or "").lower() + if not content: + return - message = ( - "✅ You have been subscribed to anon reply notifications." - if new_status - else "❌ You have been unsubscribed from anon reply notifications." - ) + patterns = [r"\becc\b", r"\bec campus\b", r"\bec\b"] + if any(re.search(pattern, content) for pattern in patterns): + gif_url = "https://tenor.com/view/pes-pes-college-pesu-pes-univercity-pes-rr-gif-26661455" + reply_text = "Did someone mention EC Campus? 👀" + async with message.channel.typing(): + await asyncio.sleep(1) + await message.reply(reply_text) + await message.channel.send(gif_url) - await interaction.response.send_message(message, ephemeral=True) - print(f"Toggled subscription for user {original_sender.id} to {new_status}") + @commands.Cog.listener() + async def on_message_delete(self, message: discord.Message) -> None: + if message.author.bot: + return - async def _handle_ghost_ping_detection(self, message: discord.Message) -> None: - """Handle ghost ping detection for deleted messages.""" mentions = message.mentions role_mentions = message.role_mentions From 90d8dedf3ebe0ba0ec181a79744a9796a7b7a2a3 Mon Sep 17 00:00:00 2001 From: achyu-dev Date: Mon, 29 Sep 2025 18:40:07 +0530 Subject: [PATCH 4/6] updated with suggestions --- cogs/events/general.py | 22 ++++++++++++++++------ utils/config.py | 6 +++--- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/cogs/events/general.py b/cogs/events/general.py index 7b8cf66..4d83001 100644 --- a/cogs/events/general.py +++ b/cogs/events/general.py @@ -132,11 +132,11 @@ async def on_message(self, message: discord.Message) -> None: """ # If it's an anon bot message from any bot that's not us, only process if it's an anon message. if message.author.bot and message.author.id != self.client.user.id: - if not (message.embeds and message.embeds[0].title == "Anon Message"): + if not (message.embeds and len(message.embeds) > 0 and message.embeds[0].title == "Anon Message"): return # if it is an anon message (bot message with embed), fall through — other handlers may act on it # (original logic only continued when it was an anon message) - return + # return # Try to handle reply-to-anon flows (separate helper to reduce complexity) if message.reference and message.reference.message_id: @@ -181,9 +181,10 @@ async def _process_reply_to_anon(self, message: discord.Message) -> None: @staticmethod def _is_anon_message(msg: discord.Message) -> bool: - return msg.author.bot and msg.embeds and msg.embeds[0].title == "Anon Message" + return msg.author.bot and msg.embeds and len(msg.embeds) > 0 and msg.embeds[0].title == "Anon Message" @staticmethod + # int and str are both accepted for target_message_id for flexibility def _find_sender_id(anon_cog: commands.Cog, target_message_id: int | str) -> str | None: for user_id, messages in anon_cog.anon_cache.items(): if any(str(target_message_id) == msg["message_id"] for msg in messages): @@ -202,6 +203,14 @@ async def _identify_current_sender( return None, True return str(message.author.id), False + async def _get_subscription_status(self, user_id: int) -> bool: + """ + Return whether a user is currently subscribed to anon notifications. + Defaults to True if no record exists. + """ + record = await self.client.link_collection.find_one({"userId": str(user_id)}) + return record.get("anon_notifications", True) if record else True + async def _notify_original_sender( self, original_sender_id: str, @@ -238,7 +247,8 @@ async def _notify_original_sender( embed.set_footer(text="PESU Bot") embed.timestamp = discord.utils.utcnow() - is_subscribed = link_record.get("anon_notifications", True) if link_record else True + is_subscribed = await self._get_subscription_status(original_sender.id) + view = self._make_toggle_view(original_sender.id, is_subscribed) try: @@ -260,8 +270,8 @@ async def toggle_callback(interaction: discord.Interaction) -> None: await interaction.response.send_message("You can't toggle someone else's subscription.", ephemeral=True) return - current_record = await self.client.link_collection.find_one({"userId": str(user_id)}) - currently_subscribed = current_record.get("anon_notifications", True) if current_record else True + # current_record = await self.client.link_collection.find_one({"userId": str(user_id)}) + currently_subscribed = await self._get_subscription_status(user_id) new_status = not currently_subscribed await self.client.link_collection.update_one( diff --git a/utils/config.py b/utils/config.py index cef00fe..4dfae76 100644 --- a/utils/config.py +++ b/utils/config.py @@ -73,11 +73,11 @@ class Config: # Channel IDs CHANNELS = { - "BOT_LOGS": 786084620944146504, - "MOD_LOGS": 778678059879890944, + "BOT_LOGS": 1393983999113822399, + "MOD_LOGS": 1386770381733630012, "NQN_LOGS": 927077979383824484, "WELCOME": 742946580285620225, - "LOBBY": 860224115633160203, + "LOBBY": 1368604372581486634, } def __init__(self, bot: DiscordBot) -> None: From 3d2ff9136d8abec11da8a9882d293b55629c93ee Mon Sep 17 00:00:00 2001 From: achyu-dev Date: Mon, 29 Sep 2025 18:40:57 +0530 Subject: [PATCH 5/6] revert config From 2c788e00978f119b5ed070c38ba9e380d246b5d1 Mon Sep 17 00:00:00 2001 From: achyu-dev Date: Mon, 29 Sep 2025 18:43:10 +0530 Subject: [PATCH 6/6] revert config --- utils/config.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/config.py b/utils/config.py index 4dfae76..cef00fe 100644 --- a/utils/config.py +++ b/utils/config.py @@ -73,11 +73,11 @@ class Config: # Channel IDs CHANNELS = { - "BOT_LOGS": 1393983999113822399, - "MOD_LOGS": 1386770381733630012, + "BOT_LOGS": 786084620944146504, + "MOD_LOGS": 778678059879890944, "NQN_LOGS": 927077979383824484, "WELCOME": 742946580285620225, - "LOBBY": 1368604372581486634, + "LOBBY": 860224115633160203, } def __init__(self, bot: DiscordBot) -> None: