优化代码
This commit is contained in:
@@ -11,7 +11,6 @@ from utils.robot_cmd.robot_command import Feature, PermissionStatus, GroupBotMan
|
|||||||
from wechat_ipad import WechatAPIClient
|
from wechat_ipad import WechatAPIClient
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class SystemUpdaterPlugin(MessagePluginInterface):
|
class SystemUpdaterPlugin(MessagePluginInterface):
|
||||||
"""系统更新插件"""
|
"""系统更新插件"""
|
||||||
|
|
||||||
@@ -105,30 +104,48 @@ class SystemUpdaterPlugin(MessagePluginInterface):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
@plugin_stats_decorator(plugin_name="系统更新")
|
@plugin_stats_decorator(plugin_name="系统更新")
|
||||||
@plugin_points_cost(1, "系统更新消耗积分", FEATURE_KEY)
|
|
||||||
async 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()
|
||||||
self.LOG.debug(f"插件执行: {self.name}:{content}")
|
|
||||||
sender = message.get("sender")
|
sender = message.get("sender")
|
||||||
roomid = message.get("roomid", "")
|
roomid = message.get("roomid", "")
|
||||||
gbm: GroupBotManager = message.get("gbm")
|
gbm = message.get("gbm", None)
|
||||||
bot: WechatAPIClient = message.get("bot")
|
|
||||||
|
|
||||||
|
self.bot: WechatAPIClient = message.get("bot")
|
||||||
# 检查权限
|
# 检查权限
|
||||||
if roomid and gbm.get_group_permission(roomid, self.feature) == PermissionStatus.DISABLED:
|
if self.admin_wxids and sender not in self.admin_wxids:
|
||||||
return False, "没有权限"
|
await self.bot.send_text_message((roomid if roomid else sender), "⚠️ 您没有执行此操作的权限",
|
||||||
|
sender)
|
||||||
|
return True, "无权限"
|
||||||
|
|
||||||
# 检查是否是命令
|
# 如果是群消息,检查群权限
|
||||||
if content in self._commands:
|
if roomid and gbm and hasattr(gbm, 'get_group_permission'):
|
||||||
return True, "命令已接收"
|
if gbm.get_group_permission(roomid, Feature.ROBOT) == PermissionStatus.DISABLED:
|
||||||
|
return False, "机器人功能已禁用"
|
||||||
|
|
||||||
# 检查是否是带参数的更新命令
|
# 提取等待时间参数
|
||||||
for cmd in self._commands:
|
wait_time = self.wait_time
|
||||||
if content.startswith(f"{cmd} "):
|
command = content.split(" ")[0]
|
||||||
return True, "带参数的命令已接收"
|
|
||||||
|
if len(content.split(" ")) > 1:
|
||||||
|
try:
|
||||||
|
param = content.split(" ")[1].strip()
|
||||||
|
if param.isdigit():
|
||||||
|
wait_time = int(param)
|
||||||
|
self.LOG.info(f"使用自定义等待时间: {wait_time}秒")
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# 发送更新通知
|
||||||
|
await self.bot.send_text_message((roomid if roomid else sender),
|
||||||
|
f"🔄 系统即将更新并重启,等待时间设置为{wait_time}秒...",
|
||||||
|
sender)
|
||||||
|
|
||||||
|
# 执行系统更新脚本
|
||||||
|
self._execute_system_update()
|
||||||
|
|
||||||
|
return True, "系统更新中"
|
||||||
|
|
||||||
return False, "无法处理的消息"
|
|
||||||
|
|
||||||
def _execute_system_update(self):
|
def _execute_system_update(self):
|
||||||
"""执行系统更新操作"""
|
"""执行系统更新操作"""
|
||||||
|
|||||||
Reference in New Issue
Block a user