调整json数据
This commit is contained in:
@@ -190,7 +190,8 @@ class GuessSongPlugin(MessagePluginInterface):
|
||||
return await self._check_answer(message)
|
||||
else: # 没有内容,提示已有游戏在进行中
|
||||
await bot.send_text_message(session_id,
|
||||
f"⚠️ 当前已有猜歌游戏在进行中,请直接回复 [猜歌名 歌名] 进行猜测\n或回复 [猜歌名 下一首] 跳过当前歌曲", sender)
|
||||
f"⚠️ 当前已有猜歌游戏在进行中,请直接回复 [猜歌名 歌名] 进行猜测\n或回复 [猜歌名 下一首] 跳过当前歌曲",
|
||||
sender)
|
||||
return True, "已有游戏进行中"
|
||||
|
||||
# 否则开始新游戏(可以指定歌手或随机)
|
||||
@@ -306,7 +307,7 @@ class GuessSongPlugin(MessagePluginInterface):
|
||||
# 构建API请求URL - 使用抖音音乐API
|
||||
if singer_name:
|
||||
# 如果指定了歌手,搜索该歌手的歌曲
|
||||
api_url = f"https://www.hhlqilongzhu.cn/api/joox/juhe_music.php?msg={singer_name}&type=json"
|
||||
api_url = f"https://hhlqilongzhu.cn/api/dg_douyinmusic.php?msg={singer_name}&type=json"
|
||||
else:
|
||||
# 如果没有指定歌手,使用热门歌手列表
|
||||
popular_singers = [
|
||||
@@ -315,7 +316,7 @@ class GuessSongPlugin(MessagePluginInterface):
|
||||
"王菲", "张惠妹", "孙燕姿", "蔡依林", "五月天"
|
||||
]
|
||||
random_singer = random.choice(popular_singers)
|
||||
api_url = f"https://www.hhlqilongzhu.cn/api/joox/juhe_music.php?msg={random_singer}&type=json"
|
||||
api_url = f"https://hhlqilongzhu.cn/api/dg_douyinmusic.php?msg={random_singer}&type=json"
|
||||
|
||||
# 发送请求获取歌曲列表
|
||||
response = requests.get(api_url)
|
||||
@@ -326,12 +327,16 @@ class GuessSongPlugin(MessagePluginInterface):
|
||||
|
||||
# 解析响应数据
|
||||
json_data = response.json()
|
||||
if not json_data.get("data") or json_data.get("code") != 200:
|
||||
self.LOG.error(f"API 返回数据格式错误: {json_data}")
|
||||
return {}
|
||||
|
||||
# 从歌曲列表中随机选择一首
|
||||
song_list = json_data
|
||||
song_list = json_data.get("data")
|
||||
if not song_list or not isinstance(song_list, list) or len(song_list) == 0:
|
||||
self.LOG.error(f"未找到歌曲列表或列表为空")
|
||||
return {}
|
||||
# self.LOG.debug(f"song_list:{song_list}")
|
||||
|
||||
# 随机选择一首歌曲
|
||||
random_song = random.choice(song_list)
|
||||
|
||||
@@ -363,7 +368,7 @@ class GuessSongPlugin(MessagePluginInterface):
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
self.LOG.exception(f"获取随机歌曲出错: {e}")
|
||||
self.LOG.error(f"获取随机歌曲出错: {e}")
|
||||
return {}
|
||||
|
||||
async def _send_song_clip(self, bot: WechatAPIClient, song_info: Dict[str, Any], session_id: str) -> bool:
|
||||
@@ -478,26 +483,27 @@ class GuessSongPlugin(MessagePluginInterface):
|
||||
current_game = None
|
||||
if self.redis_db:
|
||||
current_game = self.redis_db.get_game_session(session_id)
|
||||
|
||||
|
||||
if not current_game or current_game.get("status") != "playing":
|
||||
await bot.send_text_message(session_id, f"⚠️ 当前没有进行中的猜歌游戏", sender)
|
||||
return False, "没有进行中的游戏"
|
||||
|
||||
|
||||
# 显示当前歌曲答案
|
||||
correct_answer = current_game.get("song_name", "")
|
||||
singer_name = current_game.get("singer_name", "")
|
||||
await bot.send_text_message(session_id, f"⏭️ 已跳过当前歌曲\n歌曲:{correct_answer}\n歌手:{singer_name}", sender)
|
||||
|
||||
await bot.send_text_message(session_id, f"⏭️ 已跳过当前歌曲\n歌曲:{correct_answer}\n歌手:{singer_name}",
|
||||
sender)
|
||||
|
||||
# 发送完整音乐
|
||||
await self._send_music_message(bot, current_game, session_id)
|
||||
|
||||
|
||||
# 删除当前游戏会话
|
||||
if self.redis_db:
|
||||
self.redis_db.delete_game_session(session_id)
|
||||
|
||||
|
||||
# 开始新游戏
|
||||
return await self._start_new_game(bot, session_id, sender, None)
|
||||
|
||||
|
||||
except Exception as e:
|
||||
self.LOG.error(f"跳过当前歌曲出错: {e}")
|
||||
await bot.send_text_message(session_id, f"❌跳过当前歌曲出错,请稍后重试", sender)
|
||||
|
||||
Reference in New Issue
Block a user