重大版本调整:gewechat兼容。
This commit is contained in:
@@ -117,7 +117,7 @@ class BeautyLegPlugin(MessagePluginInterface):
|
||||
# 发送图片
|
||||
random_file_path = os.path.abspath(random_file_path)
|
||||
self.LOG.info(f"BeautyLeg.random_file_path: {random_file_path}")
|
||||
result = wcf.send_file(random_file_path, (roomid if roomid else sender))
|
||||
result = self.message_util.send_file(random_file_path, (roomid if roomid else sender))
|
||||
self.LOG.info(f"发送图片结果: {result}")
|
||||
return True, "发送成功"
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import time
|
||||
import re # 添加re模块导入
|
||||
from typing import Dict, Any, List, Optional, Tuple
|
||||
|
||||
from wcferry import Wcf
|
||||
|
||||
from message_util import MessageUtil
|
||||
from plugin_common.message_plugin_interface import MessagePluginInterface
|
||||
@@ -63,7 +62,6 @@ class DifyPlugin(MessagePluginInterface):
|
||||
self.LOG.info(f"正在初始化 {self.name} 插件...")
|
||||
|
||||
# 保存上下文对象
|
||||
self.wcf = context.get("wcf")
|
||||
self.event_system = context.get("event_system")
|
||||
self.message_util: MessageUtil = context.get("message_util")
|
||||
self.gbm = context.get("gbm")
|
||||
|
||||
@@ -6,8 +6,7 @@ import traceback
|
||||
import requests
|
||||
from typing import Dict, Any, List, Optional, Tuple
|
||||
|
||||
from wcferry import Wcf
|
||||
|
||||
from message_util import MessageUtil
|
||||
from plugin_common.message_plugin_interface import MessagePluginInterface
|
||||
from plugin_common.plugin_interface import PluginStatus
|
||||
from utils.decorator.plugin_decorators import plugin_stats_decorator
|
||||
@@ -61,9 +60,8 @@ class DouyinParserPlugin(MessagePluginInterface):
|
||||
self.LOG.info(f"正在初始化 {self.name} 插件...")
|
||||
|
||||
# 保存上下文对象
|
||||
self.wcf = context.get("wcf")
|
||||
self.event_system = context.get("event_system")
|
||||
self.message_util = context.get("message_util")
|
||||
self.message_util:MessageUtil = context.get("message_util")
|
||||
self.gbm = context.get("gbm")
|
||||
|
||||
# 从配置中获取参数
|
||||
@@ -103,7 +101,6 @@ class DouyinParserPlugin(MessagePluginInterface):
|
||||
self.LOG.info(f"插件执行: {self.name}:{content}")
|
||||
sender = message.get("sender")
|
||||
roomid = message.get("roomid", "")
|
||||
wcf: Wcf = message.get("wcf")
|
||||
gbm: GroupBotManager = message.get("gbm")
|
||||
|
||||
# 检查权限
|
||||
@@ -138,14 +135,14 @@ class DouyinParserPlugin(MessagePluginInterface):
|
||||
# 下载并发送文件
|
||||
mp4_path = self._download_stream(video_url, os.path.join(self.download_dir, "douyin.mp4"))
|
||||
if mp4_path:
|
||||
wcf.send_file(mp4_path, (roomid if roomid else sender))
|
||||
self.message_util.send_file(mp4_path, (roomid if roomid else sender))
|
||||
return True, "发送视频文件成功"
|
||||
else:
|
||||
print(f"❌下载视频失败")
|
||||
return False, "下载视频失败"
|
||||
else:
|
||||
# 发送卡片
|
||||
wcf.send_rich_text(
|
||||
self.message_util.send_rich_text(
|
||||
"BOT-PC直接查看",
|
||||
"gh_11",
|
||||
title[:30],
|
||||
|
||||
@@ -3,8 +3,6 @@ import logging
|
||||
from datetime import datetime
|
||||
from typing import Dict, Any, List, Optional, Tuple
|
||||
|
||||
from wcferry import Wcf
|
||||
|
||||
from message_util import MessageUtil
|
||||
from plugin_common.message_plugin_interface import MessagePluginInterface
|
||||
from plugin_common.plugin_interface import PluginStatus
|
||||
@@ -52,7 +50,6 @@ class GameTaskPlugin(MessagePluginInterface):
|
||||
self.LOG.info(f"正在初始化 {self.name} 插件...")
|
||||
|
||||
# 保存上下文对象
|
||||
self.wcf = context.get("wcf")
|
||||
self.event_system = context.get("event_system")
|
||||
self.message_util: MessageUtil = context.get("message_util")
|
||||
|
||||
@@ -115,7 +112,6 @@ class GameTaskPlugin(MessagePluginInterface):
|
||||
command = content.split(" ")[0].lower()
|
||||
sender = message.get("sender")
|
||||
roomid = message.get("roomid", "")
|
||||
wcf: Wcf = message.get("wcf")
|
||||
gbm: GroupBotManager = message.get("gbm")
|
||||
all_contacts = message.get("all_contacts", {})
|
||||
|
||||
|
||||
@@ -4,8 +4,7 @@ import threading
|
||||
import time # 添加这一行
|
||||
from typing import Dict, Any, List, Optional, Tuple
|
||||
|
||||
from wcferry import Wcf
|
||||
|
||||
from message_util import MessageUtil
|
||||
from plugin_common.message_plugin_interface import MessagePluginInterface
|
||||
from plugin_common.plugin_interface import PluginStatus
|
||||
from utils.decorator.plugin_decorators import plugin_stats_decorator
|
||||
@@ -55,12 +54,13 @@ class GlobalNewsPlugin(MessagePluginInterface):
|
||||
self.LOG.info(f"正在初始化 {self.name} 插件...")
|
||||
|
||||
# 保存上下文对象
|
||||
self.wcf = context.get("wcf")
|
||||
self.event_system = context.get("event_system")
|
||||
self.message_util = context.get("message_util")
|
||||
self.message_util: MessageUtil = context.get("message_util")
|
||||
|
||||
self._commands = self._config.get("GlobalNews", {}).get("command", ["全球新闻", "国际新闻", "环球新闻", "政经新闻"])
|
||||
self.command_format = self._config.get("GlobalNews", {}).get("command-format", "全球新闻 - 获取最新的全球政治经济新闻")
|
||||
self._commands = self._config.get("GlobalNews", {}).get("command",
|
||||
["全球新闻", "国际新闻", "环球新闻", "政经新闻"])
|
||||
self.command_format = self._config.get("GlobalNews", {}).get("command-format",
|
||||
"全球新闻 - 获取最新的全球政治经济新闻")
|
||||
self.enable = self._config.get("GlobalNews", {}).get("enable", True)
|
||||
|
||||
self.LOG.info(f"[{self.name}] 插件初始化完成,指令:{self._commands}")
|
||||
@@ -96,7 +96,6 @@ class GlobalNewsPlugin(MessagePluginInterface):
|
||||
self.LOG.info(f"插件执行: {self.name}:{content}")
|
||||
sender = message.get("sender")
|
||||
roomid = message.get("roomid", "")
|
||||
wcf: Wcf = message.get("wcf")
|
||||
gbm: GroupBotManager = message.get("gbm")
|
||||
|
||||
# 检查权限
|
||||
@@ -105,48 +104,48 @@ class GlobalNewsPlugin(MessagePluginInterface):
|
||||
|
||||
# 生成唯一任务ID
|
||||
task_id = f"{sender}_{roomid}_{int(time.time())}"
|
||||
|
||||
|
||||
# 发送等待消息
|
||||
wcf.send_text("🌍正在获取全球新闻,请稍候...",
|
||||
(roomid if roomid else sender), sender)
|
||||
|
||||
self.message_util.send_text("🌍正在获取全球新闻,请稍候...",
|
||||
(roomid if roomid else sender), sender)
|
||||
|
||||
# 启动异步任务
|
||||
self._start_news_task(task_id, sender, roomid, wcf)
|
||||
|
||||
self._start_news_task(task_id, sender, roomid)
|
||||
|
||||
return True, "新闻获取任务已启动"
|
||||
|
||||
def _start_news_task(self, task_id: str, sender: str, roomid: str, wcf: Wcf):
|
||||
def _start_news_task(self, task_id: str, sender: str, roomid: str):
|
||||
"""启动异步新闻获取任务"""
|
||||
thread = threading.Thread(
|
||||
target=self._fetch_news_thread,
|
||||
args=(task_id, sender, roomid, wcf)
|
||||
args=(task_id, sender, roomid)
|
||||
)
|
||||
thread.daemon = True
|
||||
thread.start()
|
||||
self._news_tasks[task_id] = thread
|
||||
self.LOG.info(f"启动新闻获取任务: {task_id}")
|
||||
|
||||
def _fetch_news_thread(self, task_id: str, sender: str, roomid: str, wcf: Wcf):
|
||||
def _fetch_news_thread(self, task_id: str, sender: str, roomid: str):
|
||||
"""在单独的线程中运行异步新闻获取任务"""
|
||||
try:
|
||||
loop = asyncio.new_event_loop()
|
||||
asyncio.set_event_loop(loop)
|
||||
news_result = loop.run_until_complete(self._fetch_news_async())
|
||||
loop.close()
|
||||
|
||||
|
||||
# 处理结果
|
||||
if news_result:
|
||||
# 发送新闻图片
|
||||
receiver = roomid if roomid else sender
|
||||
wcf.send_image(news_result, receiver)
|
||||
wcf.send_text("🌍全球新闻获取完成!", receiver, sender)
|
||||
self.message_util.send_image(news_result, receiver)
|
||||
self.message_util.send_text("🌍全球新闻获取完成!", receiver, sender)
|
||||
else:
|
||||
wcf.send_text("❌获取新闻失败,请稍后再试",
|
||||
(roomid if roomid else sender), sender)
|
||||
self.message_util.send_text("❌获取新闻失败,请稍后再试",
|
||||
(roomid if roomid else sender), sender)
|
||||
except Exception as e:
|
||||
self.LOG.error(f"新闻获取任务出错: {e}")
|
||||
wcf.send_text(f"❌获取新闻出错: {str(e)}",
|
||||
(roomid if roomid else sender), sender)
|
||||
self.message_util.send_text(f"❌获取新闻出错: {str(e)}",
|
||||
(roomid if roomid else sender), sender)
|
||||
finally:
|
||||
# 清理任务
|
||||
if task_id in self._news_tasks:
|
||||
@@ -163,23 +162,23 @@ class GlobalNewsPlugin(MessagePluginInterface):
|
||||
self._run_in_executor(fox),
|
||||
self._run_in_executor(bbc)
|
||||
]
|
||||
|
||||
|
||||
# 并行执行所有任务
|
||||
results = await asyncio.gather(*tasks)
|
||||
|
||||
|
||||
# 合并结果
|
||||
news_titles = "\n".join(results)
|
||||
|
||||
|
||||
# 使用AI分析新闻
|
||||
markdown_news = await self._run_in_executor(
|
||||
dify_news_title_analyze, news_titles
|
||||
)
|
||||
|
||||
|
||||
# 转换为图片
|
||||
image_path = await self._run_in_executor(
|
||||
convert_md_str_to_image, markdown_news, "news_output.png"
|
||||
)
|
||||
|
||||
|
||||
return image_path
|
||||
except Exception as e:
|
||||
self.LOG.error(f"异步获取新闻失败: {e}")
|
||||
@@ -188,4 +187,4 @@ class GlobalNewsPlugin(MessagePluginInterface):
|
||||
async def _run_in_executor(self, func, *args):
|
||||
"""在线程池中运行同步函数"""
|
||||
loop = asyncio.get_event_loop()
|
||||
return await loop.run_in_executor(None, func, *args)
|
||||
return await loop.run_in_executor(None, func, *args)
|
||||
|
||||
@@ -3,7 +3,6 @@ import re
|
||||
from datetime import datetime
|
||||
from typing import Dict, Any, List, Optional, Tuple
|
||||
|
||||
from wcferry import Wcf
|
||||
|
||||
from plugin_common.message_plugin_interface import MessagePluginInterface
|
||||
from plugin_common.plugin_interface import PluginStatus
|
||||
@@ -45,8 +44,6 @@ class GroupAddPlugin(MessagePluginInterface):
|
||||
self.LOG = logging.getLogger(f"Plugin.{self.name}")
|
||||
self.LOG.info(f"正在初始化 {self.name} 插件...")
|
||||
|
||||
# 保存上下文对象
|
||||
self.wcf = context.get("wcf")
|
||||
# 获取群管理器
|
||||
self.gbm = context.get("gbm")
|
||||
|
||||
@@ -99,8 +96,7 @@ class GroupAddPlugin(MessagePluginInterface):
|
||||
"""处理消息"""
|
||||
content = message.get("content", "")
|
||||
roomid = message.get("roomid", "")
|
||||
wcf: Wcf = message.get("wcf")
|
||||
|
||||
|
||||
self.LOG.info(f"插件执行: {self.name}:{content}")
|
||||
|
||||
# 提取昵称
|
||||
@@ -116,8 +112,8 @@ class GroupAddPlugin(MessagePluginInterface):
|
||||
welcome_message = f"🎉 欢迎 【{nickname}】 加入群聊👋 \n 🕒 {now_time} 🕒 !"
|
||||
|
||||
# 发送欢迎消息
|
||||
wcf.send_text(welcome_message, roomid)
|
||||
|
||||
# self.me.send_text(welcome_message, roomid)
|
||||
|
||||
self.LOG.info(f"已发送欢迎消息给新成员 {nickname} 在群 {roomid}")
|
||||
return True, f"已欢迎 {nickname}"
|
||||
|
||||
|
||||
@@ -3,8 +3,9 @@ import redis
|
||||
import re
|
||||
from typing import Dict, Any, List, Optional, Tuple
|
||||
|
||||
from wcferry import Wcf
|
||||
from gewechat_client import GewechatClient
|
||||
|
||||
from message_util import MessageUtil
|
||||
from plugin_common.message_plugin_interface import MessagePluginInterface
|
||||
from plugin_common.plugin_interface import PluginStatus
|
||||
from utils.decorator.plugin_decorators import plugin_stats_decorator
|
||||
@@ -50,13 +51,13 @@ class GroupAutoInvitePlugin(MessagePluginInterface):
|
||||
self.LOG = logging.getLogger(f"Plugin.{self.name}")
|
||||
self.LOG.info(f"正在初始化 {self.name} 插件...")
|
||||
|
||||
# 保存上下文对象
|
||||
self.wcf = context.get("wcf")
|
||||
# 获取群管理器
|
||||
self.gbm = context.get("gbm")
|
||||
# 获取Redis连接池
|
||||
self.redis_pool = context.get("redis_pool")
|
||||
|
||||
self.clent:GewechatClient = context.get("clent")
|
||||
self.message_util: MessageUtil = context.get("message_util")
|
||||
# 从配置中获取命令和启用状态
|
||||
plugin_config = self._config.get("GroupAutoInvite", {})
|
||||
self._commands = plugin_config.get("command", ["#加群配置"])
|
||||
@@ -111,27 +112,26 @@ class GroupAutoInvitePlugin(MessagePluginInterface):
|
||||
|
||||
sender = message.get("sender")
|
||||
roomid = message.get("roomid", "")
|
||||
wcf: Wcf = message.get("wcf")
|
||||
gbm: GroupBotManager = message.get("gbm")
|
||||
|
||||
# 处理加群配置命令
|
||||
if content.startswith("#加群配置|"):
|
||||
return self._handle_config_command(content, sender, roomid, wcf, gbm)
|
||||
return self._handle_config_command(content, sender, roomid, gbm)
|
||||
|
||||
# 处理加群请求
|
||||
match = re.search(r"^#加群\s+(\w+)$", content)
|
||||
if match:
|
||||
return self._handle_join_request(match.group(1), sender, roomid, wcf, gbm)
|
||||
return self._handle_join_request(match.group(1), sender, roomid, gbm)
|
||||
|
||||
return False, "无法处理的消息"
|
||||
|
||||
def _handle_config_command(self, content: str, sender: str, roomid: str, wcf: Wcf, gbm: GroupBotManager) -> Tuple[
|
||||
def _handle_config_command(self, content: str, sender: str, roomid: str, gbm: GroupBotManager) -> Tuple[
|
||||
bool, Optional[str]]:
|
||||
"""处理配置命令"""
|
||||
# 检查是否为管理员
|
||||
admin_list = self.gbm.get_admin_list()
|
||||
if sender not in admin_list:
|
||||
wcf.send_text("⚠️ 权限不足,只有管理员才能配置群邀请功能",
|
||||
self.message_util.send_text("⚠️ 权限不足,只有管理员才能配置群邀请功能",
|
||||
(roomid if roomid else sender), sender)
|
||||
return True, "权限不足"
|
||||
|
||||
@@ -140,10 +140,10 @@ class GroupAutoInvitePlugin(MessagePluginInterface):
|
||||
result = self.process_command(command)
|
||||
|
||||
# 发送结果
|
||||
wcf.send_text(result, (roomid if roomid else sender), sender)
|
||||
self.message_util.send_text(result, (roomid if roomid else sender), sender)
|
||||
return True, "配置命令处理成功"
|
||||
|
||||
def _handle_join_request(self, key: str, sender: str, roomid: str, wcf: Wcf, gbm: GroupBotManager) -> Tuple[
|
||||
def _handle_join_request(self, key: str, sender: str, roomid: str, gbm: GroupBotManager) -> Tuple[
|
||||
bool, Optional[str]]:
|
||||
"""处理加群请求"""
|
||||
try:
|
||||
@@ -152,29 +152,29 @@ class GroupAutoInvitePlugin(MessagePluginInterface):
|
||||
|
||||
# 检查是否找到群ID
|
||||
if isinstance(group_id, str) and "没有关联的群ID" in group_id:
|
||||
wcf.send_text(f"⚠️ 未找到关键词 '{key}' 对应的群聊", sender)
|
||||
self.message_util.send_text(f"⚠️ 未找到关键词 '{key}' 对应的群聊", sender)
|
||||
return True, "未找到群聊"
|
||||
# 判断是否在群里面,如果在,则不添加
|
||||
con = ContactManager.get_instance()
|
||||
members = con.get_group_members(group_id)
|
||||
# 如果在群里面,则不添加
|
||||
if sender in members:
|
||||
wcf.send_text(f"⚠️ 你已经在群聊中了,无需重复添加", sender)
|
||||
self.message_util.send_text(f"⚠️ 你已经在群聊中了,无需重复添加", sender)
|
||||
return True, "你已经在群聊中了"
|
||||
# 发送邀请
|
||||
self.LOG.info(f"邀请用户 {sender} 加入群 {group_id}")
|
||||
result = wcf.invite_chatroom_members(group_id, sender)
|
||||
result = self.message_util.invite_member(group_id, sender)
|
||||
|
||||
if result:
|
||||
wcf.send_text(f"✅ 已发送邀请,请查看群聊邀请通知", sender)
|
||||
self.message_util.send_text(f"✅ 已发送邀请,请查看群聊邀请通知", sender)
|
||||
return True, "邀请发送成功"
|
||||
else:
|
||||
wcf.send_text(f"❌ 邀请发送失败,请稍后再试", sender)
|
||||
self.message_util.send_text(f"❌ 邀请发送失败,请稍后再试", sender)
|
||||
return False, "邀请发送失败"
|
||||
|
||||
except Exception as e:
|
||||
self.LOG.error(f"处理加群请求出错: {e}")
|
||||
wcf.send_text(f"❌ 处理加群请求出错: {e}", sender)
|
||||
self.message_util.send_text(f"❌ 处理加群请求出错: {e}", sender)
|
||||
return False, f"处理出错: {e}"
|
||||
|
||||
def add_mapping(self, key, group_id):
|
||||
|
||||
@@ -4,8 +4,6 @@ import time
|
||||
from datetime import datetime
|
||||
from typing import Dict, Any, List, Optional, Tuple
|
||||
|
||||
from wcferry import Wcf
|
||||
|
||||
from plugin_common.message_plugin_interface import MessagePluginInterface
|
||||
from plugin_common.plugin_interface import PluginStatus
|
||||
from utils.robot_cmd.robot_command import Feature, PermissionStatus, GroupBotManager
|
||||
@@ -51,8 +49,6 @@ class GroupMemberChangePlugin(MessagePluginInterface):
|
||||
"""初始化插件"""
|
||||
self.LOG.info(f"正在初始化 {self.name} 插件...")
|
||||
|
||||
# 保存上下文对象
|
||||
self.wcf: Wcf = context.get("wcf")
|
||||
# 创建消息工具实例message_util
|
||||
self.message_util: MessageUtil = context.get("message_util")
|
||||
|
||||
@@ -130,7 +126,7 @@ class GroupMemberChangePlugin(MessagePluginInterface):
|
||||
"""检查指定群的成员变化"""
|
||||
try:
|
||||
# 获取当前群成员
|
||||
current_members = self.wcf.get_chatroom_members(group_id)
|
||||
current_members = self.message_util.get_chatroom_members(group_id)
|
||||
|
||||
# 添加安全检查:如果获取到的成员列表为空,可能是接口异常
|
||||
if not current_members:
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import logging
|
||||
from typing import Dict, Any, List, Optional, Tuple
|
||||
|
||||
from wcferry import Wcf
|
||||
|
||||
from gewechat.call_back_message.message import WxMessage
|
||||
from message_util import MessageUtil
|
||||
from plugin_common.message_plugin_interface import MessagePluginInterface
|
||||
from plugin_common.plugin_interface import PluginStatus
|
||||
@@ -51,7 +50,6 @@ class GroupVirtualPlugin(MessagePluginInterface):
|
||||
self.LOG.info(f"正在初始化 {self.name} 插件...")
|
||||
|
||||
# 保存上下文对象
|
||||
self.wcf: Wcf = context.get("wcf")
|
||||
self.event_system = context.get("event_system")
|
||||
self.message_util: MessageUtil = context.get("message_util")
|
||||
|
||||
@@ -99,9 +97,9 @@ class GroupVirtualPlugin(MessagePluginInterface):
|
||||
"""处理消息"""
|
||||
roomid = message.get("roomid", "")
|
||||
sender = message.get("sender", "")
|
||||
|
||||
full_wx_msg: WxMessage = message.get("full_wx_msg", "")
|
||||
# 检查是否是机器人自己发送的消息
|
||||
if sender == self.wcf.self_wxid:
|
||||
if full_wx_msg.from_self():
|
||||
return False, "不转发自己的消息"
|
||||
|
||||
# 获取该群所在的所有虚拟聊天组
|
||||
|
||||
@@ -6,7 +6,6 @@ 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 GroupBotManager
|
||||
from wcferry import Wcf
|
||||
|
||||
|
||||
class MessageRecallPlugin(MessagePluginInterface):
|
||||
@@ -44,8 +43,6 @@ class MessageRecallPlugin(MessagePluginInterface):
|
||||
self.LOG = logging.getLogger(f"Plugin.{self.name}")
|
||||
self.LOG.info(f"正在初始化 {self.name} 插件...")
|
||||
|
||||
# 保存上下文对象
|
||||
self.wcf: Wcf = context.get("wcf")
|
||||
self.event_system = context.get("event_system")
|
||||
self.message_util: MessageUtil = context.get("message_util")
|
||||
|
||||
@@ -92,48 +89,47 @@ class MessageRecallPlugin(MessagePluginInterface):
|
||||
|
||||
sender = message.get("sender")
|
||||
roomid = message.get("roomid", "")
|
||||
wcf: Wcf = message.get("wcf")
|
||||
|
||||
# 检查是否是管理员
|
||||
admin_list = GroupBotManager.get_admin_list()
|
||||
self.LOG.info(f"admin_list={admin_list}")
|
||||
# if sender not in admin_list:
|
||||
# wcf.send_text("⚠️ 权限不足,只有管理员才能撤回消息",
|
||||
# self.message_util.send_text("⚠️ 权限不足,只有管理员才能撤回消息",
|
||||
# (roomid if roomid else sender), sender)
|
||||
# return True, "权限不足"
|
||||
|
||||
# 解析命令获取消息ID
|
||||
parts = content.split(" ", 1)
|
||||
if len(parts) < 2:
|
||||
wcf.send_text(f"❌命令格式错误!\n{self.command_format}",
|
||||
self.message_util.send_text(f"❌命令格式错误!\n{self.command_format}",
|
||||
(roomid if roomid else sender), sender)
|
||||
return True, "命令格式错误"
|
||||
|
||||
try:
|
||||
# 从数据库里面提取可以处理的消息and StrTalker ={roomid}
|
||||
sql = (f"SELECT * FROM MSG where IsSender=1 and CreateTime > (strftime('%s', 'now') - 120) "
|
||||
f"limit {parts[1]}")
|
||||
data = wcf.query_sql('MSG0.db', sql)
|
||||
self.LOG.info(f"SQL:{sql}\n 查询到可撤回数据: {data}")
|
||||
if not data:
|
||||
wcf.send_text("❌ 没有可撤回的消息", (roomid if roomid else sender), sender)
|
||||
return True, "没有可撤回的消息"
|
||||
for item in data:
|
||||
if item["MsgSvrID"]:
|
||||
# 调用撤回消息API
|
||||
result = wcf.revoke_msg(item["MsgSvrID"])
|
||||
if result:
|
||||
wcf.send_text("✅ 消息撤回成功", (roomid if roomid else sender), sender)
|
||||
return True, "撤回成功"
|
||||
else:
|
||||
wcf.send_text("❌ 消息撤回失败,可能是消息ID无效或已超过撤回时间限制(2分钟)",
|
||||
(roomid if roomid else sender), sender)
|
||||
return True, "撤回失败"
|
||||
|
||||
except Exception as e:
|
||||
self.LOG.error(f"撤回消息出错: {e}")
|
||||
wcf.send_text(f"❌ 撤回消息出错: {str(e)}", (roomid if roomid else sender), sender)
|
||||
return True, f"处理出错: {e}"
|
||||
#
|
||||
# try:
|
||||
# # 从数据库里面提取可以处理的消息and StrTalker ={roomid}
|
||||
# sql = (f"SELECT * FROM MSG where IsSender=1 and CreateTime > (strftime('%s', 'now') - 120) "
|
||||
# f"limit {parts[1]}")
|
||||
# data = self.message_util.query_sql('MSG0.db', sql)
|
||||
# self.LOG.info(f"SQL:{sql}\n 查询到可撤回数据: {data}")
|
||||
# if not data:
|
||||
# self.message_util.send_text("❌ 没有可撤回的消息", (roomid if roomid else sender), sender)
|
||||
# return True, "没有可撤回的消息"
|
||||
# for item in data:
|
||||
# if item["MsgSvrID"]:
|
||||
# # 调用撤回消息API
|
||||
# result = self.message_util.revoke_msg(item["MsgSvrID"])
|
||||
# if result:
|
||||
# self.message_util.send_text("✅ 消息撤回成功", (roomid if roomid else sender), sender)
|
||||
# return True, "撤回成功"
|
||||
# else:
|
||||
# self.message_util.send_text("❌ 消息撤回失败,可能是消息ID无效或已超过撤回时间限制(2分钟)",
|
||||
# (roomid if roomid else sender), sender)
|
||||
# return True, "撤回失败"
|
||||
#
|
||||
# except Exception as e:
|
||||
# self.LOG.error(f"撤回消息出错: {e}")
|
||||
# self.message_util.send_text(f"❌ 撤回消息出错: {str(e)}", (roomid if roomid else sender), sender)
|
||||
# return True, f"处理出错: {e}"
|
||||
|
||||
def get_help(self) -> str:
|
||||
"""获取插件帮助信息"""
|
||||
|
||||
@@ -3,7 +3,6 @@ import logging
|
||||
import pytz
|
||||
from typing import Dict, Any, List, Optional, Tuple
|
||||
|
||||
from wcferry import Wcf
|
||||
|
||||
from db.connection import DBConnectionManager
|
||||
from message_util import MessageUtil
|
||||
@@ -64,7 +63,6 @@ class MessageSignPlugin(MessagePluginInterface):
|
||||
self.LOG.info(f"正在初始化 {self.name} 插件...")
|
||||
|
||||
# 保存上下文对象
|
||||
self.wcf = context.get("wcf")
|
||||
self.event_system = context.get("event_system")
|
||||
self.message_util: MessageUtil = context.get("message_util")
|
||||
self.gbm = context.get("gbm")
|
||||
@@ -217,7 +215,6 @@ class MessageSignPlugin(MessagePluginInterface):
|
||||
"""处理签到请求"""
|
||||
sender = message.get("sender")
|
||||
roomid = message.get("roomid", "")
|
||||
wcf: Wcf = message.get("wcf")
|
||||
all_contacts = message.get("all_contacts", {})
|
||||
|
||||
try:
|
||||
|
||||
@@ -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:
|
||||
"""处理群名,去除特殊字符并限制长度"""
|
||||
|
||||
@@ -3,7 +3,6 @@ import requests
|
||||
import lz4.block as lb
|
||||
from typing import Dict, Any, List, Optional, Tuple
|
||||
|
||||
from wcferry import Wcf
|
||||
|
||||
from plugin_common.message_plugin_interface import MessagePluginInterface
|
||||
from plugin_common.plugin_interface import PluginStatus
|
||||
@@ -48,7 +47,6 @@ class MusicPlugin(MessagePluginInterface):
|
||||
self.LOG.info(f"正在初始化 {self.name} 插件...")
|
||||
|
||||
# 保存上下文对象
|
||||
self.wcf = context.get("wcf")
|
||||
self.event_system = context.get("event_system")
|
||||
self.message_util = context.get("message_util")
|
||||
|
||||
@@ -90,12 +88,11 @@ class MusicPlugin(MessagePluginInterface):
|
||||
command = content.split(" ")[0]
|
||||
sender = message.get("sender")
|
||||
roomid = message.get("roomid", "")
|
||||
wcf: Wcf = message.get("wcf")
|
||||
gbm: GroupBotManager = message.get("gbm")
|
||||
|
||||
# 检查命令格式
|
||||
if len(content.split(" ")) == 1:
|
||||
wcf.send_text(f"❌命令格式错误!\n{self.command_format}",
|
||||
self.message_util.send_text(f"❌命令格式错误!\n{self.command_format}",
|
||||
(roomid if roomid else sender), sender)
|
||||
return False, "命令格式错误"
|
||||
|
||||
@@ -110,7 +107,7 @@ class MusicPlugin(MessagePluginInterface):
|
||||
# 搜索歌曲
|
||||
song_info = self._search_song(user_song_name)
|
||||
if not song_info or not song_info.get("play_url"):
|
||||
wcf.send_text(f"❌未找到歌曲:{user_song_name}",
|
||||
self.message_util.send_text(f"❌未找到歌曲:{user_song_name}",
|
||||
(roomid if roomid else sender), sender)
|
||||
return False, "未找到歌曲"
|
||||
|
||||
@@ -204,19 +201,18 @@ class MusicPlugin(MessagePluginInterface):
|
||||
</appinfo>
|
||||
<commenturl />
|
||||
</msg>"""
|
||||
|
||||
# 修改消息数据库里面的消息content内容
|
||||
text_bytes = xml_message.encode('utf-8')
|
||||
compressed_data = lb.compress(text_bytes, store_size=False).hex()
|
||||
|
||||
data = wcf.query_sql('MSG0.db', "SELECT * FROM MSG where type = 49 limit 1")
|
||||
wcf.query_sql('MSG0.db',
|
||||
f"""UPDATE MSG SET CompressContent = x'{compressed_data}', BytesExtra=x'', type=49, SubType=3,
|
||||
IsSender=0, TalkerId=2 WHERE MsgSvrID={data[0]['MsgSvrID']}"""
|
||||
)
|
||||
|
||||
result = wcf.forward_msg(data[0]["MsgSvrID"], receiver)
|
||||
self.LOG.info(f"插件化:点歌发送结果: {result}")
|
||||
# # 修改消息数据库里面的消息content内容
|
||||
# text_bytes = xml_message.encode('utf-8')
|
||||
# compressed_data = lb.compress(text_bytes, store_size=False).hex()
|
||||
#
|
||||
# data = self.message_util.query_sql('MSG0.db', "SELECT * FROM MSG where type = 49 limit 1")
|
||||
# self.message_util.query_sql('MSG0.db',
|
||||
# f"""UPDATE MSG SET CompressContent = x'{compressed_data}', BytesExtra=x'', type=49, SubType=3,
|
||||
# IsSender=0, TalkerId=2 WHERE MsgSvrID={data[0]['MsgSvrID']}"""
|
||||
# )
|
||||
#
|
||||
# result = self.message_util.forward_msg(data[0]["MsgSvrID"], receiver)
|
||||
# self.LOG.info(f"插件化:点歌发送结果: {result}")
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
|
||||
@@ -94,14 +94,14 @@ class PluginManagerPlugin(MessagePluginInterface):
|
||||
# 检查命令格式
|
||||
parts = content.split(" ")
|
||||
if len(parts) == 1:
|
||||
wcf.send_text(f"❌命令格式错误!\n{self.command_format}", target, sender)
|
||||
self.message_util.send_text(f"❌命令格式错误!\n{self.command_format}", target, sender)
|
||||
return True, "命令格式错误"
|
||||
# 只有使用的时候才全局获取对象。防止在预加载的时候跟主线程冲突
|
||||
self.plugin_registry = PluginRegistry()
|
||||
self.plugin_manager = PluginManager().get_instance()
|
||||
# 检查权限 (只允许管理员操作)
|
||||
if not self._is_admin(sender, gbm):
|
||||
wcf.send_text(f"❌权限不足,只有管理员可以管理插件", target, sender)
|
||||
self.message_util.send_text(f"❌权限不足,只有管理员可以管理插件", target, sender)
|
||||
return True, "权限不足"
|
||||
|
||||
# 解析子命令
|
||||
@@ -125,14 +125,14 @@ class PluginManagerPlugin(MessagePluginInterface):
|
||||
if handler and (sub_command == "列表" or plugin_name):
|
||||
return handler(wcf, sender, roomid)
|
||||
else:
|
||||
wcf.send_text(f"❌未知命令或缺少参数!\n{self.command_format}", target, sender)
|
||||
self.message_util.send_text(f"❌未知命令或缺少参数!\n{self.command_format}", target, sender)
|
||||
return True, "未知命令"
|
||||
|
||||
except Exception as e:
|
||||
import traceback
|
||||
error_trace = traceback.format_exc()
|
||||
self.LOG.error(f"处理插件管理请求出错: {e}\n{error_trace}")
|
||||
wcf.send_text(f"❌操作失败: {str(e)}", target, sender)
|
||||
self.message_util.send_text(f"❌操作失败: {str(e)}", target, sender)
|
||||
return True, f"处理出错: {e}"
|
||||
|
||||
def _is_admin(self, user_id: str, gbm: GroupBotManager) -> bool:
|
||||
@@ -153,7 +153,7 @@ class PluginManagerPlugin(MessagePluginInterface):
|
||||
module_name = plugin.__class__.__module__.split('.')[-2]
|
||||
message += f"{status}-{plugin.name} [模块: {module_name}]\n"
|
||||
|
||||
wcf.send_text(message, target, sender)
|
||||
self.message_util.send_text(message, target, sender)
|
||||
return True, "列出插件成功"
|
||||
|
||||
def _operate_plugin(self, plugin_name: str, wcf, sender: str, roomid: str,
|
||||
@@ -165,12 +165,12 @@ class PluginManagerPlugin(MessagePluginInterface):
|
||||
display_name, plugin = self.plugin_manager.find_plugin_by_name(plugin_name)
|
||||
|
||||
if not display_name:
|
||||
wcf.send_text(f"❌未找到插件 {plugin_name},请检查名称是否正确", target, sender)
|
||||
self.message_util.send_text(f"❌未找到插件 {plugin_name},请检查名称是否正确", target, sender)
|
||||
return True, f"未找到插件 {plugin_name}"
|
||||
|
||||
# 不允许操作自身(对于某些操作)
|
||||
if display_name == self.name and operation_func in [self._unload_plugin, self._disable_plugin]:
|
||||
wcf.send_text(f"⚠️不能对插件管理插件自身执行此操作", target, sender)
|
||||
self.message_util.send_text(f"⚠️不能对插件管理插件自身执行此操作", target, sender)
|
||||
return True, "不能对插件管理插件自身执行此操作"
|
||||
|
||||
# 执行具体操作
|
||||
@@ -182,11 +182,11 @@ class PluginManagerPlugin(MessagePluginInterface):
|
||||
plugin = self.plugin_registry.get_plugin(plugin_name)
|
||||
|
||||
if not plugin:
|
||||
wcf.send_text(f"❌插件 {plugin_name} 不存在", target, sender)
|
||||
self.message_util.send_text(f"❌插件 {plugin_name} 不存在", target, sender)
|
||||
return True, f"插件 {plugin_name} 不存在"
|
||||
|
||||
if plugin.status == PluginStatus.RUNNING:
|
||||
wcf.send_text(f"⚠️插件 {plugin_name} 已经处于启用状态", target, sender)
|
||||
self.message_util.send_text(f"⚠️插件 {plugin_name} 已经处于启用状态", target, sender)
|
||||
return True, f"插件 {plugin_name} 已经处于启用状态"
|
||||
|
||||
# 获取插件的模块名
|
||||
@@ -194,10 +194,10 @@ class PluginManagerPlugin(MessagePluginInterface):
|
||||
|
||||
# 启动插件
|
||||
if self.plugin_manager.start_plugin(module_name):
|
||||
wcf.send_text(f"✅插件 {plugin_name} 启用成功", target, sender)
|
||||
self.message_util.send_text(f"✅插件 {plugin_name} 启用成功", target, sender)
|
||||
return True, f"插件 {plugin_name} 启用成功"
|
||||
else:
|
||||
wcf.send_text(f"❌插件 {plugin_name} 启用失败", target, sender)
|
||||
self.message_util.send_text(f"❌插件 {plugin_name} 启用失败", target, sender)
|
||||
return False, f"插件 {plugin_name} 启用失败"
|
||||
|
||||
def _disable_plugin(self, plugin_name: str, wcf, sender: str, roomid: str) -> Tuple[bool, str]:
|
||||
@@ -206,11 +206,11 @@ class PluginManagerPlugin(MessagePluginInterface):
|
||||
plugin = self.plugin_registry.get_plugin(plugin_name)
|
||||
|
||||
if not plugin:
|
||||
wcf.send_text(f"❌插件 {plugin_name} 不存在", target, sender)
|
||||
self.message_util.send_text(f"❌插件 {plugin_name} 不存在", target, sender)
|
||||
return True, f"插件 {plugin_name} 不存在"
|
||||
|
||||
if plugin.status != PluginStatus.RUNNING:
|
||||
wcf.send_text(f"⚠️插件 {plugin_name} 已经处于禁用状态", target, sender)
|
||||
self.message_util.send_text(f"⚠️插件 {plugin_name} 已经处于禁用状态", target, sender)
|
||||
return True, f"插件 {plugin_name} 已经处于禁用状态"
|
||||
|
||||
# 获取插件的模块名
|
||||
@@ -218,10 +218,10 @@ class PluginManagerPlugin(MessagePluginInterface):
|
||||
|
||||
# 停止插件
|
||||
if self.plugin_manager.stop_plugin(module_name):
|
||||
wcf.send_text(f"✅插件 {plugin_name} 禁用成功", target, sender)
|
||||
self.message_util.send_text(f"✅插件 {plugin_name} 禁用成功", target, sender)
|
||||
return True, f"插件 {plugin_name} 禁用成功"
|
||||
else:
|
||||
wcf.send_text(f"❌插件 {plugin_name} 禁用失败", target, sender)
|
||||
self.message_util.send_text(f"❌插件 {plugin_name} 禁用失败", target, sender)
|
||||
return False, f"插件 {plugin_name} 禁用失败"
|
||||
|
||||
def _reload_plugin(self, plugin_name: str, wcf, sender: str, roomid: str) -> Tuple[bool, str]:
|
||||
@@ -230,7 +230,7 @@ class PluginManagerPlugin(MessagePluginInterface):
|
||||
plugin = self.plugin_registry.get_plugin(plugin_name)
|
||||
|
||||
if not plugin:
|
||||
wcf.send_text(f"❌插件 {plugin_name} 不存在", target, sender)
|
||||
self.message_util.send_text(f"❌插件 {plugin_name} 不存在", target, sender)
|
||||
return True, f"插件 {plugin_name} 不存在"
|
||||
|
||||
# 记录原插件状态
|
||||
@@ -243,10 +243,10 @@ class PluginManagerPlugin(MessagePluginInterface):
|
||||
reloaded_plugin = self.plugin_manager.reload_plugin(module_name)
|
||||
|
||||
if reloaded_plugin:
|
||||
wcf.send_text(f"✅插件 {plugin_name} 重载成功", target, sender)
|
||||
self.message_util.send_text(f"✅插件 {plugin_name} 重载成功", target, sender)
|
||||
return True, f"插件 {plugin_name} 重载成功"
|
||||
else:
|
||||
wcf.send_text(f"❌插件 {plugin_name} 重载失败", target, sender)
|
||||
self.message_util.send_text(f"❌插件 {plugin_name} 重载失败", target, sender)
|
||||
return False, f"插件 {plugin_name} 重载失败"
|
||||
|
||||
def _unload_plugin(self, plugin_name: str, wcf, sender: str, roomid: str) -> Tuple[bool, str]:
|
||||
@@ -255,7 +255,7 @@ class PluginManagerPlugin(MessagePluginInterface):
|
||||
plugin = self.plugin_registry.get_plugin(plugin_name)
|
||||
|
||||
if not plugin:
|
||||
wcf.send_text(f"❌插件 {plugin_name} 不存在", target, sender)
|
||||
self.message_util.send_text(f"❌插件 {plugin_name} 不存在", target, sender)
|
||||
return True, f"插件 {plugin_name} 不存在"
|
||||
|
||||
# 获取插件的模块名
|
||||
@@ -263,10 +263,10 @@ class PluginManagerPlugin(MessagePluginInterface):
|
||||
|
||||
# 卸载插件
|
||||
if self.plugin_manager.unload_plugin(module_name):
|
||||
wcf.send_text(f"✅插件 {plugin_name} 卸载成功", target, sender)
|
||||
self.message_util.send_text(f"✅插件 {plugin_name} 卸载成功", target, sender)
|
||||
return True, f"插件 {plugin_name} 卸载成功"
|
||||
else:
|
||||
wcf.send_text(f"❌插件 {plugin_name} 卸载失败", target, sender)
|
||||
self.message_util.send_text(f"❌插件 {plugin_name} 卸载失败", target, sender)
|
||||
return False, f"插件 {plugin_name} 卸载失败"
|
||||
|
||||
def _load_plugin(self, plugin_name: str, wcf, sender: str, roomid: str, silent: bool = False) -> Tuple[bool, str]:
|
||||
@@ -276,7 +276,7 @@ class PluginManagerPlugin(MessagePluginInterface):
|
||||
plugin_dir = os.path.join("plugins", plugin_name)
|
||||
if not os.path.exists(plugin_dir):
|
||||
if not silent:
|
||||
wcf.send_text(f"❌插件目录 {plugin_dir} 不存在",
|
||||
self.message_util.send_text(f"❌插件目录 {plugin_dir} 不存在",
|
||||
(roomid if roomid else sender), sender)
|
||||
return False, f"插件目录 {plugin_dir} 不存在"
|
||||
|
||||
@@ -285,7 +285,7 @@ class PluginManagerPlugin(MessagePluginInterface):
|
||||
existing_module_name = existing_plugin.__class__.__module__.split('.')[-2]
|
||||
if existing_module_name == plugin_name:
|
||||
if not silent:
|
||||
wcf.send_text(f"⚠️插件 {existing_plugin.name} (模块名: {plugin_name}) 已经加载",
|
||||
self.message_util.send_text(f"⚠️插件 {existing_plugin.name} (模块名: {plugin_name}) 已经加载",
|
||||
(roomid if roomid else sender), sender)
|
||||
return True, f"插件 {existing_plugin.name} 已经加载"
|
||||
|
||||
@@ -294,18 +294,18 @@ class PluginManagerPlugin(MessagePluginInterface):
|
||||
plugin = self.plugin_manager.load_plugin(plugin_name)
|
||||
if plugin:
|
||||
if not silent:
|
||||
wcf.send_text(f"✅插件 {plugin.name} 加载成功",
|
||||
self.message_util.send_text(f"✅插件 {plugin.name} 加载成功",
|
||||
(roomid if roomid else sender), sender)
|
||||
return True, f"插件 {plugin.name} 加载成功"
|
||||
else:
|
||||
if not silent:
|
||||
wcf.send_text(f"❌插件 {plugin_name} 加载失败",
|
||||
self.message_util.send_text(f"❌插件 {plugin_name} 加载失败",
|
||||
(roomid if roomid else sender), sender)
|
||||
return False, f"插件 {plugin_name} 加载失败"
|
||||
except Exception as e:
|
||||
self.LOG.error(f"加载插件 {plugin_name} 出错: {e}")
|
||||
if not silent:
|
||||
wcf.send_text(f"❌加载插件出错: {str(e)}",
|
||||
self.message_util.send_text(f"❌加载插件出错: {str(e)}",
|
||||
(roomid if roomid else sender), sender)
|
||||
return False, f"加载插件出错: {e}"
|
||||
|
||||
@@ -315,13 +315,13 @@ class PluginManagerPlugin(MessagePluginInterface):
|
||||
display_name, plugin = self.plugin_manager.find_plugin_by_name(plugin_name)
|
||||
|
||||
if not display_name:
|
||||
wcf.send_text(f"❌未找到插件 {plugin_name},请检查名称是否正确",
|
||||
self.message_util.send_text(f"❌未找到插件 {plugin_name},请检查名称是否正确",
|
||||
(roomid if roomid else sender), sender)
|
||||
return True, f"未找到插件 {plugin_name}"
|
||||
|
||||
plugin = self.plugin_registry.get_plugin(display_name)
|
||||
if not plugin:
|
||||
wcf.send_text(f"❌插件 {display_name} 不存在",
|
||||
self.message_util.send_text(f"❌插件 {display_name} 不存在",
|
||||
(roomid if roomid else sender), sender)
|
||||
return True, f"插件 {display_name} 不存在"
|
||||
|
||||
@@ -340,5 +340,5 @@ class PluginManagerPlugin(MessagePluginInterface):
|
||||
🔑 命令:{', '.join(plugin.commands) if hasattr(plugin, 'commands') else '无'}
|
||||
"""
|
||||
|
||||
wcf.send_text(message, (roomid if roomid else sender), sender)
|
||||
self.message_util.send_text(message, (roomid if roomid else sender), sender)
|
||||
return True, "查看插件详情成功"
|
||||
|
||||
@@ -4,7 +4,6 @@ from datetime import datetime
|
||||
from typing import Dict, Any, List, Optional, Tuple
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
from wcferry import Wcf
|
||||
|
||||
from db.connection import DBConnectionManager
|
||||
from db.points_db import PointsDBOperator, PointSource
|
||||
@@ -54,7 +53,6 @@ class PointTradePlugin(MessagePluginInterface):
|
||||
self.LOG.info(f"正在初始化 {self.name} 插件...")
|
||||
|
||||
# 保存上下文对象
|
||||
self.wcf = context.get("wcf")
|
||||
self.event_system = context.get("event_system")
|
||||
self.message_util: MessageUtil = context.get("message_util")
|
||||
self.gbm = context.get("gbm")
|
||||
@@ -129,7 +127,6 @@ class PointTradePlugin(MessagePluginInterface):
|
||||
command = content.split(" ")
|
||||
sender = message.get("sender")
|
||||
roomid = message.get("roomid", "")
|
||||
wcf: Wcf = message.get("wcf")
|
||||
gbm: GroupBotManager = message.get("gbm")
|
||||
xml = message.get("xml", "")
|
||||
|
||||
@@ -159,7 +156,6 @@ class PointTradePlugin(MessagePluginInterface):
|
||||
command = content.split(" ")
|
||||
sender = message.get("sender")
|
||||
roomid = message.get("roomid", "")
|
||||
wcf: Wcf = message.get("wcf")
|
||||
xml = message.get("xml", "")
|
||||
|
||||
# 检查命令格式
|
||||
@@ -312,7 +308,6 @@ class PointTradePlugin(MessagePluginInterface):
|
||||
"""处理积分排行榜命令"""
|
||||
sender = message.get("sender")
|
||||
roomid = message.get("roomid", "")
|
||||
wcf: Wcf = message.get("wcf")
|
||||
|
||||
if not roomid:
|
||||
self.message_util.send_text("❌积分排行榜仅在群聊中可用!", sender, "")
|
||||
@@ -452,7 +447,6 @@ class PointTradePlugin(MessagePluginInterface):
|
||||
content = str(message.get("content", "")).strip()
|
||||
sender = message.get("sender")
|
||||
roomid = message.get("roomid", "")
|
||||
wcf: Wcf = message.get("wcf")
|
||||
xml = message.get("xml", "")
|
||||
|
||||
# 检查是否在群聊中
|
||||
@@ -633,7 +627,6 @@ class PointTradePlugin(MessagePluginInterface):
|
||||
"""处理保释命令"""
|
||||
sender = message.get("sender")
|
||||
roomid = message.get("roomid", "")
|
||||
wcf: Wcf = message.get("wcf")
|
||||
xml = message.get("xml", "")
|
||||
|
||||
# 检查是否在群聊中
|
||||
|
||||
@@ -78,7 +78,6 @@ class SystemUpdaterPlugin(MessagePluginInterface):
|
||||
self.LOG.info(f"正在初始化 {self.name} 插件...")
|
||||
|
||||
# 保存上下文对象
|
||||
self.wcf = context.get("wcf")
|
||||
self.message_util = context.get("message_util")
|
||||
self.config = self._config
|
||||
|
||||
@@ -127,12 +126,11 @@ class SystemUpdaterPlugin(MessagePluginInterface):
|
||||
content = str(message.get("content", "")).strip()
|
||||
sender = message.get("sender")
|
||||
roomid = message.get("roomid", "")
|
||||
wcf = message.get("wcf")
|
||||
gbm = message.get("gbm", None)
|
||||
|
||||
# 检查权限
|
||||
if self.admin_wxids and sender not in self.admin_wxids:
|
||||
wcf.send_text("⚠️ 您没有执行此操作的权限",
|
||||
self.message_util.send_text("⚠️ 您没有执行此操作的权限",
|
||||
(roomid if roomid else sender), sender)
|
||||
return True, "无权限"
|
||||
|
||||
@@ -156,12 +154,12 @@ class SystemUpdaterPlugin(MessagePluginInterface):
|
||||
|
||||
# 检查win_click模块是否可用
|
||||
if win_click is None:
|
||||
wcf.send_text("⚠️ 无法执行更新操作,系统缺少必要的组件",
|
||||
self.message_util.send_text("⚠️ 无法执行更新操作,系统缺少必要的组件",
|
||||
(roomid if roomid else sender), sender)
|
||||
return True, "缺少win_click模块"
|
||||
|
||||
# 发送更新通知
|
||||
wcf.send_text(f"🔄 系统即将更新并重启,等待时间设置为{wait_time}秒...",
|
||||
self.message_util.send_text(f"🔄 系统即将更新并重启,等待时间设置为{wait_time}秒...",
|
||||
(roomid if roomid else sender), sender)
|
||||
|
||||
# 启动更新流程
|
||||
|
||||
@@ -3,7 +3,6 @@ import os
|
||||
import requests
|
||||
from typing import Dict, Any, List, Optional, Tuple
|
||||
|
||||
from wcferry import Wcf
|
||||
|
||||
from plugin_common.message_plugin_interface import MessagePluginInterface
|
||||
from plugin_common.plugin_interface import PluginStatus
|
||||
@@ -50,7 +49,6 @@ class VideoPlugin(MessagePluginInterface):
|
||||
self.LOG.info(f"正在初始化 {self.name} 插件...")
|
||||
|
||||
# 保存上下文对象
|
||||
self.wcf = context.get("wcf")
|
||||
self.event_system = context.get("event_system")
|
||||
self.message_util = context.get("message_util")
|
||||
self.gbm = context.get("gbm")
|
||||
@@ -96,7 +94,6 @@ class VideoPlugin(MessagePluginInterface):
|
||||
self.LOG.info(f"插件执行: {self.name}:{content}")
|
||||
sender = message.get("sender")
|
||||
roomid = message.get("roomid", "")
|
||||
wcf: Wcf = message.get("wcf")
|
||||
gbm: GroupBotManager = message.get("gbm")
|
||||
|
||||
# 检查权限
|
||||
@@ -109,18 +106,18 @@ class VideoPlugin(MessagePluginInterface):
|
||||
file_abspath = self._download_stream("https://api.guiguiya.com/api/hook/heisis", save_path)
|
||||
|
||||
if not file_abspath or not file_abspath.endswith("mp4"):
|
||||
wcf.send_text(f"\n❌视频下载失败,请稍后再试",
|
||||
self.message_util.send_text(f"\n❌视频下载失败,请稍后再试",
|
||||
(roomid if roomid else sender), sender)
|
||||
return False, "视频下载失败"
|
||||
|
||||
# 发送视频
|
||||
result = wcf.send_file(file_abspath, (roomid if roomid else sender))
|
||||
result = self.message_util.send_file(file_abspath, (roomid if roomid else sender))
|
||||
self.LOG.info(f"发送视频结果: {result}")
|
||||
return True, "发送成功"
|
||||
|
||||
except Exception as e:
|
||||
self.LOG.error(f"处理视频请求出错: {e}")
|
||||
wcf.send_text(f"\n❌请求出错:{e}",
|
||||
self.message_util.send_text(f"\n❌请求出错:{e}",
|
||||
(roomid if roomid else sender), sender)
|
||||
return False, f"处理出错: {e}"
|
||||
|
||||
|
||||
@@ -3,8 +3,6 @@ import os
|
||||
import requests
|
||||
from typing import Dict, Any, List, Optional, Tuple
|
||||
|
||||
from wcferry import Wcf
|
||||
|
||||
from message_util import MessageUtil
|
||||
from plugin_common.message_plugin_interface import MessagePluginInterface
|
||||
from plugin_common.plugin_interface import PluginStatus
|
||||
@@ -51,7 +49,6 @@ class VideoManPlugin(MessagePluginInterface):
|
||||
self.LOG.info(f"正在初始化 {self.name} 插件...")
|
||||
|
||||
# 保存上下文对象
|
||||
self.wcf = context.get("wcf")
|
||||
self.event_system = context.get("event_system")
|
||||
self.message_util: MessageUtil = context.get("message_util")
|
||||
self.gbm = context.get("gbm")
|
||||
@@ -97,7 +94,6 @@ class VideoManPlugin(MessagePluginInterface):
|
||||
self.LOG.info(f"插件执行: {self.name}:{content}")
|
||||
sender = message.get("sender")
|
||||
roomid = message.get("roomid", "")
|
||||
wcf: Wcf = message.get("wcf")
|
||||
gbm: GroupBotManager = message.get("gbm")
|
||||
|
||||
# 检查权限
|
||||
@@ -114,7 +110,7 @@ class VideoManPlugin(MessagePluginInterface):
|
||||
return False, "视频下载失败"
|
||||
|
||||
# 发送视频
|
||||
result = wcf.send_file(file_abspath, (roomid if roomid else sender))
|
||||
result = self.message_util.send_file(file_abspath, (roomid if roomid else sender))
|
||||
self.LOG.info(f"发送视频结果: {result}")
|
||||
return True, "发送成功"
|
||||
|
||||
|
||||
@@ -3,8 +3,6 @@ import os
|
||||
import random
|
||||
from typing import Dict, Any, List, Optional, Tuple
|
||||
|
||||
from wcferry import Wcf
|
||||
|
||||
from plugin_common.message_plugin_interface import MessagePluginInterface
|
||||
from plugin_common.plugin_interface import PluginStatus
|
||||
from utils.decorator.plugin_decorators import plugin_stats_decorator
|
||||
@@ -49,7 +47,6 @@ class XiurenImagePlugin(MessagePluginInterface):
|
||||
self.LOG.info(f"正在初始化 {self.name} 插件...")
|
||||
|
||||
# 保存上下文对象
|
||||
self.wcf = context.get("wcf")
|
||||
self.event_system = context.get("event_system")
|
||||
self.message_util = context.get("message_util")
|
||||
|
||||
@@ -95,7 +92,6 @@ class XiurenImagePlugin(MessagePluginInterface):
|
||||
self.LOG.info(f"插件执行: {self.name}:{content}")
|
||||
sender = message.get("sender")
|
||||
roomid = message.get("roomid", "")
|
||||
wcf: Wcf = message.get("wcf")
|
||||
gbm: GroupBotManager = message.get("gbm")
|
||||
|
||||
# 检查权限
|
||||
@@ -106,12 +102,12 @@ class XiurenImagePlugin(MessagePluginInterface):
|
||||
# 获取随机图片
|
||||
pic_path = self._get_random_pic()
|
||||
if not pic_path:
|
||||
wcf.send_text(f"❌未找到图片资源",
|
||||
self.message_util.send_text(f"❌未找到图片资源",
|
||||
(roomid if roomid else sender), sender)
|
||||
return False, "未找到图片资源"
|
||||
|
||||
# 发送图片
|
||||
result = wcf.send_file(pic_path, (roomid if roomid else sender))
|
||||
result = self.message_util.send_file(pic_path, (roomid if roomid else sender))
|
||||
self.LOG.info(f"发送图片结果: {result}")
|
||||
return True, "发送成功"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user