From df494da9e400b3a9baebb8385e9e4a53076e9438 Mon Sep 17 00:00:00 2001 From: Rock Chin <1010553892@qq.com> Date: Fri, 31 Mar 2023 06:49:13 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E9=99=90=E6=9D=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- main.py | 5 +++++ pkg/qqbot/cmds/mgr.py | 13 +++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index c9b02dcc..e9a9cf30 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,5 @@ scenario/ !scenario/default-template.json override.json cookies.json -res/announcement_saved \ No newline at end of file +res/announcement_saved +cmdpriv.json \ No newline at end of file diff --git a/main.py b/main.py index ac69286e..16d4113d 100644 --- a/main.py +++ b/main.py @@ -197,6 +197,7 @@ def start(first_time_init=False): try: pkg.openai.dprompt.register_all() pkg.qqbot.cmds.mgr.register_all() + pkg.qqbot.cmds.mgr.apply_privileges() except Exception as e: logging.error(e) traceback.print_exc() @@ -372,6 +373,10 @@ def check_file(): if not os.path.exists("scenario/default.json"): shutil.copy("scenario/default-template.json", "scenario/default.json") + # 检查cmdpriv.json + if not os.path.exists("cmdpriv.json"): + shutil.copy("cmdpriv-template.json", "cmdpriv.json") + # 检查temp目录 if not os.path.exists("temp/"): os.mkdir("temp/") diff --git a/pkg/qqbot/cmds/mgr.py b/pkg/qqbot/cmds/mgr.py index 66c9efb6..da45d160 100644 --- a/pkg/qqbot/cmds/mgr.py +++ b/pkg/qqbot/cmds/mgr.py @@ -311,3 +311,16 @@ def register_all(): walk(pkg.qqbot.cmds, '', '') logging.debug(__command_list__) + + +def apply_privileges(): + """读取cmdpriv.json并应用指令权限""" + with open('cmdpriv.json', 'r') as f: + data = json.load(f) + for path, priv in data.items(): + if path == 'comment': + continue + if __command_list__[path]['privilege'] != priv: + logging.debug('应用权限: {} -> {}(default: {})'.format(path, priv, __command_list__[path]['privilege'])) + + __command_list__[path]['privilege'] = priv