855 协议版本-调整完毕内容

This commit is contained in:
liuwei
2025-04-30 13:22:33 +08:00
parent 869bce8a18
commit 454d084715
88 changed files with 1565 additions and 7816 deletions

View File

@@ -1,14 +1,13 @@
import logging
from loguru import logger
import requests
from typing import Dict, Any, List, Optional, Tuple
from gewechat.client import gewe_client
from gewechat.response.gewe_resp import GeweResponse
from plugin_common.message_plugin_interface import MessagePluginInterface
from plugin_common.plugin_interface import PluginStatus
from utils.decorator.plugin_decorators import plugin_stats_decorator
from utils.robot_cmd.robot_command import Feature, PermissionStatus, GroupBotManager
from utils.decorator.points_decorator import plugin_points_cost
from wechat_ipad import WechatAPIClient
class MusicPlugin(MessagePluginInterface):
@@ -43,7 +42,7 @@ class MusicPlugin(MessagePluginInterface):
def initialize(self, context: Dict[str, Any]) -> bool:
"""初始化插件"""
self.LOG = logging.getLogger(f"Plugin.{self.name}")
self.LOG = logger
self.LOG.info(f"正在初始化 {self.name} 插件...")
# 保存上下文对象
@@ -81,7 +80,7 @@ class MusicPlugin(MessagePluginInterface):
@plugin_stats_decorator(plugin_name="音乐点播")
@plugin_points_cost(2, "音乐点播消耗积分", Feature.MUSIC)
def process_message(self, message: Dict[str, Any]) -> Tuple[bool, Optional[str]]:
async def process_message(self, message: Dict[str, Any]) -> Tuple[bool, Optional[str]]:
"""处理消息"""
content = str(message.get("content", "")).strip()
self.LOG.info(f"插件执行: {self.name}{content}")
@@ -89,11 +88,12 @@ class MusicPlugin(MessagePluginInterface):
sender = message.get("sender")
roomid = message.get("roomid", "")
gbm: GroupBotManager = message.get("gbm")
bot: WechatAPIClient = message.get("bot")
# 检查命令格式
if len(content.split(" ")) == 1:
self.message_util.send_text(f"❌命令格式错误!\n{self.command_format}",
(roomid if roomid else sender), sender)
await bot.send_text_message((roomid if roomid else sender), f"❌命令格式错误!\n{self.command_format}"
, sender)
return False, "命令格式错误"
# 检查权限
@@ -107,12 +107,11 @@ class MusicPlugin(MessagePluginInterface):
# 搜索歌曲
song_info = self._search_song(user_song_name)
if not song_info or not song_info.get("play_url"):
self.message_util.send_text(f"❌未找到歌曲:{user_song_name}",
(roomid if roomid else sender), sender)
await bot.send_text_message((roomid if roomid else sender), f"❌未找到歌曲:{user_song_name}", sender)
return False, "未找到歌曲"
# 发送音乐
self._send_music_message(song_info, roomid or sender)
await self._send_music_message(bot, song_info, roomid or sender)
return True, "发送成功"
except Exception as e:
@@ -143,7 +142,7 @@ class MusicPlugin(MessagePluginInterface):
self.LOG.error(f"搜索歌曲出错: {e}")
return {}
def _send_music_message(self, song_info: Dict[str, Any], receiver: str) -> bool:
async def _send_music_message(self, bot: WechatAPIClient, song_info: Dict[str, Any], receiver: str) -> bool:
"""发送音乐消息"""
try:
song_name = song_info.get("song_name", "")
@@ -201,11 +200,11 @@ class MusicPlugin(MessagePluginInterface):
</appinfo>
<commenturl />
</msg>"""
resp = gewe_client.client.post_app_msg(gewe_client.client.app_id, receiver, xml_message)
data = GeweResponse(resp)
self.LOG.info(f"发送音乐消息:{data}")
if data.is_success:
return True
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}")
return True
except Exception as e:
self.LOG.error(f"发送音乐消息出错: {e}")