测试音乐信息
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user