From 44be041eacd15e4ff0821f2d5fcf57f4637d019c Mon Sep 17 00:00:00 2001 From: liuwei Date: Mon, 26 May 2025 15:00:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E9=9F=B3=E4=B9=90=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/music/main.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/plugins/music/main.py b/plugins/music/main.py index 00a2290..e004f78 100644 --- a/plugins/music/main.py +++ b/plugins/music/main.py @@ -1,3 +1,5 @@ +import base64 + from loguru import logger import requests from typing import Dict, Any, List, Optional, Tuple @@ -9,6 +11,8 @@ from utils.robot_cmd.robot_command import Feature, PermissionStatus, GroupBotMan from utils.decorator.points_decorator import plugin_points_cost from wechat_ipad import WechatAPIClient +import aiohttp + class MusicPlugin(MessagePluginInterface): """音乐点播插件""" @@ -141,16 +145,14 @@ class MusicPlugin(MessagePluginInterface): self.LOG.error(f"搜索歌曲出错: {e}") return {} - - async def url_to_base64(url): + async def url_to_base64(self, play_url: str): async with aiohttp.ClientSession() as session: - async with session.get(url) as resp: + async with session.get(play_url) as resp: resp.raise_for_status() data = await resp.read() b64_str = base64.b64encode(data).decode('utf-8') return b64_str - async def _send_music_message(self, bot: WechatAPIClient, song_info: Dict[str, Any], receiver: str) -> bool: """发送音乐消息""" try: @@ -209,7 +211,7 @@ class MusicPlugin(MessagePluginInterface): 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}") - voice_base64 =url_to_base64(play_url) + voice_base64 = await self.url_to_base64(play_url) res = await bot.send_voice_message(wxid=receiver, voice=voice_base64) self.LOG.info(f"发送音乐消息 voice res:{res}") return True