feat: 支持命令限权

This commit is contained in:
Rock Chin
2023-03-31 06:49:13 +00:00
parent 73dccb21f5
commit df494da9e4
3 changed files with 20 additions and 1 deletions

1
.gitignore vendored
View File

@@ -17,3 +17,4 @@ scenario/
override.json
cookies.json
res/announcement_saved
cmdpriv.json

View File

@@ -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/")

View File

@@ -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