diff --git a/cmds.py b/cmds.py index d60132e..ab6a2b8 100644 --- a/cmds.py +++ b/cmds.py @@ -1,6 +1,8 @@ import secrets -from models import User +from sanic import SanicException + +from models import User, GiteaUser from sio_model import SioDecorator, Message, SioRequest @@ -18,6 +20,8 @@ def cmds(app, data): parser = sqt.parser parser.add_argument('-vd', '--validate', help='绑定QQ与gitea', action="store_true") + parser.add_argument('-ust', '--ustatus', help='查询Gitea绑定状态', + action="store_true") args = parser.parse_args(sqt.args) if args.validate: state = secrets.token_urlsafe(16) @@ -35,6 +39,20 @@ def cmds(app, data): f'response_type=code&state={state}') msg = Message(content=f'click: \n{url}', room_id=sqt.room_id) await sqt.app.ctx.sio.emit('sendMessage', msg.to_json()) + + if args.ustatus: + g_user = await GiteaUser.filter(qid_id=sqt.sender_id).get_or_none() + if g_user: + msg = Message(content=f'您的Gitea账号是:{g_user.name}', room_id=sqt.room_id) + else: + try: + task = await sqt.app.get_task(str(sqt.sender_id)) + result = task.result() + msg = Message(content=f'绑定状态:{result}', room_id=sqt.room_id) + except SanicException: + msg = Message(content=f'你还没有绑定呢', room_id=sqt.room_id) + await sqt.app.ctx.sio.emit('sendMessage', msg.to_json()) + if len(sqt.args) == 0: parser.parse_args(["-h"]) diff --git a/server.py b/server.py index f5d81dd..b7504c3 100644 --- a/server.py +++ b/server.py @@ -145,15 +145,15 @@ async def redirect(rqt: Request): logger.warn(f'该请求不是从QQ中请求的链接') return text('请从QQ处申请绑定') - msg = Message(content='已在绑定中,可能因为意外而失败', room_id=q_user.id) + msg = Message(content='已在绑定中,可能因为意外而失败\n查询结果使用\n/gitea -ust', room_id=q_user.id) await app.ctx.sio.emit('sendMessage', msg.to_json()) - await app.add_task(get_gitea_token(app, {'client_id': app.ctx.sio_config.client_id, - 'client_secret': app.ctx.sio_config.client_secret, - 'code': code, - 'grant_type': 'authorization_code', - 'redirect_uri': f'{app.ctx.sio_config.localhost}/redirect'}, - q_user), name=str(q_user.id)) + rqt.app.add_task(get_gitea_token(app, {'client_id': app.ctx.sio_config.client_id, + 'client_secret': app.ctx.sio_config.client_secret, + 'code': code, + 'grant_type': 'authorization_code', + 'redirect_uri': f'{app.ctx.sio_config.localhost}/redirect'}, + q_user), name=str(q_user.id)) return text('success')