mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-02 03:55:55 +00:00
feat: 支持命令限权
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -17,3 +17,4 @@ scenario/
|
|||||||
override.json
|
override.json
|
||||||
cookies.json
|
cookies.json
|
||||||
res/announcement_saved
|
res/announcement_saved
|
||||||
|
cmdpriv.json
|
||||||
5
main.py
5
main.py
@@ -197,6 +197,7 @@ def start(first_time_init=False):
|
|||||||
try:
|
try:
|
||||||
pkg.openai.dprompt.register_all()
|
pkg.openai.dprompt.register_all()
|
||||||
pkg.qqbot.cmds.mgr.register_all()
|
pkg.qqbot.cmds.mgr.register_all()
|
||||||
|
pkg.qqbot.cmds.mgr.apply_privileges()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(e)
|
logging.error(e)
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
@@ -372,6 +373,10 @@ def check_file():
|
|||||||
if not os.path.exists("scenario/default.json"):
|
if not os.path.exists("scenario/default.json"):
|
||||||
shutil.copy("scenario/default-template.json", "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目录
|
# 检查temp目录
|
||||||
if not os.path.exists("temp/"):
|
if not os.path.exists("temp/"):
|
||||||
os.mkdir("temp/")
|
os.mkdir("temp/")
|
||||||
|
|||||||
@@ -311,3 +311,16 @@ def register_all():
|
|||||||
|
|
||||||
walk(pkg.qqbot.cmds, '', '')
|
walk(pkg.qqbot.cmds, '', '')
|
||||||
logging.debug(__command_list__)
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user