调整管理员信息

This commit is contained in:
liuwei
2026-01-19 14:11:29 +08:00
parent 316b35cb93
commit 9ca6123891
3 changed files with 10 additions and 7 deletions

View File

@@ -203,7 +203,7 @@ class RobotMenuPlugin(MessagePluginInterface):
# 格式:菜单 启用 功能名 或 菜单 关闭 功能名 # 格式:菜单 启用 功能名 或 菜单 关闭 功能名
if len(parts) >= 3 and parts[1] in ["启用", "关闭"]: if len(parts) >= 3 and parts[1] in ["启用", "关闭"]:
# 检查管理员权限 # 检查管理员权限
if not self._is_admin(sender, gbm): if not self._is_admin(sender):
await bot.send_at_message(target, "❌权限不足,只有管理员可以管理功能", [sender]) await bot.send_at_message(target, "❌权限不足,只有管理员可以管理功能", [sender])
return True, "权限不足" return True, "权限不足"
@@ -253,7 +253,7 @@ class RobotMenuPlugin(MessagePluginInterface):
self.LOG.error(traceback.format_exc()) self.LOG.error(traceback.format_exc())
return False, f"处理出错: {e}" return False, f"处理出错: {e}"
def _is_admin(self, user_id: str, gbm: GroupBotManager) -> bool: def _is_admin(self, user_id: str) -> bool:
"""检查用户是否为管理员""" """检查用户是否为管理员"""
# admin_list 现在是 GroupBotManager 的类属性,可以直接访问 # admin_list 现在是 GroupBotManager 的类属性,可以直接访问
admin_list = GroupBotManager.get_admin_list() admin_list = GroupBotManager.get_admin_list()

View File

@@ -3,5 +3,4 @@ enable = true
commands = ["更新系统", "系统更新", "重启系统", "更新重启"] commands = ["更新系统", "系统更新", "重启系统", "更新重启"]
wait_time = 5 wait_time = 5
# 设置管理员微信ID只有这些ID可以执行更新操作 # 设置管理员微信ID只有这些ID可以执行更新操作
admin_wxids = ["Jyunere"] # 在此添加管理员微信ID例如 ["wxid_123456", "wxid_abcdef"]
shell_path= "/home/liuwei/abot/restart.sh" shell_path= "/home/liuwei/abot/restart.sh"

View File

@@ -71,7 +71,6 @@ class SystemUpdaterPlugin(MessagePluginInterface):
self._commands = plugin_config.get("commands", ["更新系统", "系统更新"]) self._commands = plugin_config.get("commands", ["更新系统", "系统更新"])
self._shell_path = plugin_config.get("shell_path", "") self._shell_path = plugin_config.get("shell_path", "")
self.wait_time = plugin_config.get("wait_time", 5) self.wait_time = plugin_config.get("wait_time", 5)
self.admin_wxids = plugin_config.get("admin_wxids", [])
self.enable = plugin_config.get("enable", True) self.enable = plugin_config.get("enable", True)
self.LOG.debug(f"[{self.name}] 插件初始化完成,指令:{self._commands}") self.LOG.debug(f"[{self.name}] 插件初始化完成,指令:{self._commands}")
@@ -109,11 +108,11 @@ class SystemUpdaterPlugin(MessagePluginInterface):
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: GroupBotManager = message.get("gbm")
self.bot: WechatAPIClient = message.get("bot") self.bot: WechatAPIClient = message.get("bot")
# 检查权限 # 检查权限
if self.admin_wxids and sender not in self.admin_wxids: if not self._is_admin(sender):
await self.bot.send_text_message((roomid if roomid else sender), "⚠️ 您没有执行此操作的权限", await self.bot.send_text_message((roomid if roomid else sender), "⚠️ 您没有执行此操作的权限",
sender) sender)
return True, "无权限" return True, "无权限"
@@ -146,7 +145,6 @@ class SystemUpdaterPlugin(MessagePluginInterface):
return True, "系统更新中" return True, "系统更新中"
def _execute_system_update(self): def _execute_system_update(self):
"""执行系统更新操作""" """执行系统更新操作"""
try: try:
@@ -168,6 +166,12 @@ class SystemUpdaterPlugin(MessagePluginInterface):
# 捕获其他异常 # 捕获其他异常
logger.error(f"系统更新失败: {str(e)}") logger.error(f"系统更新失败: {str(e)}")
def _is_admin(self, user_id: str) -> bool:
"""检查用户是否为管理员"""
# admin_list 现在是 GroupBotManager 的类属性,可以直接访问
admin_list = GroupBotManager.get_admin_list()
return user_id in admin_list
# 插件入口点 # 插件入口点
def get_plugin(): def get_plugin():