From 833d0005faa036e3336866fe20dda8e9254a72f2 Mon Sep 17 00:00:00 2001 From: liuwei Date: Tue, 3 Jun 2025 11:48:01 +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 | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/plugins/guess_song/main.py b/plugins/guess_song/main.py index a03bcff..1d34cb9 100644 --- a/plugins/guess_song/main.py +++ b/plugins/guess_song/main.py @@ -36,6 +36,7 @@ class GuessSongRedisDB: """保存游戏会话数据""" try: with self.get_redis_connection() as redis_client: + logger.info(f"保存猜歌游戏数据{game_data}") # 设置过期时间为10分钟 redis_client.setex( f'{self.prefix}{room_id}', @@ -110,7 +111,7 @@ class GuessSongPlugin(MessagePluginInterface): # 保存上下文对象 self.event_system = context.get("event_system") - self.db_manager = context.get("db_manager") + self.db_manager = DBConnectionManager.get_instance() # 初始化Redis操作类 if self.db_manager: @@ -150,7 +151,7 @@ class GuessSongPlugin(MessagePluginInterface): """处理消息""" content = str(message.get("content", "")).strip() self.LOG.debug(f"插件执行: {self.name}:{content}") - + # 简化命令处理,只检查开头是否包含命令前缀 command_found = False for cmd in self._commands: @@ -158,10 +159,10 @@ class GuessSongPlugin(MessagePluginInterface): 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") @@ -182,7 +183,7 @@ class GuessSongPlugin(MessagePluginInterface): # 简化逻辑:如果有内容,且游戏进行中,则视为答案 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)