在QQ内添加权限

This commit is contained in:
San Liy 2023-12-21 01:11:02 +08:00
parent 02b9ffec7b
commit 5a331e773d

39
cmds.py
View File

@ -1,5 +1,6 @@
import secrets
from casbin import AsyncEnforcer
from sanic import SanicException
from models import User, GiteaUser
@ -56,4 +57,42 @@ def cmds(app, data):
if len(sqt.args) == 0:
parser.parse_args(["-h"])
@sio_decorator.cmd('authadd')
async def auth_add(sqt: SioRequest):
parser = sqt.parser
parser.add_argument('-ag', '--addgroup', help='添加用户组',
action="store_true")
parser.add_argument('-g', '--group', help='组名')
parser.add_argument('-m', '--command', help='命令名')
parser.add_argument('-au', '--adduser', help='添加用户到组',
action="store_true")
parser.add_argument('-u', '--user', help='用户QQ号')
args = parser.parse_args(sqt.args)
e: AsyncEnforcer = sqt.app.ctx.e
msg = ''
if args.addgroup:
if args.group and args.command:
if await e.add_policy(args.group, args.command):
msg = Message(content=f'添加成功p, {args.group}, {args.command}', room_id=sqt.room_id)
else:
msg = Message(content='添加失败,用户组已存在或其它错误', room_id=sqt.room_id)
else:
msg = Message(content='缺失参数,请使用-h查看帮助', room_id=sqt.room_id)
if args.adduser:
if args.user and args.group:
if await e.add_role_for_user(args.user, args.group):
msg = Message(content=f'添加成功g, {args.user}, {args.group}', room_id=sqt.room_id)
else:
msg = Message(content='添加失败,用户已在组内或其它错误', room_id=sqt.room_id)
else:
msg = Message(content='缺失参数,请使用-h查看帮助', room_id=sqt.room_id)
if len(sqt.args) == 0:
parser.parse_args(["-h"])
else:
if msg == '':
msg = Message(content='参数错误,请使用-h查看帮助', room_id=sqt.room_id)
await sqt.app.ctx.sio.emit('sendMessage', msg.to_json())
return sio_decorator