测试猜歌名
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
[GuessSong]
|
||||
enable = true
|
||||
command = ["猜歌名"]
|
||||
command-format = """
|
||||
@@ -5,4 +6,19 @@ command-format = """
|
||||
猜歌名 - 开始猜歌游戏
|
||||
猜歌名 歌手名 - 开始指定歌手的猜歌游戏
|
||||
猜歌名 歌名 - 提交你的答案
|
||||
"""
|
||||
"""
|
||||
|
||||
[GuessSong.api]
|
||||
music_list_api = "https://hhlqilongzhu.cn/api/dg_douyinmusic.php?msg={singer_name}&type=json&num=50"
|
||||
music_single_api = "https://hhlqilongzhu.cn/api/dg_douyinmusic.php?msg={search_query}&type=json&n=1"
|
||||
|
||||
[GuessSong.popular_singers]
|
||||
list = [
|
||||
"周杰伦", "林俊杰", "薛之谦", "陈奕迅", "邓紫棋", "李荣浩", "张学友", "刘德华",
|
||||
"张国荣", "梅艳芳", "Beyond", "容祖儿", "谢霆锋",
|
||||
"王菲", "张惠妹", "孙燕姿", "蔡依林", "五月天"
|
||||
]
|
||||
|
||||
[GuessSong.game]
|
||||
clip_duration = 10 # 音频片段时长(秒)
|
||||
hint_timeout = 30 # 提示等待时间(秒)
|
||||
@@ -117,9 +117,29 @@ class GuessSongPlugin(MessagePluginInterface):
|
||||
if self.db_manager:
|
||||
self.redis_db = GuessSongRedisDB(self.db_manager)
|
||||
|
||||
self._commands = self._config.get("GuessSong", {}).get("command", ["猜歌名"])
|
||||
self.command_format = self._config.get("GuessSong", {}).get("command-format", "猜歌名 [歌手名]/[歌名]")
|
||||
self.enable = self._config.get("GuessSong", {}).get("enable", True)
|
||||
# 从配置文件加载设置
|
||||
guess_song_config = self._config.get("GuessSong", {})
|
||||
self._commands = guess_song_config.get("command", ["猜歌名"])
|
||||
self.command_format = guess_song_config.get("command-format", "猜歌名 [歌手名]/[歌名]")
|
||||
self.enable = guess_song_config.get("enable", True)
|
||||
|
||||
# 加载API配置
|
||||
api_config = guess_song_config.get("api", {})
|
||||
self.music_list_api = api_config.get("music_list_api", "")
|
||||
self.music_single_api = api_config.get("music_single_api", "")
|
||||
|
||||
# 加载游戏配置
|
||||
game_config = guess_song_config.get("game", {})
|
||||
self.clip_duration = game_config.get("clip_duration", 10)
|
||||
self.hint_timeout = game_config.get("hint_timeout", 30)
|
||||
|
||||
# 加载热门歌手列表
|
||||
singers_config = guess_song_config.get("popular_singers", {})
|
||||
self.popular_singers = singers_config.get("list", [
|
||||
"周杰伦", "林俊杰", "薛之谦", "陈奕迅", "邓紫棋", "李荣浩", "张学友", "刘德华",
|
||||
"张国荣", "梅艳芳", "Beyond", "容祖儿", "谢霆锋",
|
||||
"王菲", "张惠妹", "孙燕姿", "蔡依林", "五月天"
|
||||
])
|
||||
|
||||
self.LOG.info(f"[{self.name}] 插件初始化完成,指令:{self._commands}")
|
||||
return True
|
||||
@@ -275,12 +295,12 @@ class GuessSongPlugin(MessagePluginInterface):
|
||||
return True, "猜对了"
|
||||
else:
|
||||
# 答案错误
|
||||
# 检查是否需要给提示(超过30秒且未给过提示)
|
||||
# 检查是否需要给提示(超过指定时间且未给过提示)
|
||||
current_time = time.time()
|
||||
start_time = game_data.get("start_time", 0)
|
||||
hint_given = game_data.get("hint_given", False)
|
||||
|
||||
if not hint_given and (current_time - start_time) > 30:
|
||||
if not hint_given and (current_time - start_time) > self.hint_timeout:
|
||||
# 给出提示(显示歌名的第一个字)
|
||||
hint = correct_answer[0] + "*" * (len(correct_answer) - 1)
|
||||
await bot.send_text_message(session_id, f"💡 提示:歌名以 '{correct_answer[0]}' 开头")
|
||||
@@ -307,16 +327,11 @@ class GuessSongPlugin(MessagePluginInterface):
|
||||
# 构建API请求URL - 使用抖音音乐API
|
||||
if singer_name:
|
||||
# 如果指定了歌手,搜索该歌手的歌曲
|
||||
api_url = f"https://hhlqilongzhu.cn/api/dg_douyinmusic.php?msg={singer_name}&type=json&num=50"
|
||||
api_url = f"{self.music_list_api}".format(singer_name=singer_name)
|
||||
else:
|
||||
# 如果没有指定歌手,使用热门歌手列表
|
||||
popular_singers = [
|
||||
"周杰伦", "林俊杰", "薛之谦", "陈奕迅", "邓紫棋", "李荣浩", "张学友", "刘德华",
|
||||
"张国荣", "梅艳芳", "Beyond", "容祖儿", "谢霆锋",
|
||||
"王菲", "张惠妹", "孙燕姿", "蔡依林", "五月天"
|
||||
]
|
||||
random_singer = random.choice(popular_singers)
|
||||
api_url = f"https://hhlqilongzhu.cn/api/dg_douyinmusic.php?msg={random_singer}&type=json&num=50"
|
||||
random_singer = random.choice(self.popular_singers)
|
||||
api_url = f"{self.music_list_api}".format(singer_name=random_singer)
|
||||
|
||||
# 发送请求获取歌曲列表
|
||||
response = requests.get(api_url)
|
||||
@@ -346,7 +361,7 @@ class GuessSongPlugin(MessagePluginInterface):
|
||||
search_query = f"{singer_name}-{song_name}"
|
||||
|
||||
# 调用原有API获取播放链接
|
||||
detail_api = f"https://www.hhlqilongzhu.cn/api/joox/juhe_music.php?msg={search_query}&type=json&n=1"
|
||||
detail_api = f"{self.music_single_api}".format(search_query=search_query)
|
||||
detail_response = requests.get(detail_api)
|
||||
|
||||
if detail_response.status_code != 200:
|
||||
@@ -392,8 +407,8 @@ class GuessSongPlugin(MessagePluginInterface):
|
||||
# 使用pydub处理音频
|
||||
audio = AudioSegment.from_file(BytesIO(audio_data))
|
||||
|
||||
# 截取前10秒
|
||||
clip_duration = 10 * 1000 # 10秒,单位毫秒
|
||||
# 截取前N秒
|
||||
clip_duration = self.clip_duration * 1000 # 转换为毫秒
|
||||
audio_clip = audio[:clip_duration]
|
||||
|
||||
# 将音频片段转换为字节
|
||||
|
||||
Reference in New Issue
Block a user