diff --git a/plugins/message_summary/main.py b/plugins/message_summary/main.py index cb95a80..3b091b6 100644 --- a/plugins/message_summary/main.py +++ b/plugins/message_summary/main.py @@ -1,11 +1,11 @@ import json import re import threading +from pathlib import Path from typing import Dict, Any, Tuple, Optional, List import requests -from message_util import MessageUtil from utils.string_utils import remove_trailing_content from utils.wechat.message_to_db import MessageStorage from utils.compress_chat_data import compress_chat_data @@ -15,6 +15,7 @@ from utils.decorator.points_decorator import plugin_points_cost from utils.markdown_to_image import convert_md_str_to_image from utils.decorator.plugin_decorators import plugin_stats_decorator from utils.robot_cmd.robot_command import GroupBotManager, Feature, PermissionStatus +from wechat_ipad import WechatAPIClient class MessageSummaryPlugin(MessagePluginInterface): @@ -46,6 +47,7 @@ class MessageSummaryPlugin(MessagePluginInterface): def __init__(self): super().__init__() + self.bot: WechatAPIClient = None def initialize(self, context: Dict[str, Any]) -> bool: """初始化插件""" @@ -55,7 +57,6 @@ class MessageSummaryPlugin(MessagePluginInterface): self._api_key = api_config.get("api_key", "app-McGLzBhBjeBCSEi7n83MtuTo") self._api_url = api_config.get("api_url", "http://192.168.2.240/v1/chat-messages") self.message_storage = MessageStorage() - self.message_util: MessageUtil = context.get("message_util") self.LOG.info(f"初始化 {self.name} 插件成功") return True @@ -80,11 +81,12 @@ class MessageSummaryPlugin(MessagePluginInterface): @plugin_stats_decorator(plugin_name="群聊总结") @plugin_points_cost(10, "群聊总结消耗积分", Feature.SUMMARY_CAPABILITY) - 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]]: """处理消息""" try: # 检查是否是总结命令 content = message.get("content", "") + self.bot: WechatAPIClient = message.get("bot") if not content.startswith(self.command_prefix): return False, None @@ -94,7 +96,7 @@ class MessageSummaryPlugin(MessagePluginInterface): # 获取需要总结的内容 group_id = message.get("roomid") if not group_id: - self.message_util.send_text("只支持群聊消息总结", message.get("sender")) + await self.bot.send_text_message(group_id, "只支持群聊消息总结", message.get("sender")) return False, None # 权限判断 gbm: GroupBotManager = message.get("gbm") @@ -110,7 +112,7 @@ class MessageSummaryPlugin(MessagePluginInterface): # 获取群名并处理 group_name = all_contacts.get(group_id, group_id) group_name = self._sanitize_group_name(group_name) - self.message_util.send_text("⏳群消息总结中… 😊", group_id) + await self.bot.send_text_message(group_id, "⏳群消息总结中… 😊") # 创建线程异步处理总结生成和发送 summary_thread = threading.Thread( @@ -134,12 +136,12 @@ class MessageSummaryPlugin(MessagePluginInterface): summary, image_path = self._generate_summary(chat_content, group_name) if image_path: - self.message_util.send_file(image_path, group_id) + self.bot.send_image_message(group_id, Path(image_path)) else: - self.message_util.send_text("❌ 生成总结图片失败", group_id) + self.bot.send_text_message(group_id, "❌ 生成总结图片失败") except Exception as e: self.LOG.error(f"异步生成总结失败: {e}") - self.message_util.send_text(f"❌ 生成总结失败: {str(e)}", group_id) + self.bot.send_text_message(group_id, f"❌ 生成总结失败: {str(e)}") def _sanitize_group_name(self, group_name: str) -> str: """处理群名,去除特殊字符并限制长度""" diff --git a/plugins/music/main.py b/plugins/music/main.py index e443889..4530452 100644 --- a/plugins/music/main.py +++ b/plugins/music/main.py @@ -151,55 +151,51 @@ class MusicPlugin(MessagePluginInterface): singer_pic = song_info.get("singer_pic", "") data_url = song_info.get("data_url", "") - xml_message = f""" - - - - {song_name} - {singer_name} - view - 3 - 0 - - {data_url} - {play_url} - - - - - - - - - - - - 0 - - - - - - - - 0 - - - - - - 0 - - - {singer_pic} - - 0 - - 49 - 汽水音乐 - - - """ + xml_message = f""" + {song_name} + {singer_name} + view + 3 + 0 + + {data_url} + {play_url} + + + + + + + + + + + + 0 + + + + + + + + 0 + + + + + + 0 + + + {singer_pic} + +0 + + 49 + 汽水音乐 + +""" self.LOG.info(f"发送音乐消息:{xml_message}") res = await bot.send_app_message(wxid=receiver, xml=xml_message, type=0)