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