From 2a5c78941211bcba4e78dad26370da1787ed77ed Mon Sep 17 00:00:00 2001 From: liuwei Date: Tue, 3 Jun 2025 11:42:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=8C=9C=E6=AD=8C=E5=90=8D?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=8C=E4=BB=8EAPI=E4=B8=AD=E6=8F=90?= =?UTF-8?q?=E5=8F=96=E6=AD=8C=E6=9B=B2=E5=89=8D=E5=A5=8F=EF=BC=8C=E7=84=B6?= =?UTF-8?q?=E5=90=8E=E7=8C=9C=E6=AD=8C=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/guess_song/main.py | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/plugins/guess_song/main.py b/plugins/guess_song/main.py index 1fc1a6c..a03bcff 100644 --- a/plugins/guess_song/main.py +++ b/plugins/guess_song/main.py @@ -150,7 +150,18 @@ class GuessSongPlugin(MessagePluginInterface): """处理消息""" content = str(message.get("content", "")).strip() self.LOG.debug(f"插件执行: {self.name}:{content}") - command = content.split(" ")[0] + + # 简化命令处理,只检查开头是否包含命令前缀 + command_found = False + for cmd in self._commands: + if content.startswith(cmd): + command_found = True + content = content[len(cmd):].strip() + break + + if not command_found: + return False, "不匹配的命令" + sender = message.get("sender") roomid = message.get("roomid", "") gbm: GroupBotManager = message.get("gbm") @@ -163,24 +174,17 @@ class GuessSongPlugin(MessagePluginInterface): if roomid and gbm.get_group_permission(roomid, Feature.GUESS_MUSIC) == PermissionStatus.DISABLED: return False, "没有权限" - # 提取参数 - params = content[len(command):].strip() - # 获取当前游戏会话 current_game = None if self.redis_db: current_game = self.redis_db.get_game_session(session_id) - # 如果没有参数,开始新游戏(随机歌手) - if not params: - return await self._start_new_game(bot, session_id, sender, None) - - # 如果有游戏进行中,且参数不是歌手名,则视为猜歌名答案 - if current_game and current_game.get("status") == "playing": - return await self._check_answer(bot, session_id, sender, params, current_game) - - # 否则,视为指定歌手开始新游戏 - return await self._start_new_game(bot, session_id, sender, params) + # 简化逻辑:如果有内容,且游戏进行中,则视为答案 + if current_game and current_game.get("status") == "playing" and content: + return await self._check_answer(bot, session_id, sender, content, current_game) + + # 否则开始新游戏(可以指定歌手或随机) + return await self._start_new_game(bot, session_id, sender, content if content else None) async def _start_new_game(self, bot: WechatAPIClient, session_id: str, sender: str, singer_name: Optional[str]) -> \ Tuple[bool, str]: