mirror of
https://github.com/Genshin-bots/gsuid_core.git
synced 2025-05-12 06:55:49 +08:00
🐛 修复绑定信息
和扫码登陆
(KimigaiiWuyi/GenshinUID#574)
This commit is contained in:
parent
ff47dafc66
commit
c3b96efe3e
@ -47,7 +47,7 @@ class GsClient:
|
||||
bot_id='Nonebot222',
|
||||
user_type='direct',
|
||||
user_pm=1,
|
||||
group_id='12345678888',
|
||||
group_id=None,
|
||||
user_id='444835641',
|
||||
content=content,
|
||||
)
|
||||
|
@ -66,6 +66,9 @@ async def get_user_card(bot_id: str, user_id: str) -> Union[bytes, str]:
|
||||
if user_data.uid is not None and user_data.uid != '0':
|
||||
uid_text = f'原神UID {user_data.uid}'
|
||||
user_push_data = await sqla.select_push_data(user_data.uid)
|
||||
if user_push_data is None:
|
||||
await sqla.insert_push_data(user_data.uid)
|
||||
user_push_data = await sqla.select_push_data(user_data.uid)
|
||||
else:
|
||||
uid_text = '未发现原神UID'
|
||||
user_push_data = GsPush(bot_id='TEMP')
|
||||
|
@ -43,7 +43,9 @@ async def get_ck_by_all_stoken(bot_id: str):
|
||||
|
||||
async def get_ck_by_stoken(bot_id: str, user_id: str):
|
||||
sqla = get_sqla(bot_id)
|
||||
uid_list: List = await sqla.get_bind_uid_list(user_id)
|
||||
uid_list = await sqla.get_bind_uid_list(user_id)
|
||||
if uid_list is None:
|
||||
return UID_HINT
|
||||
uid_dict = {uid: user_id for uid in uid_list}
|
||||
im = await refresh_ck_by_uid_list(bot_id, uid_dict)
|
||||
return im
|
||||
|
@ -12,10 +12,10 @@ from typing import (
|
||||
)
|
||||
|
||||
from sqlalchemy.future import select
|
||||
from sqlalchemy import delete, update
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from sqlmodel import Field, SQLModel, col
|
||||
from sqlalchemy.sql.expression import func
|
||||
from sqlalchemy import and_, delete, update
|
||||
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
|
||||
|
||||
from gsuid_core.data_store import get_res_path
|
||||
@ -65,20 +65,18 @@ class BaseIDModel(SQLModel):
|
||||
@classmethod
|
||||
@with_session
|
||||
async def base_select_data(
|
||||
cls, session: AsyncSession, model: Type[T_BaseIDModel], **data
|
||||
cls: type[T_BaseIDModel], session: AsyncSession, **data
|
||||
) -> Optional[T_BaseIDModel]:
|
||||
conditions = []
|
||||
for key, value in data.items():
|
||||
conditions.append(getattr(model, key) == value)
|
||||
where_clause = and_(*conditions)
|
||||
sql = select(model).where(where_clause)
|
||||
result = await session.execute(sql)
|
||||
stmt = select(cls)
|
||||
for k, v in data.items():
|
||||
stmt = stmt.where(getattr(cls, k) == v)
|
||||
result = await session.execute(stmt)
|
||||
data = result.scalars().all()
|
||||
return data[0] if data else None
|
||||
|
||||
@classmethod
|
||||
async def data_exist(cls, model: Type[T_BaseIDModel], **data) -> bool:
|
||||
return bool(await cls.base_select_data(model, **data))
|
||||
async def data_exist(cls, **data) -> bool:
|
||||
return bool(await cls.base_select_data(**data))
|
||||
|
||||
|
||||
class BaseBotIDModel(BaseIDModel):
|
||||
@ -102,6 +100,7 @@ class BaseBotIDModel(BaseIDModel):
|
||||
query = sql.values(**data)
|
||||
query.execution_options(synchronize_session='fetch')
|
||||
await session.execute(query)
|
||||
await session.commit()
|
||||
return 0
|
||||
return -1
|
||||
|
||||
|
@ -370,7 +370,7 @@ class SQLA:
|
||||
|
||||
async def update_push_data(self, uid: str, data: dict) -> bool:
|
||||
retcode = -1
|
||||
if await GsPush.data_exist(GsPush, uid=uid):
|
||||
if await GsPush.data_exist(uid=uid):
|
||||
retcode = await GsPush.update_data_by_uid(
|
||||
uid, self.bot_id, 'sr' if self.is_sr else None, **data
|
||||
)
|
||||
@ -385,10 +385,10 @@ class SQLA:
|
||||
await self.update_push_data(uid, {f'{mode}_is_push': status})
|
||||
|
||||
async def select_push_data(self, uid: str) -> Optional[GsPush]:
|
||||
return await GsPush.base_select_data(GsPush, uid=uid)
|
||||
return await GsPush.base_select_data(uid=uid)
|
||||
|
||||
async def push_exists(self, uid: str) -> bool:
|
||||
return await GsPush.data_exist(GsPush, uid=uid)
|
||||
return await GsPush.data_exist(uid=uid)
|
||||
|
||||
#####################
|
||||
# 杂项部分 #
|
||||
|
Loading…
x
Reference in New Issue
Block a user