fix: token user sometimes invaild

This commit is contained in:
xtaodada 2023-07-24 20:03:44 +08:00
parent 13877ebe41
commit f801953a1f
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
3 changed files with 3 additions and 4 deletions

View File

@ -189,7 +189,7 @@ async def rerun_misskey_bot(user_id: int) -> bool:
async def init_misskey_bot():
await sqlite.create_db_and_tables()
count = 0
for user in await UserAction.get_all_token_ok_users():
for user in await UserAction.get_all_have_token_users():
mid = await test_token(user.host, user.token)
if not mid:
logs.warning(f"{user.user_id} Token 失效")

View File

@ -41,7 +41,7 @@ class RevokeAction:
keys = []
async for key in cache.scan(f"sub:{uid}:*"):
key: str
keys.append(key[4:])
keys.append(key.split(":")[-1])
return keys
@staticmethod

View File

@ -49,12 +49,11 @@ class UserAction:
return None
@staticmethod
async def get_all_token_ok_users() -> list[User]:
async def get_all_have_token_users() -> list[User]:
async with sqlite.session() as session:
session = cast(AsyncSession, session)
statement = (
select(User)
.where(User.status == TokenStatusEnum.STATUS_SUCCESS)
.where(User.token != "")
.where(User.host != "")
)