diff --git a/main.py b/main.py index 6b5c81c..d36769b 100644 --- a/main.py +++ b/main.py @@ -522,8 +522,8 @@ class GroupDailyAnalysis(Star): yield event.plain_result("🔍 正在启动分析引擎,正在拉取最近消息...") elif adapter and orig_msg_id: await adapter.set_reaction( - event.get_group_id(), orig_msg_id, "🔍" - ) # 🔍 + event.get_group_id(), orig_msg_id, "analysis_started" + ) # 调用 DDD 应用级服务 result = await self.analysis_service.execute_daily_analysis( @@ -540,8 +540,8 @@ class GroupDailyAnalysis(Star): if not use_text_reply and adapter and orig_msg_id: await adapter.set_reaction( - event.get_group_id(), orig_msg_id, "📊" - ) # 📊 + event.get_group_id(), orig_msg_id, "analysis_done" + ) async for res in self._send_analysis_report(event, result): yield res diff --git a/src/infrastructure/platform/adapters/discord_adapter.py b/src/infrastructure/platform/adapters/discord_adapter.py index 7f81133..6c57fb8 100644 --- a/src/infrastructure/platform/adapters/discord_adapter.py +++ b/src/infrastructure/platform/adapters/discord_adapter.py @@ -764,11 +764,14 @@ class DiscordAdapter(PlatformAdapter): return False try: - # 映射常见的表情 ID 为文字表情,使分析状态在跨平台保持一致 - mapping = {289: "🔍", 424: "📊", 124: "✅"} - emoji_to_use = emoji - if isinstance(emoji, int) or (isinstance(emoji, str) and emoji.isdigit()): - emoji_to_use = mapping.get(int(emoji), emoji) + reaction_key = str(emoji) + emoji_to_use = { + "analysis_started": "🔍", + "analysis_done": "📊", + "289": "🔍", + "124": "📊", + "424": "📊", + }.get(reaction_key, reaction_key) channel_id = int(group_id) channel = self._discord_client.get_channel(channel_id) diff --git a/src/infrastructure/platform/adapters/onebot_adapter.py b/src/infrastructure/platform/adapters/onebot_adapter.py index a9c278e..2751e83 100644 --- a/src/infrastructure/platform/adapters/onebot_adapter.py +++ b/src/infrastructure/platform/adapters/onebot_adapter.py @@ -1377,12 +1377,13 @@ class OneBotAdapter(PlatformAdapter): 支持 Go-CQHTTP, NapCat, Lagrange 等 OneBot 实现。 """ try: - # 语义化映射:根据用户喜好精细化 OneBot 端的降级 - emoji_id = str(emoji) - if str(emoji) == "🔍": - emoji_id = "289" # 🫣 表情 (表示任务已接收) - elif str(emoji) == "📊": - emoji_id = "124" # 👌 表情 (表示任务处理完成) + reaction_key = str(emoji) + emoji_id = { + "analysis_started": "289", # 🫣 表情 (表示任务已接收) + "analysis_done": "124", # 👌 表情 (表示任务处理完成) + "🔍": "289", + "📊": "124", + }.get(reaction_key, reaction_key) await self.bot.call_action( "set_msg_emoji_like", diff --git a/src/infrastructure/platform/adapters/telegram_adapter.py b/src/infrastructure/platform/adapters/telegram_adapter.py index 7035618..980df07 100644 --- a/src/infrastructure/platform/adapters/telegram_adapter.py +++ b/src/infrastructure/platform/adapters/telegram_adapter.py @@ -909,34 +909,70 @@ class TelegramAdapter(PlatformAdapter): return False try: - # 映射常见的表情 ID 为文字表情 - mapping = {289: "🔍", 424: "📊", 124: "✅"} - emoji_to_use = emoji - if isinstance(emoji, int) or (isinstance(emoji, str) and emoji.isdigit()): - emoji_to_use = mapping.get(int(emoji), emoji) - chat_id, _ = self._parse_group_id(group_id) # 只有开启了库支持且版本符合时才尝试。set_message_reaction 是 Bot API 7.0 (PTB 20.8+) 特性。 - if hasattr(client, "set_message_reaction"): + if not hasattr(client, "set_message_reaction"): + return False + + if not is_add: try: from telegram import ReactionTypeEmoji - reaction = [ReactionTypeEmoji(emoji=emoji_to_use)] if is_add else [] await client.set_message_reaction( chat_id=chat_id, message_id=int(message_id), - reaction=reaction, + reaction=[], ) return True except ImportError: - # 如果版本太低没有 ReactionTypeEmoji,尝试直接传字符串 (有些实现支持) await client.set_message_reaction( chat_id=chat_id, message_id=int(message_id), - reaction=emoji_to_use if is_add else None, + reaction=None, ) return True + + reaction_key = str(emoji) + candidates = { + "analysis_started": ("👀", "🤔", "👍"), + "analysis_done": ("👌", "👍", "🎉"), + "🔍": ("👀", "🤔", "👍"), + "📊": ("👌", "👍", "🎉"), + "289": ("👀", "🤔", "👍"), + "124": ("👌", "👍", "🎉"), + "424": ("👌", "👍", "🎉"), + "✅": ("👌", "👍", "🎉"), + }.get(reaction_key, (reaction_key,)) + + try: + from telegram import ReactionTypeEmoji + + for candidate in candidates: + try: + await client.set_message_reaction( + chat_id=chat_id, + message_id=int(message_id), + reaction=[ReactionTypeEmoji(emoji=candidate)], + ) + return True + except Exception: + continue + except ImportError: + for candidate in candidates: + try: + await client.set_message_reaction( + chat_id=chat_id, + message_id=int(message_id), + reaction=candidate, + ) + return True + except Exception: + continue + + logger.debug( + f"[Telegram] set_reaction 未匹配到可用表情: emoji={emoji}, candidates={candidates}" + ) return False except Exception as e: logger.debug(f"[Telegram] set_reaction 失败: {e}")