From 7a0022cb595b2b13d1c04ceab0442c37a308e51a Mon Sep 17 00:00:00 2001 From: Franz Rolfsvaag Date: Sat, 9 Aug 2025 15:51:43 +0200 Subject: [PATCH] Adjustments to reaction emoji acceptance --- .dockerignore | 8 ++++++++ data_manager.py | 4 ++++ modules/common/emoji_accept.py | 24 ++++++++++++++++++++++++ modules/nick_nudge/nick_nudge.py | 3 ++- modules/reaction_role/reaction_role.py | 5 +++-- modules/user_cards/user_cards.py | 3 ++- 6 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 .dockerignore create mode 100644 modules/common/emoji_accept.py diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..e3cd87a --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +.git +__pycache__/ +*.pyc +.env +settings.conf +data.json +data.json.bak +example/ diff --git a/data_manager.py b/data_manager.py index b6e2efd..b2a28b9 100644 --- a/data_manager.py +++ b/data_manager.py @@ -30,6 +30,10 @@ class DataManager: 'user_cards': [], 'pirates_list_posts': [], 'spicepay_prefs': [], + 'nick_verified': [], + 'nick_claim_pending': [], + 'nick_reviews': [], + 'rr_msg_channels': [], } self._save(default) return default diff --git a/modules/common/emoji_accept.py b/modules/common/emoji_accept.py new file mode 100644 index 0000000..33e8490 --- /dev/null +++ b/modules/common/emoji_accept.py @@ -0,0 +1,24 @@ +# Accept/approve emoji set used across the bot. +# Works for both unicode and custom server emoji. + +# Unicode emoji that should count as "accept" +ACCEPT_UNICODE = {"✅", "🫡", "❤️"} + +# Custom emoji short names that should count as "accept" +# Add names (not the <:name:id> literal) for any server emoji you want. +ACCEPT_CUSTOM_NAMES = {"diverOK"} + +def is_accept(emoji) -> bool: + """ + Return True if the given emoji should count as an 'accept' reaction. + Compatible with Reaction.emoji and RawReactionActionEvent.emoji. + """ + try: + # unicode path + if str(emoji) in ACCEPT_UNICODE: + return True + # custom emoji path (has a .name) + name = getattr(emoji, "name", None) + return name in ACCEPT_CUSTOM_NAMES + except Exception: + return False diff --git a/modules/nick_nudge/nick_nudge.py b/modules/nick_nudge/nick_nudge.py index e2902b4..f551223 100644 --- a/modules/nick_nudge/nick_nudge.py +++ b/modules/nick_nudge/nick_nudge.py @@ -6,6 +6,7 @@ from discord.ext import commands from discord import app_commands from mod_perms import is_moderator_userid +from modules.common.emoji_accept import is_accept CHECK = '✅' # approved/verified CROSS = '❌' # reject / no @@ -172,7 +173,7 @@ class NickNudgeCog(commands.Cog): @commands.Cog.listener() async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent): # 1) Handle DM nudge confirmations (user reacts ✅ in DM) - if payload.guild_id is None and str(payload.emoji) in ACCEPT and payload.user_id != self.bot.user.id: + if payload.guild_id is None and is_accept(payload.emoji) and payload.user_id != self.bot.user.id: entry = next((m for m in self.bot.data_manager.get('nick_dm_map') if m['message_id'] == payload.message_id), None) if not entry: return diff --git a/modules/reaction_role/reaction_role.py b/modules/reaction_role/reaction_role.py index 567ac51..8b82112 100644 --- a/modules/reaction_role/reaction_role.py +++ b/modules/reaction_role/reaction_role.py @@ -1,5 +1,6 @@ import discord from discord.ext import commands +from modules.common.emoji_accept import is_accept CHECKMARK = '✅' ACCEPT = {CHECKMARK, '🫡'} @@ -110,7 +111,7 @@ class ReactionRoleCog(commands.Cog): # ---- listeners ---- @commands.Cog.listener() async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent): - if str(payload.emoji) not in ACCEPT or not payload.guild_id: + if not payload.guild_id or not is_accept(payload.emoji): return guild = self.bot.get_guild(payload.guild_id) member = await self._get_member(guild, payload.user_id) @@ -157,7 +158,7 @@ class ReactionRoleCog(commands.Cog): @commands.Cog.listener() async def on_raw_reaction_remove(self, payload: discord.RawReactionActionEvent): - if str(payload.emoji) not in ACCEPT or not payload.guild_id: + if not payload.guild_id or not is_accept(payload.emoji): return guild = self.bot.get_guild(payload.guild_id) member = await self._get_member(guild, payload.user_id) diff --git a/modules/user_cards/user_cards.py b/modules/user_cards/user_cards.py index 2d38fc0..287be69 100644 --- a/modules/user_cards/user_cards.py +++ b/modules/user_cards/user_cards.py @@ -3,6 +3,7 @@ import time from typing import Optional, Set, Tuple import discord from discord.ext import commands +from modules.common.emoji_accept import is_accept CHECK = '✅' # verified CROSS = '❌' # not done @@ -270,7 +271,7 @@ class UserCardsCog(commands.Cog): if not message: return ids for rxn in message.reactions: - if str(rxn.emoji) in ACCEPT: # <-- was == CHECK + if is_accept(rxn.emoji): async for u in rxn.users(limit=None): if not u.bot: ids.add(u.id)