🚨修复绑定错误

This commit is contained in:
qwerdvd 2023-08-10 22:55:58 +08:00
parent bc4c1983ec
commit bad6bcdd76
4 changed files with 12 additions and 7 deletions

View File

@ -1,4 +1,3 @@
from gsuid_core.utils.plugins_config.models import (
GSC,
GsStrConfig,

View File

@ -1,7 +1,7 @@
from ..utils.ark_api import ark_skd_api
from ..utils.database.models import ArknightsUser
ERROR_HINT = '添加失败,格式为:用户ID - Cred\n \
ERROR_HINT = '添加失败,格式为:明日方舟UID - Cred\n \
例如:1810461245 - VropL583Sb1hClS5buQ4nSASkDlL8tMT'
@ -11,11 +11,16 @@ async def deal_skd_cred(bot_id: str, cred: str, user_id: str) -> str:
_ck = cred.replace(' ', '').split('-')
if len(_ck) != 2 or not _ck[0] or not _ck[0].isdigit() or not _ck[1]:
return ERROR_HINT
print(_ck)
print(_ck[0], _ck[1])
check_cred = await ark_skd_api.check_cred_valid(_ck[1])
if check_cred:
print(check_cred)
if isinstance(check_cred, bool):
return 'Cred无效!'
else:
skd_uid = check_cred.user.id_
uid, cred = _ck[0], _ck[1]
await ArknightsUser.insert_data(user_id, bot_id,
Cred=cred, uid=uid, skd_uid=check_cred)
cred=cred, uid=uid, skd_uid=skd_uid)
return '添加成功!'

View File

@ -1,6 +1,7 @@
from copy import deepcopy
from typing import Any, Literal
import msgspec
from aiohttp import ClientSession, ContentTypeError, TCPConnector
from gsuid_core.logger import logger
@ -20,7 +21,7 @@ class BaseArkApi:
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36",
}
async def check_cred_valid(self, Cred: str) -> bool | str:
async def check_cred_valid(self, Cred: str) -> bool | ArknightsUserMeModel:
header = deepcopy(self._HEADER)
header['Cred'] = Cred
raw_data = await self._ark_request(ARK_USER_ME, header=header)
@ -28,7 +29,7 @@ class BaseArkApi:
if isinstance(unpack_data, int):
return False
else:
return ArknightsUserMeModel(**unpack_data).user.id_
return msgspec.convert(unpack_data, type=ArknightsUserMeModel)
def unpack(self, raw_data: dict | int) -> dict | int:
if isinstance(raw_data, dict):

View File

@ -78,7 +78,7 @@ class UserMeInfo(Struct):
birthday: str
class ArknightsUserMeModel(Struct):
class ArknightsUserMeModel(Struct, omit_defaults=True):
user: UserMeInfo
userRts: UserMeInfoRts
userSanctionList: list[str]