feat: simplify simadmin restart entry menu
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
#[priority: 999]
|
||||
#[platform: qq,qb,wx,wb,tg,tb,fs,we,web,wxmp]
|
||||
#[open_source: true]
|
||||
#[version: 1.3.0]
|
||||
#[version: 1.3.1]
|
||||
#[public: false]
|
||||
#[price: 0]
|
||||
#[description: 管理员专用:兼容多个 SimAdmin 实例,支持多级菜单配置管理、状态查询和短信发送。配置桶 otto/simadmin_instances。]
|
||||
@@ -28,7 +28,7 @@ Autman Python 插件:SimAdmin 多实例状态查询、短信发送、多级菜
|
||||
- sim状态 主卡 查询指定实例
|
||||
- sim短信 主卡 10086 CXLL
|
||||
- sim短信 all 10086 测试短信
|
||||
- sim重启 <实例名|all> <基带|服务|系统>
|
||||
- sim重启基带 / sim重启服务 / sim重启系统 选择某个实例或全部启用实例
|
||||
"""
|
||||
|
||||
import json
|
||||
@@ -511,22 +511,60 @@ def restart_instances(sender, instances, action_spec):
|
||||
reply(sender, "%s 结果:\n%s" % (action_spec["label"], "\n".join(results)))
|
||||
|
||||
|
||||
def handle_restart(sender, message):
|
||||
m = re.match(r"^sim重启\s+(\S+)\s+(\S+)\s*$", message)
|
||||
if not m:
|
||||
raise SimAdminError("格式错误:sim重启 <实例名|all> <基带|服务|系统>")
|
||||
target, action = m.group(1), m.group(2)
|
||||
action_spec = normalize_restart_action(action)
|
||||
selected = find_instances(load_instances(), target)
|
||||
def choose_restart_targets(sender, action_spec):
|
||||
all_instances = load_instances(include_disabled=True, allow_empty=True)
|
||||
enabled_instances = [x for x in all_instances if x.get("enabled")]
|
||||
if not enabled_instances:
|
||||
raise SimAdminError("没有启用的 SimAdmin 实例")
|
||||
lines = ["%s:请选择设备" % action_spec["label"]]
|
||||
for idx, item in enumerate(all_instances, 1):
|
||||
lines.append(instance_brief(item, idx))
|
||||
lines.extend([
|
||||
"",
|
||||
"a. 全部启用设备",
|
||||
"q. 取消",
|
||||
])
|
||||
choice = listen_text(sender, "\n".join(lines), allow_empty=False).strip()
|
||||
lower = choice.lower()
|
||||
if lower in ("a", "all", "全部", "所有", "*"):
|
||||
return enabled_instances, True
|
||||
if not choice.isdigit():
|
||||
raise SimAdminError("请输入实例编号或 a/全部")
|
||||
idx = int(choice) - 1
|
||||
if idx < 0 or idx >= len(all_instances):
|
||||
raise SimAdminError("编号超出范围")
|
||||
item = all_instances[idx]
|
||||
if not item.get("enabled"):
|
||||
raise SimAdminError("实例【%s】已禁用,请先启用后再操作" % item["name"])
|
||||
return [item], False
|
||||
|
||||
|
||||
def confirm_restart(sender, selected, action_spec, is_all=False):
|
||||
names = "、".join(x["name"] for x in selected)
|
||||
warning = "确认对【%s】执行【%s】?\n" % (names, action_spec["label"])
|
||||
if is_all:
|
||||
warning += "这是批量操作,会影响全部启用设备。"
|
||||
if action_spec["path"].endswith("/system/reboot"):
|
||||
warning += "系统重启会导致设备离线,请确认后再继续。输入 yes 确认"
|
||||
elif target.lower() in ("all", "*", "全部"):
|
||||
warning += "这是批量操作,会影响全部启用设备。输入 yes 确认"
|
||||
warning += "系统重启会导致设备离线。"
|
||||
warning += "输入 yes 确认"
|
||||
return confirm(sender, warning)
|
||||
|
||||
|
||||
def handle_restart(sender, message):
|
||||
text = str(message or "").strip()
|
||||
direct = re.match(r"^sim重启(基带|服务|系统)$", text)
|
||||
legacy = re.match(r"^sim重启\s+(\S+)\s+(\S+)\s*$", text)
|
||||
if direct:
|
||||
action_spec = normalize_restart_action(direct.group(1))
|
||||
selected, is_all = choose_restart_targets(sender, action_spec)
|
||||
elif legacy:
|
||||
target, action = legacy.group(1), legacy.group(2)
|
||||
action_spec = normalize_restart_action(action)
|
||||
selected = find_instances(load_instances(), target)
|
||||
is_all = target.lower() in ("all", "*", "全部")
|
||||
else:
|
||||
warning += "输入 yes 确认"
|
||||
if not confirm(sender, warning):
|
||||
raise SimAdminError("格式错误:请发送 sim重启基带 / sim重启服务 / sim重启系统")
|
||||
if not confirm_restart(sender, selected, action_spec, is_all):
|
||||
reply(sender, "已取消重启操作")
|
||||
return
|
||||
restart_instances(sender, selected, action_spec)
|
||||
@@ -894,7 +932,8 @@ def handle_help(sender):
|
||||
"- sim状态 查询全部启用实例",
|
||||
"- sim状态 <实例名> 查询指定实例",
|
||||
"- sim短信 <实例名|all> <号码> <内容>",
|
||||
"- sim重启 <实例名|all> <基带|服务|系统>",
|
||||
"- sim重启基带 / sim重启服务 / sim重启系统",
|
||||
" 二级菜单选择某个实例或全部启用实例",
|
||||
"菜单支持:查看、添加、编辑、删除、启用/禁用、测试、导出 JSON、单设备重启、一键重启全部启用设备。",
|
||||
]))
|
||||
|
||||
|
||||
+54
-15
@@ -12,7 +12,7 @@
|
||||
#[priority: 999]
|
||||
#[platform: qq,qb,wx,wb,tg,tb,fs,we,web,wxmp]
|
||||
#[open_source: true]
|
||||
#[version: 1.3.0]
|
||||
#[version: 1.3.1]
|
||||
#[public: false]
|
||||
#[price: 0]
|
||||
#[description: 管理员专用:兼容多个 SimAdmin 实例,支持多级菜单配置管理、状态查询和短信发送。配置桶 otto/simadmin_instances。]
|
||||
@@ -28,7 +28,7 @@ Autman Python 插件:SimAdmin 多实例状态查询、短信发送、多级菜
|
||||
- sim状态 主卡 查询指定实例
|
||||
- sim短信 主卡 10086 CXLL
|
||||
- sim短信 all 10086 测试短信
|
||||
- sim重启 <实例名|all> <基带|服务|系统>
|
||||
- sim重启基带 / sim重启服务 / sim重启系统 选择某个实例或全部启用实例
|
||||
"""
|
||||
|
||||
import json
|
||||
@@ -511,22 +511,60 @@ def restart_instances(sender, instances, action_spec):
|
||||
reply(sender, "%s 结果:\n%s" % (action_spec["label"], "\n".join(results)))
|
||||
|
||||
|
||||
def handle_restart(sender, message):
|
||||
m = re.match(r"^sim重启\s+(\S+)\s+(\S+)\s*$", message)
|
||||
if not m:
|
||||
raise SimAdminError("格式错误:sim重启 <实例名|all> <基带|服务|系统>")
|
||||
target, action = m.group(1), m.group(2)
|
||||
action_spec = normalize_restart_action(action)
|
||||
selected = find_instances(load_instances(), target)
|
||||
def choose_restart_targets(sender, action_spec):
|
||||
all_instances = load_instances(include_disabled=True, allow_empty=True)
|
||||
enabled_instances = [x for x in all_instances if x.get("enabled")]
|
||||
if not enabled_instances:
|
||||
raise SimAdminError("没有启用的 SimAdmin 实例")
|
||||
lines = ["%s:请选择设备" % action_spec["label"]]
|
||||
for idx, item in enumerate(all_instances, 1):
|
||||
lines.append(instance_brief(item, idx))
|
||||
lines.extend([
|
||||
"",
|
||||
"a. 全部启用设备",
|
||||
"q. 取消",
|
||||
])
|
||||
choice = listen_text(sender, "\n".join(lines), allow_empty=False).strip()
|
||||
lower = choice.lower()
|
||||
if lower in ("a", "all", "全部", "所有", "*"):
|
||||
return enabled_instances, True
|
||||
if not choice.isdigit():
|
||||
raise SimAdminError("请输入实例编号或 a/全部")
|
||||
idx = int(choice) - 1
|
||||
if idx < 0 or idx >= len(all_instances):
|
||||
raise SimAdminError("编号超出范围")
|
||||
item = all_instances[idx]
|
||||
if not item.get("enabled"):
|
||||
raise SimAdminError("实例【%s】已禁用,请先启用后再操作" % item["name"])
|
||||
return [item], False
|
||||
|
||||
|
||||
def confirm_restart(sender, selected, action_spec, is_all=False):
|
||||
names = "、".join(x["name"] for x in selected)
|
||||
warning = "确认对【%s】执行【%s】?\n" % (names, action_spec["label"])
|
||||
if is_all:
|
||||
warning += "这是批量操作,会影响全部启用设备。"
|
||||
if action_spec["path"].endswith("/system/reboot"):
|
||||
warning += "系统重启会导致设备离线,请确认后再继续。输入 yes 确认"
|
||||
elif target.lower() in ("all", "*", "全部"):
|
||||
warning += "这是批量操作,会影响全部启用设备。输入 yes 确认"
|
||||
warning += "系统重启会导致设备离线。"
|
||||
warning += "输入 yes 确认"
|
||||
return confirm(sender, warning)
|
||||
|
||||
|
||||
def handle_restart(sender, message):
|
||||
text = str(message or "").strip()
|
||||
direct = re.match(r"^sim重启(基带|服务|系统)$", text)
|
||||
legacy = re.match(r"^sim重启\s+(\S+)\s+(\S+)\s*$", text)
|
||||
if direct:
|
||||
action_spec = normalize_restart_action(direct.group(1))
|
||||
selected, is_all = choose_restart_targets(sender, action_spec)
|
||||
elif legacy:
|
||||
target, action = legacy.group(1), legacy.group(2)
|
||||
action_spec = normalize_restart_action(action)
|
||||
selected = find_instances(load_instances(), target)
|
||||
is_all = target.lower() in ("all", "*", "全部")
|
||||
else:
|
||||
warning += "输入 yes 确认"
|
||||
if not confirm(sender, warning):
|
||||
raise SimAdminError("格式错误:请发送 sim重启基带 / sim重启服务 / sim重启系统")
|
||||
if not confirm_restart(sender, selected, action_spec, is_all):
|
||||
reply(sender, "已取消重启操作")
|
||||
return
|
||||
restart_instances(sender, selected, action_spec)
|
||||
@@ -894,7 +932,8 @@ def handle_help(sender):
|
||||
"- sim状态 查询全部启用实例",
|
||||
"- sim状态 <实例名> 查询指定实例",
|
||||
"- sim短信 <实例名|all> <号码> <内容>",
|
||||
"- sim重启 <实例名|all> <基带|服务|系统>",
|
||||
"- sim重启基带 / sim重启服务 / sim重启系统",
|
||||
" 二级菜单选择某个实例或全部启用实例",
|
||||
"菜单支持:查看、添加、编辑、删除、启用/禁用、测试、导出 JSON、单设备重启、一键重启全部启用设备。",
|
||||
]))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user