oclaw/runtime/operations/scripts/set_wecom_auto_bind.py
oliver 4a23b715a2 重构仓库目录为统一的 runtime 分层并清理历史 openclaw 残留。
本次迁移将网关/通道/工具/技能/脚本与协议资源集中到新结构,统一路径常量与脚本转发机制,减少顶层噪音并保证运行与测试行为一致。

Made-with: Cursor
2026-04-25 01:24:23 +08:00

55 lines
1.7 KiB
Python

from __future__ import annotations
import sys
from oclaw.platform.config.paths import db_path
from oclaw.platform.persistence.sqlite_store import SqliteStore
def _to_bool(v: str) -> str:
return "1" if str(v).strip().lower() in ("1", "true", "yes", "on") else "0"
def main() -> int:
args = [str(x).strip() for x in sys.argv[1:]]
if not args:
print("usage:")
print(" python -m scripts.set_wecom_auto_bind on|off")
print(" python -m scripts.set_wecom_auto_bind on <tenant_name> <role>")
print(" python -m scripts.set_wecom_auto_bind show")
return 2
cmd = args[0].lower()
store = SqliteStore(db_path())
if cmd == "show":
enabled = str(store.get_setting("wecom_auto_bind_enabled") or "1").strip()
tenant_name = str(store.get_setting("wecom_auto_bind_tenant_name") or "Team").strip() or "Team"
role = str(store.get_setting("wecom_auto_bind_role") or "member").strip() or "member"
print("ok=1")
print(f"enabled={enabled}")
print(f"tenant_name={tenant_name}")
print(f"role={role}")
return 0
if cmd not in ("on", "off"):
print("error=invalid_command")
return 2
enabled = _to_bool("1" if cmd == "on" else "0")
tenant_name = (args[1] if len(args) >= 2 else "Team").strip() or "Team"
role = (args[2] if len(args) >= 3 else "member").strip() or "member"
store.set_setting("wecom_auto_bind_enabled", enabled)
store.set_setting("wecom_auto_bind_tenant_name", tenant_name)
store.set_setting("wecom_auto_bind_role", role)
print("ok=1")
print(f"enabled={enabled}")
print(f"tenant_name={tenant_name}")
print(f"role={role}")
return 0
if __name__ == "__main__":
raise SystemExit(main())