添加猜歌名功能,从API中提取歌曲前奏,然后猜歌名
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user