系统更新指令
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import subprocess
|
||||
from loguru import logger
|
||||
from typing import Dict, Any, List, Optional, Tuple
|
||||
|
||||
from plugin_common.message_plugin_interface import MessagePluginInterface
|
||||
from plugin_common.plugin_interface import PluginStatus
|
||||
from utils.robot_cmd.robot_command import Feature, PermissionStatus
|
||||
|
||||
from wechat_ipad import WechatAPIClient
|
||||
|
||||
|
||||
class SystemUpdaterPlugin(MessagePluginInterface):
|
||||
@@ -39,6 +40,7 @@ class SystemUpdaterPlugin(MessagePluginInterface):
|
||||
super().__init__()
|
||||
self.admin_wxids = []
|
||||
self.wait_time = 15 # 默认等待15秒
|
||||
self.bot: WechatAPIClient = None
|
||||
|
||||
def initialize(self, context: Dict[str, Any]) -> bool:
|
||||
"""初始化插件"""
|
||||
@@ -56,7 +58,6 @@ class SystemUpdaterPlugin(MessagePluginInterface):
|
||||
self.admin_wxids = plugin_config.get("admin_wxids", [])
|
||||
self.enable = plugin_config.get("enable", True)
|
||||
|
||||
|
||||
self.LOG.info(f"[{self.name}] 插件初始化完成,指令:{self._commands}")
|
||||
return True
|
||||
|
||||
@@ -86,17 +87,18 @@ class SystemUpdaterPlugin(MessagePluginInterface):
|
||||
|
||||
return False
|
||||
|
||||
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()
|
||||
sender = message.get("sender")
|
||||
roomid = message.get("roomid", "")
|
||||
gbm = message.get("gbm", None)
|
||||
|
||||
self.bot: WechatAPIClient = message.get("bot")
|
||||
# 检查权限
|
||||
if self.admin_wxids and sender not in self.admin_wxids:
|
||||
self.message_util.send_text("⚠️ 您没有执行此操作的权限",
|
||||
(roomid if roomid else sender), sender)
|
||||
await self.bot.send_text_message((roomid if roomid else sender), "⚠️ 您没有执行此操作的权限",
|
||||
sender)
|
||||
return True, "无权限"
|
||||
|
||||
# 如果是群消息,检查群权限
|
||||
@@ -118,12 +120,31 @@ class SystemUpdaterPlugin(MessagePluginInterface):
|
||||
pass
|
||||
|
||||
# 发送更新通知
|
||||
self.message_util.send_text(f"🔄 系统即将更新并重启,等待时间设置为{wait_time}秒...",
|
||||
(roomid if roomid else sender), sender)
|
||||
await self.bot.send_text_message((roomid if roomid else sender),
|
||||
f"🔄 系统即将更新并重启,等待时间设置为{wait_time}秒...",
|
||||
sender)
|
||||
|
||||
# 执行系统更新脚本
|
||||
self._execute_system_update()
|
||||
|
||||
return True, "系统更新中"
|
||||
|
||||
def _execute_system_update(self):
|
||||
"""执行系统更新操作"""
|
||||
try:
|
||||
# 调用 restart.sh 脚本进行系统更新
|
||||
result = subprocess.run(
|
||||
["/home/liuwei/wechatbot/WeChatRobot/restart.sh"], # 指定脚本的实际路径
|
||||
check=True,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
)
|
||||
logger.info(f"更新命令执行成功: {result.stdout.decode()}")
|
||||
except subprocess.CalledProcessError as e:
|
||||
logger.error(f"执行更新命令时出错: {e.stderr.decode()}")
|
||||
except Exception as e:
|
||||
logger.error(f"系统更新失败: {str(e)}")
|
||||
|
||||
|
||||
# 插件入口点
|
||||
def get_plugin():
|
||||
|
||||
Reference in New Issue
Block a user