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