绑定的查询优化

This commit is contained in:
San Liy 2023-12-21 00:14:39 +08:00
parent 5edd7cd133
commit 8be8f43ca7
2 changed files with 26 additions and 8 deletions

20
cmds.py
View File

@ -1,6 +1,8 @@
import secrets import secrets
from models import User from sanic import SanicException
from models import User, GiteaUser
from sio_model import SioDecorator, Message, SioRequest from sio_model import SioDecorator, Message, SioRequest
@ -18,6 +20,8 @@ def cmds(app, data):
parser = sqt.parser parser = sqt.parser
parser.add_argument('-vd', '--validate', help='绑定QQ与gitea', parser.add_argument('-vd', '--validate', help='绑定QQ与gitea',
action="store_true") action="store_true")
parser.add_argument('-ust', '--ustatus', help='查询Gitea绑定状态',
action="store_true")
args = parser.parse_args(sqt.args) args = parser.parse_args(sqt.args)
if args.validate: if args.validate:
state = secrets.token_urlsafe(16) state = secrets.token_urlsafe(16)
@ -35,6 +39,20 @@ def cmds(app, data):
f'response_type=code&state={state}') f'response_type=code&state={state}')
msg = Message(content=f'click: \n{url}', room_id=sqt.room_id) msg = Message(content=f'click: \n{url}', room_id=sqt.room_id)
await sqt.app.ctx.sio.emit('sendMessage', msg.to_json()) 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: if len(sqt.args) == 0:
parser.parse_args(["-h"]) parser.parse_args(["-h"])

View File

@ -145,15 +145,15 @@ async def redirect(rqt: Request):
logger.warn(f'该请求不是从QQ中请求的链接') logger.warn(f'该请求不是从QQ中请求的链接')
return text('请从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.ctx.sio.emit('sendMessage', msg.to_json())
await app.add_task(get_gitea_token(app, {'client_id': app.ctx.sio_config.client_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, 'client_secret': app.ctx.sio_config.client_secret,
'code': code, 'code': code,
'grant_type': 'authorization_code', 'grant_type': 'authorization_code',
'redirect_uri': f'{app.ctx.sio_config.localhost}/redirect'}, 'redirect_uri': f'{app.ctx.sio_config.localhost}/redirect'},
q_user), name=str(q_user.id)) q_user), name=str(q_user.id))
return text('success') return text('success')