重大版本调整:gewechat兼容。
This commit is contained in:
@@ -5,6 +5,7 @@ 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
|
||||
@@ -54,6 +55,8 @@ 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
|
||||
except Exception as e:
|
||||
@@ -88,13 +91,10 @@ class MessageSummaryPlugin(MessagePluginInterface):
|
||||
command = content[len(self.command_prefix):].split()[0]
|
||||
if command not in self.commands:
|
||||
return False, None
|
||||
wcf = message.get("wcf")
|
||||
# 获取需要总结的内容
|
||||
group_id = message.get("roomid")
|
||||
if not group_id:
|
||||
# 直接发送消息
|
||||
if wcf:
|
||||
wcf.send_text("只支持群聊消息总结", message.get("sender"))
|
||||
self.message_util.send_text("只支持群聊消息总结", message.get("sender"))
|
||||
return False, None
|
||||
# 权限判断
|
||||
gbm: GroupBotManager = message.get("gbm")
|
||||
@@ -110,18 +110,17 @@ class MessageSummaryPlugin(MessagePluginInterface):
|
||||
# 获取群名并处理
|
||||
group_name = all_contacts.get(group_id, group_id)
|
||||
group_name = self._sanitize_group_name(group_name)
|
||||
if wcf:
|
||||
wcf.send_text("⏳群消息总结中… 😊", group_id)
|
||||
self.message_util.send_text("⏳群消息总结中… 😊", group_id)
|
||||
|
||||
# 创建线程异步处理总结生成和发送
|
||||
summary_thread = threading.Thread(
|
||||
target=self._async_generate_and_send_summary,
|
||||
args=(chat_content, group_name, group_id, message)
|
||||
)
|
||||
summary_thread.daemon = True # 设置为守护线程,主程序退出时线程也会退出
|
||||
summary_thread.start()
|
||||
# 创建线程异步处理总结生成和发送
|
||||
summary_thread = threading.Thread(
|
||||
target=self._async_generate_and_send_summary,
|
||||
args=(chat_content, group_name, group_id, message)
|
||||
)
|
||||
summary_thread.daemon = True # 设置为守护线程,主程序退出时线程也会退出
|
||||
summary_thread.start()
|
||||
|
||||
return True, "异步总结已启动"
|
||||
return True, "异步总结已启动"
|
||||
|
||||
except Exception as e:
|
||||
self.LOG.error(f"处理消息总结命令失败: {e}")
|
||||
@@ -138,17 +137,17 @@ class MessageSummaryPlugin(MessagePluginInterface):
|
||||
wcf = message.get("wcf")
|
||||
if wcf:
|
||||
# if summary:
|
||||
# wcf.send_text(f"总结已生成:\n{summary}", group_id, message.get("sender"))
|
||||
# self.message_util.send_text(f"总结已生成:\n{summary}", group_id, message.get("sender"))
|
||||
|
||||
if image_path:
|
||||
wcf.send_file(image_path, group_id)
|
||||
self.message_util.send_file(image_path, group_id)
|
||||
else:
|
||||
wcf.send_text("❌ 生成总结图片失败", group_id)
|
||||
self.message_util.send_text("❌ 生成总结图片失败", group_id)
|
||||
except Exception as e:
|
||||
self.LOG.error(f"异步生成总结失败: {e}")
|
||||
wcf = message.get("wcf")
|
||||
if wcf:
|
||||
wcf.send_text(f"❌ 生成总结失败: {str(e)}", group_id)
|
||||
self.message_util.send_text(f"❌ 生成总结失败: {str(e)}", group_id)
|
||||
|
||||
def _sanitize_group_name(self, group_name: str) -> str:
|
||||
"""处理群名,去除特殊字符并限制长度"""
|
||||
|
||||
Reference in New Issue
Block a user