mirror of
https://github.com/KimigaiiWuyi/GenshinUID.git
synced 2025-05-07 04:03:45 +08:00
🐛 修复一些BUG
This commit is contained in:
parent
d6127d76f3
commit
52ad9bc67a
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
@ -23,4 +23,7 @@
|
||||
"python.linting.flake8CategorySeverity.W": "Warning",
|
||||
"python.linting.flake8CategorySeverity.F": "Warning",
|
||||
"python.linting.flake8CategorySeverity.E": "Warning",
|
||||
}
|
||||
"python.analysis.extraPaths": [
|
||||
"${workspaceFolder}/../../../../"
|
||||
]
|
||||
}
|
@ -306,9 +306,9 @@ async def talent_wiki(name: str, level: int) -> Union[List[Message], str]:
|
||||
im = '该角色不存在。'
|
||||
else:
|
||||
if int(level) <= 3:
|
||||
if level == '1':
|
||||
if level == 1:
|
||||
data = data['combat1']
|
||||
elif level == '2':
|
||||
elif level == 2:
|
||||
data = data['combat2']
|
||||
else:
|
||||
data = data['combat3']
|
||||
@ -380,11 +380,11 @@ async def talent_wiki(name: str, level: int) -> Union[List[Message], str]:
|
||||
mes_list.append(MessageSegment.text(f'lv.{index + 1}\n{mes}'))
|
||||
im = mes_list
|
||||
else:
|
||||
if level == '4':
|
||||
if level == 4:
|
||||
data = data['passive1']
|
||||
elif level == '5':
|
||||
elif level == 5:
|
||||
data = data['passive2']
|
||||
elif level == '6':
|
||||
elif level == 6:
|
||||
data = data['passive3']
|
||||
else:
|
||||
if 'passive4' in data:
|
||||
|
@ -18,12 +18,17 @@ class SQLA:
|
||||
self.bot_id = bot_id
|
||||
self.url = f'sqlite+aiosqlite:///{url}'
|
||||
self.engine = create_async_engine(self.url, pool_recycle=1500)
|
||||
self.session = sessionmaker(
|
||||
self.async_session = sessionmaker(
|
||||
self.engine, expire_on_commit=False, class_=AsyncSession
|
||||
)()
|
||||
)
|
||||
|
||||
def create_all(self):
|
||||
asyncio.create_task(self._create_all())
|
||||
try:
|
||||
asyncio.create_task(self._create_all())
|
||||
except RuntimeError:
|
||||
loop = asyncio.get_event_loop()
|
||||
loop.run_until_complete(self._create_all())
|
||||
loop.close()
|
||||
|
||||
async def _create_all(self):
|
||||
async with self.engine.begin() as conn:
|
||||
@ -33,67 +38,80 @@ class SQLA:
|
||||
# GsBind 部分 #
|
||||
#####################
|
||||
async def select_bind_data(self, user_id: str) -> Optional[GsBind]:
|
||||
result = await self.session.execute(
|
||||
select(GsBind).where(
|
||||
GsBind.user_id == user_id and GsBind.bot_id == self.bot_id
|
||||
)
|
||||
)
|
||||
data = result.scalars().all()
|
||||
return data[0] if data else None
|
||||
async with self.async_session() as session:
|
||||
async with session.begin():
|
||||
result = await session.execute(
|
||||
select(GsBind).where(
|
||||
GsBind.user_id == user_id
|
||||
and GsBind.bot_id == self.bot_id
|
||||
)
|
||||
)
|
||||
data = result.scalars().all()
|
||||
return data[0] if data else None
|
||||
|
||||
async def insert_bind_data(self, user_id: str, **data) -> int:
|
||||
new_uid = data['uid'] if 'uid' in data else ''
|
||||
if len(new_uid) != 9:
|
||||
return -1
|
||||
if await self.bind_exists(user_id):
|
||||
uid_list = await self.get_bind_uid_list(user_id)
|
||||
if uid_list and new_uid not in uid_list:
|
||||
uid_list.append(new_uid)
|
||||
else:
|
||||
return -2
|
||||
data['uid'] = '_'.join(uid_list)
|
||||
await self.update_bind_data(user_id, data)
|
||||
else:
|
||||
new_data = GsBind(user_id=user_id, bot_id=self.bot_id, **data)
|
||||
self.session.add(new_data)
|
||||
await self.session.commit()
|
||||
return 0
|
||||
async with self.async_session() as session:
|
||||
async with session.begin():
|
||||
new_uid = data['uid'] if 'uid' in data else ''
|
||||
if len(new_uid) != 9:
|
||||
return -1
|
||||
if await self.bind_exists(user_id):
|
||||
uid_list = await self.get_bind_uid_list(user_id)
|
||||
if uid_list and new_uid not in uid_list:
|
||||
uid_list.append(new_uid)
|
||||
else:
|
||||
return -2
|
||||
data['uid'] = '_'.join(uid_list)
|
||||
await self.update_bind_data(user_id, data)
|
||||
else:
|
||||
new_data = GsBind(
|
||||
user_id=user_id, bot_id=self.bot_id, **data
|
||||
)
|
||||
session.add(new_data)
|
||||
await session.commit()
|
||||
return 0
|
||||
|
||||
async def delete_bind_data(self, user_id: str, **data) -> int:
|
||||
_uid = data['uid'] if 'uid' in data else ''
|
||||
if await self.bind_exists(user_id):
|
||||
uid_list = await self.get_bind_uid_list(user_id)
|
||||
if uid_list and _uid in uid_list:
|
||||
uid_list.remove(_uid)
|
||||
else:
|
||||
return -1
|
||||
data['uid'] = '_'.join(uid_list)
|
||||
await self.update_bind_data(user_id, data)
|
||||
await self.session.commit()
|
||||
return 0
|
||||
else:
|
||||
return -1
|
||||
async with self.async_session() as session:
|
||||
async with session.begin():
|
||||
_uid = data['uid'] if 'uid' in data else ''
|
||||
if await self.bind_exists(user_id):
|
||||
uid_list = await self.get_bind_uid_list(user_id)
|
||||
if uid_list and _uid in uid_list:
|
||||
uid_list.remove(_uid)
|
||||
else:
|
||||
return -1
|
||||
data['uid'] = '_'.join(uid_list)
|
||||
await self.update_bind_data(user_id, data)
|
||||
await session.commit()
|
||||
return 0
|
||||
else:
|
||||
return -1
|
||||
|
||||
async def update_bind_data(self, user_id: str, data: Optional[Dict]):
|
||||
sql = update(GsBind).where(
|
||||
GsBind.user_id == user_id and GsBind.bot_id == self.bot_id
|
||||
)
|
||||
if data is not None:
|
||||
query = sql.values(**data)
|
||||
query.execution_options(synchronize_session='fetch')
|
||||
await self.session.execute(query)
|
||||
async with self.async_session() as session:
|
||||
async with session.begin():
|
||||
sql = update(GsBind).where(
|
||||
GsBind.user_id == user_id and GsBind.bot_id == self.bot_id
|
||||
)
|
||||
if data is not None:
|
||||
query = sql.values(**data)
|
||||
query.execution_options(synchronize_session='fetch')
|
||||
await session.execute(query)
|
||||
|
||||
async def bind_exists(self, user_id: str) -> bool:
|
||||
return bool(await self.select_bind_data(user_id))
|
||||
|
||||
async def get_all_uid_list(self) -> List[str]:
|
||||
sql = select(GsBind).where(GsBind.bot_id == self.bot_id)
|
||||
result = await self.session.execute(sql)
|
||||
data: List[GsBind] = result.scalars().all()
|
||||
uid_list: List[str] = []
|
||||
for item in data:
|
||||
uid_list.extend(item.uid.split("_") if item.uid else [])
|
||||
return uid_list
|
||||
async with self.async_session() as session:
|
||||
async with session.begin():
|
||||
sql = select(GsBind).where(GsBind.bot_id == self.bot_id)
|
||||
result = await session.execute(sql)
|
||||
data: List[GsBind] = result.scalars().all()
|
||||
uid_list: List[str] = []
|
||||
for item in data:
|
||||
uid_list.extend(item.uid.split("_") if item.uid else [])
|
||||
return uid_list
|
||||
|
||||
async def get_bind_uid_list(self, user_id: str) -> List[str]:
|
||||
data = await self.select_bind_data(user_id)
|
||||
@ -126,22 +144,28 @@ class SQLA:
|
||||
#####################
|
||||
|
||||
async def select_user_data(self, uid: str) -> Optional[GsUser]:
|
||||
sql = select(GsUser).where(GsUser.uid == uid)
|
||||
result = await self.session.execute(sql)
|
||||
return data[0] if (data := result.scalars().all()) else None
|
||||
async with self.async_session() as session:
|
||||
async with session.begin():
|
||||
sql = select(GsUser).where(GsUser.uid == uid)
|
||||
result = await session.execute(sql)
|
||||
return data[0] if (data := result.scalars().all()) else None
|
||||
|
||||
async def select_cache_cookie(self, uid: str) -> Optional[str]:
|
||||
sql = select(GsCache).where(GsCache.uid == uid)
|
||||
result = await self.session.execute(sql)
|
||||
data: List[GsCache] = result.scalars().all()
|
||||
return data[0].cookie if len(data) >= 1 else None
|
||||
async with self.async_session() as session:
|
||||
async with session.begin():
|
||||
sql = select(GsCache).where(GsCache.uid == uid)
|
||||
result = await session.execute(sql)
|
||||
data: List[GsCache] = result.scalars().all()
|
||||
return data[0].cookie if len(data) >= 1 else None
|
||||
|
||||
async def delete_error_cache(self) -> bool:
|
||||
data = await self.get_all_error_cookie()
|
||||
for cookie in data:
|
||||
sql = delete(GsCache).where(GsCache.cookie == cookie)
|
||||
await self.session.execute(sql)
|
||||
return True
|
||||
async with self.async_session() as session:
|
||||
async with session.begin():
|
||||
data = await self.get_all_error_cookie()
|
||||
for cookie in data:
|
||||
sql = delete(GsCache).where(GsCache.cookie == cookie)
|
||||
await session.execute(sql)
|
||||
return True
|
||||
|
||||
async def insert_cache_data(
|
||||
self,
|
||||
@ -149,75 +173,91 @@ class SQLA:
|
||||
uid: Optional[str] = None,
|
||||
mys_id: Optional[str] = None,
|
||||
) -> bool:
|
||||
new_data = GsCache(cookie=cookie, uid=uid, mys_id=mys_id)
|
||||
self.session.add(new_data)
|
||||
await self.session.commit()
|
||||
return True
|
||||
async with self.async_session() as session:
|
||||
async with session.begin():
|
||||
new_data = GsCache(cookie=cookie, uid=uid, mys_id=mys_id)
|
||||
session.add(new_data)
|
||||
await session.commit()
|
||||
return True
|
||||
|
||||
async def insert_user_data(
|
||||
self, user_id: str, uid: str, cookie: str, stoken: Optional[str] = None
|
||||
) -> bool:
|
||||
if await self.user_exists(uid):
|
||||
sql = (
|
||||
update(GsUser)
|
||||
.where(GsUser.uid == uid)
|
||||
.values(cookie=cookie, status=None, stoken=stoken)
|
||||
)
|
||||
await self.session.execute(sql)
|
||||
else:
|
||||
account_id = re.search(r'account_id=(\d*)', cookie)
|
||||
assert account_id is not None
|
||||
account_id = str(account_id.group(1))
|
||||
async with self.async_session() as session:
|
||||
async with session.begin():
|
||||
if await self.user_exists(uid):
|
||||
sql = (
|
||||
update(GsUser)
|
||||
.where(GsUser.uid == uid)
|
||||
.values(cookie=cookie, status=None, stoken=stoken)
|
||||
)
|
||||
await session.execute(sql)
|
||||
else:
|
||||
account_id = re.search(r'account_id=(\d*)', cookie)
|
||||
assert account_id is not None
|
||||
account_id = str(account_id.group(1))
|
||||
|
||||
user_data = GsUser(
|
||||
uid=uid,
|
||||
mys_id=account_id,
|
||||
cookie=cookie,
|
||||
stoken=stoken if stoken else None,
|
||||
user_id=user_id,
|
||||
bot_id=self.bot_id,
|
||||
sign_switch='off',
|
||||
push_switch='off',
|
||||
bbs_switch='off',
|
||||
region=SERVER.get(uid[0], 'cn_gf01'),
|
||||
)
|
||||
self.session.add(user_data)
|
||||
await self.session.commit()
|
||||
return True
|
||||
user_data = GsUser(
|
||||
uid=uid,
|
||||
mys_id=account_id,
|
||||
cookie=cookie,
|
||||
stoken=stoken if stoken else None,
|
||||
user_id=user_id,
|
||||
bot_id=self.bot_id,
|
||||
sign_switch='off',
|
||||
push_switch='off',
|
||||
bbs_switch='off',
|
||||
region=SERVER.get(uid[0], 'cn_gf01'),
|
||||
)
|
||||
session.add(user_data)
|
||||
await session.commit()
|
||||
return True
|
||||
|
||||
async def update_user_data(self, uid: str, data: Optional[Dict]):
|
||||
sql = update(GsUser).where(
|
||||
GsUser.uid == uid and GsUser.bot_id == self.bot_id
|
||||
)
|
||||
if data is not None:
|
||||
query = sql.values(**data)
|
||||
query.execution_options(synchronize_session='fetch')
|
||||
await self.session.execute(query)
|
||||
await self.session.commit()
|
||||
async with self.async_session() as session:
|
||||
async with session.begin():
|
||||
sql = update(GsUser).where(
|
||||
GsUser.uid == uid and GsUser.bot_id == self.bot_id
|
||||
)
|
||||
if data is not None:
|
||||
query = sql.values(**data)
|
||||
query.execution_options(synchronize_session='fetch')
|
||||
await session.execute(query)
|
||||
await session.commit()
|
||||
|
||||
async def delete_user_data(self, uid: str):
|
||||
if await self.user_exists(uid):
|
||||
sql = delete(GsUser).where(GsUser.uid == uid)
|
||||
await self.session.execute(sql)
|
||||
await self.session.commit()
|
||||
return True
|
||||
return False
|
||||
async with self.async_session() as session:
|
||||
async with session.begin():
|
||||
if await self.user_exists(uid):
|
||||
sql = delete(GsUser).where(GsUser.uid == uid)
|
||||
await session.execute(sql)
|
||||
await session.commit()
|
||||
return True
|
||||
return False
|
||||
|
||||
async def delete_cache(self):
|
||||
sql = (
|
||||
update(GsUser)
|
||||
.where(GsUser.status == 'limit30')
|
||||
.values(status=None)
|
||||
)
|
||||
empty_sql = delete(GsCache)
|
||||
await self.session.execute(sql)
|
||||
await self.session.execute(empty_sql)
|
||||
await self.session.commit()
|
||||
async with self.async_session() as session:
|
||||
async with session.begin():
|
||||
sql = (
|
||||
update(GsUser)
|
||||
.where(GsUser.status == 'limit30')
|
||||
.values(status=None)
|
||||
)
|
||||
empty_sql = delete(GsCache)
|
||||
await session.execute(sql)
|
||||
await session.execute(empty_sql)
|
||||
await session.commit()
|
||||
|
||||
async def mark_invalid(self, cookie: str, mark: str):
|
||||
sql = update(GsUser).where(GsUser.cookie == cookie).values(status=mark)
|
||||
await self.session.execute(sql)
|
||||
await self.session.commit()
|
||||
async with self.async_session() as session:
|
||||
async with session.begin():
|
||||
sql = (
|
||||
update(GsUser)
|
||||
.where(GsUser.cookie == cookie)
|
||||
.values(status=mark)
|
||||
)
|
||||
await session.execute(sql)
|
||||
await session.commit()
|
||||
|
||||
async def user_exists(self, uid: str) -> bool:
|
||||
data = await self.select_user_data(uid)
|
||||
@ -226,36 +266,58 @@ class SQLA:
|
||||
async def update_user_stoken(
|
||||
self, uid: str, stoken: Optional[str]
|
||||
) -> bool:
|
||||
if await self.user_exists(uid):
|
||||
sql = update(GsUser).where(GsUser.uid == uid).values(stoken=stoken)
|
||||
await self.session.execute(sql)
|
||||
await self.session.commit()
|
||||
return True
|
||||
return False
|
||||
async with self.async_session() as session:
|
||||
async with session.begin():
|
||||
if await self.user_exists(uid):
|
||||
sql = (
|
||||
update(GsUser)
|
||||
.where(GsUser.uid == uid)
|
||||
.values(stoken=stoken)
|
||||
)
|
||||
await session.execute(sql)
|
||||
await session.commit()
|
||||
return True
|
||||
return False
|
||||
|
||||
async def update_user_cookie(
|
||||
self, uid: str, cookie: Optional[str]
|
||||
) -> bool:
|
||||
if await self.user_exists(uid):
|
||||
sql = update(GsUser).where(GsUser.uid == uid).values(cookie=cookie)
|
||||
await self.session.execute(sql)
|
||||
await self.session.commit()
|
||||
return True
|
||||
return False
|
||||
async with self.async_session() as session:
|
||||
async with session.begin():
|
||||
if await self.user_exists(uid):
|
||||
sql = (
|
||||
update(GsUser)
|
||||
.where(GsUser.uid == uid)
|
||||
.values(cookie=cookie)
|
||||
)
|
||||
await session.execute(sql)
|
||||
await session.commit()
|
||||
return True
|
||||
return False
|
||||
|
||||
async def update_switch_status(self, uid: str, data: Dict) -> bool:
|
||||
if await self.user_exists(uid):
|
||||
sql = update(GsUser).where(GsUser.uid == uid).values(**data)
|
||||
await self.session.execute(sql)
|
||||
await self.session.commit()
|
||||
return True
|
||||
return False
|
||||
async with self.async_session() as session:
|
||||
async with session.begin():
|
||||
if await self.user_exists(uid):
|
||||
sql = (
|
||||
update(GsUser).where(GsUser.uid == uid).values(**data)
|
||||
)
|
||||
await session.execute(sql)
|
||||
await session.commit()
|
||||
return True
|
||||
return False
|
||||
|
||||
async def update_error_status(self, cookie: str, err: str) -> bool:
|
||||
sql = update(GsUser).where(GsUser.cookie == cookie).values(status=err)
|
||||
await self.session.execute(sql)
|
||||
await self.session.commit()
|
||||
return True
|
||||
async with self.async_session() as session:
|
||||
async with session.begin():
|
||||
sql = (
|
||||
update(GsUser)
|
||||
.where(GsUser.cookie == cookie)
|
||||
.values(status=err)
|
||||
)
|
||||
await session.execute(sql)
|
||||
await session.commit()
|
||||
return True
|
||||
|
||||
async def get_user_cookie(self, uid: str) -> Optional[str]:
|
||||
data = await self.select_user_data(uid)
|
||||
@ -270,12 +332,14 @@ class SQLA:
|
||||
return data.stoken if data and data.stoken else None
|
||||
|
||||
async def get_all_user(self) -> List[GsUser]:
|
||||
sql = select(GsUser).where(
|
||||
GsUser.cookie is not None and GsUser.cookie != ''
|
||||
)
|
||||
result = await self.session.execute(sql)
|
||||
data: List[GsUser] = result.scalars().all()
|
||||
return data
|
||||
async with self.async_session() as session:
|
||||
async with session.begin():
|
||||
sql = select(GsUser).where(
|
||||
GsUser.cookie is not None and GsUser.cookie != ''
|
||||
)
|
||||
result = await session.execute(sql)
|
||||
data: List[GsUser] = result.scalars().all()
|
||||
return data
|
||||
|
||||
async def get_all_cookie(self) -> List[str]:
|
||||
data = await self.get_all_user()
|
||||
@ -294,74 +358,84 @@ class SQLA:
|
||||
return [user for user in data if user.push_switch != 'off']
|
||||
|
||||
async def get_random_cookie(self, uid: str) -> Optional[str]:
|
||||
# 有绑定自己CK 并且该CK有效的前提下,优先使用自己CK
|
||||
if await self.user_exists(uid) and await self.cookie_validate(uid):
|
||||
return await self.get_user_cookie(uid)
|
||||
# 自动刷新缓存
|
||||
await self.delete_error_cache()
|
||||
# 获得缓存库Ck
|
||||
cache_data = await self.select_cache_cookie(uid)
|
||||
if cache_data is not None:
|
||||
return cache_data
|
||||
# 随机取CK
|
||||
server = SERVER.get(uid[0], 'cn_gf01')
|
||||
sql = (
|
||||
select(GsUser)
|
||||
.where(GsUser.region == server)
|
||||
.order_by(func.random())
|
||||
)
|
||||
data = await self.session.execute(sql)
|
||||
user_list: List[GsUser] = data.scalars().all()
|
||||
for user in user_list:
|
||||
if not user.status and user.cookie:
|
||||
await self.insert_cache_data(user.cookie, uid) # 进入缓存
|
||||
return user.cookie
|
||||
continue
|
||||
else:
|
||||
return None
|
||||
async with self.async_session() as session:
|
||||
async with session.begin():
|
||||
# 有绑定自己CK 并且该CK有效的前提下,优先使用自己CK
|
||||
if await self.user_exists(uid) and await self.cookie_validate(
|
||||
uid
|
||||
):
|
||||
return await self.get_user_cookie(uid)
|
||||
# 自动刷新缓存
|
||||
await self.delete_error_cache()
|
||||
# 获得缓存库Ck
|
||||
cache_data = await self.select_cache_cookie(uid)
|
||||
if cache_data is not None:
|
||||
return cache_data
|
||||
# 随机取CK
|
||||
server = SERVER.get(uid[0], 'cn_gf01')
|
||||
sql = (
|
||||
select(GsUser)
|
||||
.where(GsUser.region == server)
|
||||
.order_by(func.random())
|
||||
)
|
||||
data = await session.execute(sql)
|
||||
user_list: List[GsUser] = data.scalars().all()
|
||||
for user in user_list:
|
||||
if not user.status and user.cookie:
|
||||
await self.insert_cache_data(user.cookie, uid) # 进入缓存
|
||||
return user.cookie
|
||||
continue
|
||||
else:
|
||||
return None
|
||||
|
||||
async def get_switch_status_list(
|
||||
self, switch: Literal['push', 'sign', 'bbs']
|
||||
) -> List[GsUser]:
|
||||
_switch = getattr(GsUser, switch, GsUser.push_switch)
|
||||
sql = select(GsUser).filter(_switch != 'off')
|
||||
data = await self.session.execute(sql)
|
||||
data_list: List[GsUser] = data.scalars().all()
|
||||
return [user for user in data_list]
|
||||
async with self.async_session() as session:
|
||||
async with session.begin():
|
||||
_switch = getattr(GsUser, switch, GsUser.push_switch)
|
||||
sql = select(GsUser).filter(_switch != 'off')
|
||||
data = await session.execute(sql)
|
||||
data_list: List[GsUser] = data.scalars().all()
|
||||
return [user for user in data_list]
|
||||
|
||||
#####################
|
||||
# GsPush 部分 #
|
||||
#####################
|
||||
async def insert_push_data(self, uid: str):
|
||||
push_data = GsPush(
|
||||
bot_id=self.bot_id,
|
||||
uid=uid,
|
||||
coin_push='off',
|
||||
coin_value=2100,
|
||||
coin_is_push='off',
|
||||
resin_push='on',
|
||||
resin_value=140,
|
||||
resin_is_push='off',
|
||||
go_push='off',
|
||||
go_value=120,
|
||||
go_is_push='off',
|
||||
transform_push='off',
|
||||
transform_value=140,
|
||||
transform_is_push='off',
|
||||
)
|
||||
self.session.add(push_data)
|
||||
await self.session.commit()
|
||||
async with self.async_session() as session:
|
||||
async with session.begin():
|
||||
push_data = GsPush(
|
||||
bot_id=self.bot_id,
|
||||
uid=uid,
|
||||
coin_push='off',
|
||||
coin_value=2100,
|
||||
coin_is_push='off',
|
||||
resin_push='on',
|
||||
resin_value=140,
|
||||
resin_is_push='off',
|
||||
go_push='off',
|
||||
go_value=120,
|
||||
go_is_push='off',
|
||||
transform_push='off',
|
||||
transform_value=140,
|
||||
transform_is_push='off',
|
||||
)
|
||||
session.add(push_data)
|
||||
await session.commit()
|
||||
|
||||
async def update_push_data(self, uid: str, data: dict) -> bool:
|
||||
await self.push_exists(uid)
|
||||
sql = (
|
||||
update(GsPush)
|
||||
.where(GsPush.uid == uid and GsPush.bot_id == self.bot_id)
|
||||
.values(**data)
|
||||
)
|
||||
await self.session.execute(sql)
|
||||
await self.session.commit()
|
||||
return True
|
||||
async with self.async_session() as session:
|
||||
async with session.begin():
|
||||
await self.push_exists(uid)
|
||||
sql = (
|
||||
update(GsPush)
|
||||
.where(GsPush.uid == uid and GsPush.bot_id == self.bot_id)
|
||||
.values(**data)
|
||||
)
|
||||
await session.execute(sql)
|
||||
await session.commit()
|
||||
return True
|
||||
|
||||
async def change_push_status(
|
||||
self,
|
||||
@ -372,42 +446,54 @@ class SQLA:
|
||||
await self.update_push_data(uid, {f'{mode}_is_push': status})
|
||||
|
||||
async def select_push_data(self, uid: str) -> Optional[GsPush]:
|
||||
await self.push_exists(uid)
|
||||
sql = select(GsPush).where(
|
||||
GsPush.uid == uid and GsPush.bot_id == self.bot_id
|
||||
)
|
||||
result = await self.session.execute(sql)
|
||||
data = result.scalars().all()
|
||||
return data[0] if len(data) >= 1 else None
|
||||
async with self.async_session() as session:
|
||||
async with session.begin():
|
||||
await self.push_exists(uid)
|
||||
sql = select(GsPush).where(
|
||||
GsPush.uid == uid and GsPush.bot_id == self.bot_id
|
||||
)
|
||||
result = await session.execute(sql)
|
||||
data = result.scalars().all()
|
||||
return data[0] if len(data) >= 1 else None
|
||||
|
||||
async def push_exists(self, uid: str) -> bool:
|
||||
sql = select(GsPush).where(
|
||||
GsPush.uid == uid and GsPush.bot_id == self.bot_id
|
||||
)
|
||||
result = await self.session.execute(sql)
|
||||
data = result.scalars().all()
|
||||
if not data:
|
||||
await self.insert_push_data(uid)
|
||||
return True
|
||||
async with self.async_session() as session:
|
||||
async with session.begin():
|
||||
sql = select(GsPush).where(
|
||||
GsPush.uid == uid and GsPush.bot_id == self.bot_id
|
||||
)
|
||||
result = await session.execute(sql)
|
||||
data = result.scalars().all()
|
||||
if not data:
|
||||
await self.insert_push_data(uid)
|
||||
return True
|
||||
|
||||
#####################
|
||||
# 杂项部分 #
|
||||
#####################
|
||||
|
||||
async def refresh_cache(self, uid: str):
|
||||
sql = delete(GsCache).where(GsCache.uid == uid)
|
||||
await self.session.execute(sql)
|
||||
return True
|
||||
async with self.async_session() as session:
|
||||
async with session.begin():
|
||||
sql = delete(GsCache).where(GsCache.uid == uid)
|
||||
await session.execute(sql)
|
||||
return True
|
||||
|
||||
async def close(self):
|
||||
await self.session.close()
|
||||
async with self.async_session() as session:
|
||||
async with session.begin():
|
||||
await session.close()
|
||||
|
||||
async def insert_new_bind(self, **kwargs):
|
||||
new_data = GsBind(**kwargs)
|
||||
self.session.add(new_data)
|
||||
await self.session.commit()
|
||||
async with self.async_session() as session:
|
||||
async with session.begin():
|
||||
new_data = GsBind(**kwargs)
|
||||
session.add(new_data)
|
||||
await session.commit()
|
||||
|
||||
async def insert_new_user(self, **kwargs):
|
||||
new_data = GsUser(**kwargs)
|
||||
self.session.add(new_data)
|
||||
await self.session.commit()
|
||||
async with self.async_session() as session:
|
||||
async with session.begin():
|
||||
new_data = GsUser(**kwargs)
|
||||
session.add(new_data)
|
||||
await session.commit()
|
||||
|
41
poetry.lock
generated
41
poetry.lock
generated
@ -326,14 +326,14 @@ typecheck = ["mypy"]
|
||||
|
||||
[[package]]
|
||||
name = "beautifulsoup4"
|
||||
version = "4.11.2"
|
||||
version = "4.12.0"
|
||||
description = "Screen-scraping library"
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.6.0"
|
||||
files = [
|
||||
{file = "beautifulsoup4-4.11.2-py3-none-any.whl", hash = "sha256:0e79446b10b3ecb499c1556f7e228a53e64a2bfcebd455f370d8927cb5b59e39"},
|
||||
{file = "beautifulsoup4-4.11.2.tar.gz", hash = "sha256:bc4bdda6717de5a2987436fb8d72f45dc90dd856bdfd512a1314ce90349a0106"},
|
||||
{file = "beautifulsoup4-4.12.0-py3-none-any.whl", hash = "sha256:2130a5ad7f513200fae61a17abb5e338ca980fa28c439c0571014bc0217e9591"},
|
||||
{file = "beautifulsoup4-4.12.0.tar.gz", hash = "sha256:c5fceeaec29d09c84970e47c65f2f0efe57872f7cff494c9691a26ec0ff13234"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
@ -593,14 +593,14 @@ test = ["pytest (>=6)"]
|
||||
|
||||
[[package]]
|
||||
name = "fastapi"
|
||||
version = "0.94.1"
|
||||
version = "0.95.0"
|
||||
description = "FastAPI framework, high performance, easy to learn, fast to code, ready for production"
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
files = [
|
||||
{file = "fastapi-0.94.1-py3-none-any.whl", hash = "sha256:451387550c2d25a972193f22e408a82e75a8e7867c834a03076704fe20df3256"},
|
||||
{file = "fastapi-0.94.1.tar.gz", hash = "sha256:4a75936dbf9eb74be5eb0d41a793adefe9f3fc6ba66dbdabd160120fd3c2d9cd"},
|
||||
{file = "fastapi-0.95.0-py3-none-any.whl", hash = "sha256:daf73bbe844180200be7966f68e8ec9fd8be57079dff1bacb366db32729e6eb5"},
|
||||
{file = "fastapi-0.95.0.tar.gz", hash = "sha256:99d4fdb10e9dd9a24027ac1d0bd4b56702652056ca17a6c8721eec4ad2f14e18"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
@ -615,14 +615,14 @@ test = ["anyio[trio] (>=3.2.1,<4.0.0)", "black (==23.1.0)", "coverage[toml] (>=6
|
||||
|
||||
[[package]]
|
||||
name = "fastapi-amis-admin"
|
||||
version = "0.5.0"
|
||||
version = "0.5.1"
|
||||
description = "FastAPI-Amis-Admin is a high-performance, efficient and easily extensible FastAPI admin framework. Inspired by Django-admin, and has as many powerful functions as Django-admin. "
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
files = [
|
||||
{file = "fastapi_amis_admin-0.5.0-py3-none-any.whl", hash = "sha256:82f232c27b277d83f8829c1be07ec64ebbc94acf6bfd6fadf30c1f9fc9ed2704"},
|
||||
{file = "fastapi_amis_admin-0.5.0.tar.gz", hash = "sha256:f17d9cba8e2b32374d5a6f6576b98867d5777668a92885663a01b7a0faf206ff"},
|
||||
{file = "fastapi_amis_admin-0.5.1-py3-none-any.whl", hash = "sha256:7cb65e6389c8f132152fd185cb8832d63a2401689db92b2e0fc2cb9d8d22969c"},
|
||||
{file = "fastapi_amis_admin-0.5.1.tar.gz", hash = "sha256:da4d11fc1f68bb48c817e02b477b5673e4d8e42dfec28e29eabd3937f2b35a36"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
@ -668,14 +668,14 @@ test = ["aiosqlite (>=0.15.0)", "jinja2 (>=2.11.2,<4.0.0)", "pytest (>=6.2.4)",
|
||||
|
||||
[[package]]
|
||||
name = "filelock"
|
||||
version = "3.9.1"
|
||||
version = "3.10.0"
|
||||
description = "A platform independent file lock."
|
||||
category = "dev"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
files = [
|
||||
{file = "filelock-3.9.1-py3-none-any.whl", hash = "sha256:4427cdda14a1c68e264845142842d6de2d0fa2c15ba31571a3d9c9a1ec9d191c"},
|
||||
{file = "filelock-3.9.1.tar.gz", hash = "sha256:e393782f76abea324dee598d2ea145b857a20df0e0ee4f80fcf35e72a341d2c7"},
|
||||
{file = "filelock-3.10.0-py3-none-any.whl", hash = "sha256:e90b34656470756edf8b19656785c5fea73afa1953f3e1b0d645cef11cab3182"},
|
||||
{file = "filelock-3.10.0.tar.gz", hash = "sha256:3199fd0d3faea8b911be52b663dfccceb84c95949dd13179aa21436d1a79c4ce"},
|
||||
]
|
||||
|
||||
[package.extras]
|
||||
@ -947,14 +947,14 @@ socks = ["socksio (>=1.0.0,<2.0.0)"]
|
||||
|
||||
[[package]]
|
||||
name = "identify"
|
||||
version = "2.5.20"
|
||||
version = "2.5.21"
|
||||
description = "File identification library for Python"
|
||||
category = "dev"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
files = [
|
||||
{file = "identify-2.5.20-py2.py3-none-any.whl", hash = "sha256:5dfef8a745ca4f2c95f27e9db74cb4c8b6d9916383988e8791f3595868f78a33"},
|
||||
{file = "identify-2.5.20.tar.gz", hash = "sha256:c8b288552bc5f05a08aff09af2f58e6976bf8ac87beb38498a0e3d98ba64eb18"},
|
||||
{file = "identify-2.5.21-py2.py3-none-any.whl", hash = "sha256:69edcaffa8e91ae0f77d397af60f148b6b45a8044b2cc6d99cafa5b04793ff00"},
|
||||
{file = "identify-2.5.21.tar.gz", hash = "sha256:7671a05ef9cfaf8ff63b15d45a91a1147a03aaccb2976d4e9bd047cbbc508471"},
|
||||
]
|
||||
|
||||
[package.extras]
|
||||
@ -2246,14 +2246,14 @@ files = [
|
||||
|
||||
[[package]]
|
||||
name = "tzlocal"
|
||||
version = "4.2"
|
||||
version = "4.3"
|
||||
description = "tzinfo object for the local timezone"
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.6"
|
||||
python-versions = ">=3.7"
|
||||
files = [
|
||||
{file = "tzlocal-4.2-py3-none-any.whl", hash = "sha256:89885494684c929d9191c57aa27502afc87a579be5cdd3225c77c463ea043745"},
|
||||
{file = "tzlocal-4.2.tar.gz", hash = "sha256:ee5842fa3a795f023514ac2d801c4a81d1743bbe642e3940143326b3a00addd7"},
|
||||
{file = "tzlocal-4.3-py3-none-any.whl", hash = "sha256:b44c4388f3d34f25862cfbb387578a4d70fec417649da694a132f628a23367e2"},
|
||||
{file = "tzlocal-4.3.tar.gz", hash = "sha256:3f21d09e1b2aa9f2dacca12da240ca37de3ba5237a93addfd6d593afe9073355"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
@ -2262,8 +2262,7 @@ pytz-deprecation-shim = "*"
|
||||
tzdata = {version = "*", markers = "platform_system == \"Windows\""}
|
||||
|
||||
[package.extras]
|
||||
devenv = ["black", "pyroma", "pytest-cov", "zest.releaser"]
|
||||
test = ["pytest (>=4.3)", "pytest-mock (>=3.3)"]
|
||||
devenv = ["black", "check-manifest", "flake8", "pyroma", "pytest (>=4.3)", "pytest-cov", "pytest-mock (>=3.3)", "zest.releaser"]
|
||||
|
||||
[[package]]
|
||||
name = "urllib3"
|
||||
|
@ -8,16 +8,16 @@ async-timeout==4.0.2 ; python_full_version >= "3.8.1" and python_full_version <
|
||||
attrs==22.2.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
backports-zoneinfo==0.2.1 ; python_full_version >= "3.8.1" and python_version < "3.9"
|
||||
bcrypt==4.0.1 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
beautifulsoup4==4.11.2 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
beautifulsoup4==4.12.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
certifi==2022.12.7 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
charset-normalizer==3.1.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
colorama==0.4.6 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0" and platform_system == "Windows" or python_full_version >= "3.8.1" and python_version < "4.0" and sys_platform == "win32"
|
||||
dnspython==2.3.0 ; python_full_version >= "3.8.1" and python_version < "4.0"
|
||||
email-validator==1.3.1 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
et-xmlfile==1.1.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
fastapi-amis-admin==0.5.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
fastapi-amis-admin==0.5.1 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
fastapi-user-auth==0.5.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
fastapi==0.94.1 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
fastapi==0.95.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
frozenlist==1.3.3 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
gitdb==4.0.10 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
gitpython==3.1.31 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
@ -59,6 +59,6 @@ starlette==0.26.1 ; python_full_version >= "3.8.1" and python_full_version < "4.
|
||||
tomlkit==0.11.6 ; python_full_version >= "3.8.1" and python_version < "4.0"
|
||||
typing-extensions==4.5.0 ; python_full_version >= "3.8.1" and python_version < "4.0"
|
||||
tzdata==2022.7 ; python_full_version >= "3.8.1" and python_version < "4.0"
|
||||
tzlocal==4.2 ; python_full_version >= "3.8.1" and python_version < "4.0"
|
||||
tzlocal==4.3 ; python_full_version >= "3.8.1" and python_version < "4.0"
|
||||
win32-setctime==1.1.0 ; python_full_version >= "3.8.1" and python_version < "4.0" and sys_platform == "win32"
|
||||
yarl==1.8.2 ; python_full_version >= "3.8.1" and python_version < "4.0"
|
||||
|
Loading…
x
Reference in New Issue
Block a user