fix: align simadmin plugin with working autman scripts
This commit is contained in:
@@ -26,19 +26,19 @@ plugin/scripts/simadmin_multi.py
|
||||
插件头注已设置:
|
||||
|
||||
```text
|
||||
#[admin: true]
|
||||
#[admin: false]
|
||||
#[rule: ^sim帮助$]
|
||||
#[rule: ^sim配置$]
|
||||
#[rule: ^sim管理$]
|
||||
#[rule: ^sim状态(?:\s+\S+)?$]
|
||||
#[rule: ^sim短信\s+\S+\s+\S+\s+[\s\S]+$]
|
||||
#[priority: 900]
|
||||
#[rule: ^sim状态.*$]
|
||||
#[rule: ^sim短信.*$]
|
||||
#[priority: 999]
|
||||
#[platform: qq,qb,wx,wb,tg,tb,fs,we,web,wxmp]
|
||||
```
|
||||
|
||||
即:仅管理员可用。代码内也会再次判断 `sender.isAdmin()`。
|
||||
说明:头注里故意设置 `#[admin: false]`,只让框架负责触发规则;插件代码内仍会调用 `sender.isAdmin()` 做管理员校验,非管理员会回复 `仅管理员可用`。这样可以避免部分实机环境框架层管理员识别失败时直接拦截、导致完全无回应。
|
||||
|
||||
> 实机排查修复:头注采用 Autman 官方常见的 `#[key: value]` 无空格格式,并扩展平台到 `qq,qb,wx,wb,tg,tb,fs,we,web,wxmp`。如果部署到外置微信/内置微信/频道等不同适配器,旧版只写 `qq,wx,tg,tb,fs` 可能导致规则未注册或平台不匹配,从而没有任何交互回应。
|
||||
> 实机排查修复:参考已有可用 Python 插件,头注采用 Autman 常见的 `#[key: value]` 无空格格式,优先级提升到 `999`,并将复杂规则降级为 `^sim状态.*$` / `^sim短信.*$`。复杂正则里的 `(?:...)`、`\S`、`[\s\S]` 在某些规则解析器里可能不兼容,导致插件不触发。平台扩展到 `qq,qb,wx,wb,tg,tb,fs,we,web,wxmp`,避免适配器 imType 不匹配。
|
||||
|
||||
## 配置存储
|
||||
|
||||
|
||||
@@ -2,16 +2,16 @@
|
||||
#[language: python]
|
||||
#[service: BOSS]
|
||||
#[disable: false]
|
||||
#[admin: true]
|
||||
#[admin: false]
|
||||
#[rule: ^sim帮助$]
|
||||
#[rule: ^sim配置$]
|
||||
#[rule: ^sim管理$]
|
||||
#[rule: ^sim状态(?:\s+\S+)?$]
|
||||
#[rule: ^sim短信\s+\S+\s+\S+\s+[\s\S]+$]
|
||||
#[priority: 900]
|
||||
#[rule: ^sim状态.*$]
|
||||
#[rule: ^sim短信.*$]
|
||||
#[priority: 999]
|
||||
#[platform: qq,qb,wx,wb,tg,tb,fs,we,web,wxmp]
|
||||
#[open_source: true]
|
||||
#[version: 1.2.1]
|
||||
#[version: 1.2.2]
|
||||
#[public: false]
|
||||
#[price: 0]
|
||||
#[description: 管理员专用:兼容多个 SimAdmin 实例,支持多级菜单配置管理、状态查询和短信发送。配置桶 otto/simadmin_instances。]
|
||||
@@ -48,12 +48,11 @@ class SimAdminError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def get_sender():
|
||||
return middleware.Sender(middleware.getSenderID())
|
||||
sender = middleware.Sender(middleware.getSenderID())
|
||||
|
||||
|
||||
def reply(sender, text):
|
||||
sender.reply(str(text))
|
||||
def reply(sender_obj, text):
|
||||
sender_obj.reply(str(text))
|
||||
|
||||
|
||||
def listen_text(sender, prompt, allow_empty=False, default=None):
|
||||
@@ -633,23 +632,42 @@ def handle_help(sender):
|
||||
]))
|
||||
|
||||
|
||||
def main():
|
||||
sender = get_sender()
|
||||
def _safe_get_message():
|
||||
try:
|
||||
message = (sender.getMessage() or "").strip().strip('"')
|
||||
if not sender.isAdmin():
|
||||
reply(sender, "仅管理员可用")
|
||||
return
|
||||
return (sender.getMessage() or "").strip().strip('"')
|
||||
except Exception:
|
||||
return ""
|
||||
|
||||
|
||||
def _safe_is_admin():
|
||||
try:
|
||||
return bool(sender.isAdmin())
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
||||
def main():
|
||||
try:
|
||||
message = _safe_get_message()
|
||||
# 参考已有实机插件:头注 admin 只负责触发,敏感权限在代码里判断。
|
||||
# 这样即使框架层 admin 识别异常,也至少会给出“仅管理员可用”,不会表现为无回应。
|
||||
if message in ("sim帮助", "sim配置", "sim管理") or message.startswith("sim状态") or message.startswith("sim短信"):
|
||||
if not _safe_is_admin():
|
||||
reply(sender, "仅管理员可用")
|
||||
return
|
||||
if message == "sim帮助":
|
||||
handle_help(sender)
|
||||
elif message in ("sim配置", "sim管理"):
|
||||
sys.exit(0)
|
||||
if message in ("sim配置", "sim管理"):
|
||||
handle_config(sender)
|
||||
elif message.startswith("sim状态"):
|
||||
sys.exit(0)
|
||||
if message.startswith("sim状态"):
|
||||
handle_status(sender, message)
|
||||
elif message.startswith("sim短信"):
|
||||
sys.exit(0)
|
||||
if message.startswith("sim短信"):
|
||||
handle_sms(sender, message)
|
||||
else:
|
||||
handle_help(sender)
|
||||
sys.exit(0)
|
||||
reply(sender, "指令不支持,请发送:sim帮助 / sim配置 / sim状态 / sim短信")
|
||||
except SimAdminError as e:
|
||||
reply(sender, "SimAdmin插件提示:" + str(e))
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user