From 0c29753b687b62c02d8995c1debebb30a5ff60d9 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Fri, 22 Dec 2023 00:17:10 +0800 Subject: [PATCH] Fix command handling and error messages --- cmds.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/cmds.py b/cmds.py index 23e4a40..a2d184b 100644 --- a/cmds.py +++ b/cmds.py @@ -70,30 +70,31 @@ def cmds(app, data): action="store_true") args = parser.parse_args(sqt.args) + reply = ReplyMessage(id=sqt.message_id) 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) + msg = Message(content=f'添加成功:p, {args.group}, {args.command}', room_id=sqt.room_id, reply_to=reply) else: - msg = Message(content='添加失败,用户组已存在或其它错误', room_id=sqt.room_id) + msg = Message(content='添加失败,用户组已存在或其它错误', room_id=sqt.room_id, reply_to=reply) else: - msg = Message(content='缺失参数,请使用-h查看帮助', room_id=sqt.room_id) + msg = Message(content='缺失参数,请使用-h查看帮助', room_id=sqt.room_id, reply_to=reply) if args.adduser: if args.group: if await e.add_role_for_user(str(args.user or sqt.room_id), args.group): - msg = Message(content=f'添加成功:g, {args.user or sqt.room_id}, {args.group}', room_id=sqt.room_id) + msg = Message(content=f'添加成功:g, {args.user or sqt.room_id}, {args.group}', room_id=sqt.room_id, reply_to=reply) else: - msg = Message(content='添加失败,用户已在组内或其它错误', room_id=sqt.room_id) + msg = Message(content='添加失败,用户已在组内或其它错误', room_id=sqt.room_id, reply_to=reply) else: - msg = Message(content='缺失参数,请使用-h查看帮助', room_id=sqt.room_id) + msg = Message(content='缺失参数,请使用-h查看帮助', room_id=sqt.room_id, reply_to=reply) if len(sqt.args) == 0: parser.parse_args(["-h"]) else: if msg == '': - msg = Message(content='参数错误,请使用-h查看帮助', room_id=sqt.room_id) + msg = Message(content='参数错误,请使用-h查看帮助', room_id=sqt.room_id, reply_to=reply) await sqt.app.ctx.sio.emit('sendMessage', msg.to_json()) await e.save_policy() @@ -113,25 +114,25 @@ def cmds(app, data): if args.rmgroup: if args.group and args.command: if await e.remove_policy(args.group, args.command): - msg = Message(content=f'移除成功:p, {args.group}, {args.command}', room_id=sqt.room_id) + msg = Message(content=f'移除成功:p, {args.group}, {args.command}', room_id=sqt.room_id, reply_to=reply) else: - msg = Message(content='移除失败,用户组已存在或其它错误', room_id=sqt.room_id) + msg = Message(content='移除失败,用户组已存在或其它错误', room_id=sqt.room_id, reply_to=reply) else: - msg = Message(content='缺失参数,请使用-h查看帮助', room_id=sqt.room_id) + msg = Message(content='缺失参数,请使用-h查看帮助', room_id=sqt.room_id, reply_to=reply) if args.rmuser: if args.group: if await e.delete_role_for_user(str(args.user or sqt.room_id), args.group): - msg = Message(content=f'移除成功:g, {args.user or sqt.room_id}, {args.group}', room_id=sqt.room_id) + msg = Message(content=f'移除成功:g, {args.user or sqt.room_id}, {args.group}', room_id=sqt.room_id, reply_to=reply) else: - msg = Message(content='移除失败,用户已在组内或其它错误', room_id=sqt.room_id) + msg = Message(content='移除失败,用户已在组内或其它错误', room_id=sqt.room_id, reply_to=reply) else: - msg = Message(content='缺失参数,请使用-h查看帮助', room_id=sqt.room_id) + msg = Message(content='缺失参数,请使用-h查看帮助', room_id=sqt.room_id, reply_to=reply) if len(sqt.args) == 0: parser.parse_args(["-h"]) else: if msg == '': - msg = Message(content='参数错误,请使用-h查看帮助', room_id=sqt.room_id) + msg = Message(content='参数错误,请使用-h查看帮助', room_id=sqt.room_id, reply_to=reply) await sqt.app.ctx.sio.emit('sendMessage', msg.to_json()) await e.save_policy()