优化代码

This commit is contained in:
liuwei
2025-06-09 17:48:41 +08:00
parent 0d5140a894
commit df5ccc4ae8
3 changed files with 27 additions and 65 deletions

View File

@@ -20,6 +20,8 @@ import aiohttp
from pydub import AudioSegment
from io import BytesIO
from wechat_ipad.models.appmsg_xml import MUSIC_XML
class GuessSongRedisDB:
"""猜歌名游戏Redis相关操作"""
@@ -135,17 +137,17 @@ class GuessSongPlugin(MessagePluginInterface):
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", [
@@ -438,52 +440,8 @@ class GuessSongPlugin(MessagePluginInterface):
singer_pic = song_info.get("singer_pic", "")
data_url = song_info.get("data_url", "")
xml_message = f"""<appmsg appid="wx904fb3ecf62c7dea" sdkver="0">
<title>{song_name}</title>
<des>{singer_name}-点击三角直接播放</des>
<action>view</action>
<type>3</type>
<showtype>0</showtype>
<content />
<url>{data_url}</url>
<dataurl>{play_url}</dataurl>
<lowurl/>
<lowdataurl/>
<recorditem />
<thumburl />
<messageaction />
<laninfo />
<extinfo />
<sourceusername />
<sourcedisplayname />
<commenturl />
<appattach>
<totallen>0</totallen>
<attachid />
<emoticonmd5></emoticonmd5>
<fileext />
<aeskey></aeskey>
</appattach>
<webviewshared>
<publisherId />
<publisherReqId>0</publisherReqId>
</webviewshared>
<weappinfo>
<pagepath />
<username />
<appid />
<appservicetype>0</appservicetype>
</weappinfo>
<websearch />
<songalbumurl>{singer_pic}</songalbumurl>
</appmsg>
<scene>0</scene>
<appinfo>
<version>49</version>
<appname>汽水音乐</appname>
</appinfo>
<commenturl />"""
xml_message = f"{MUSIC_XML}".format(song_name=song_name, singer_name=singer_name, play_url=play_url,
data_url=data_url, singer_pic=singer_pic)
self.LOG.info(f"发送音乐消息:{xml_message}")
res = await bot.send_app_message(wxid=receiver, xml=xml_message, type=0)
self.LOG.info(f"发送音乐消息 res:{res}")