mirror of
https://github.com/PaiGramTeam/PaiGram.git
synced 2024-11-16 04:35:49 +00:00
⚡ 给 genshin.py
添加 Redis cache
This commit is contained in:
parent
465f7c4148
commit
abf44075aa
@ -16,6 +16,7 @@ from genshin import Client, types
|
|||||||
from httpx import UnsupportedProtocol
|
from httpx import UnsupportedProtocol
|
||||||
from typing_extensions import ParamSpec
|
from typing_extensions import ParamSpec
|
||||||
|
|
||||||
|
from core.base.redisdb import RedisDB
|
||||||
from core.bot import bot
|
from core.bot import bot
|
||||||
from core.cookies.services import CookiesService, PublicCookiesService
|
from core.cookies.services import CookiesService, PublicCookiesService
|
||||||
from core.error import ServiceNotFoundError
|
from core.error import ServiceNotFoundError
|
||||||
@ -43,6 +44,11 @@ user_service = bot.services.get(UserService)
|
|||||||
user_service = cast(UserService, user_service)
|
user_service = cast(UserService, user_service)
|
||||||
public_cookies_service = bot.services.get(PublicCookiesService)
|
public_cookies_service = bot.services.get(PublicCookiesService)
|
||||||
public_cookies_service = cast(PublicCookiesService, public_cookies_service)
|
public_cookies_service = cast(PublicCookiesService, public_cookies_service)
|
||||||
|
redis_db = bot.services.get(RedisDB)
|
||||||
|
redis_db = cast(RedisDB, redis_db)
|
||||||
|
genshin_cache: Optional[genshin.RedisCache] = None
|
||||||
|
if redis_db:
|
||||||
|
genshin_cache = genshin.RedisCache(redis_db.client)
|
||||||
|
|
||||||
REGION_MAP = {
|
REGION_MAP = {
|
||||||
"1": RegionEnum.HYPERION,
|
"1": RegionEnum.HYPERION,
|
||||||
@ -109,6 +115,8 @@ async def get_genshin_client(user_id: int, region: Optional[RegionEnum] = None,
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
raise TypeError("region is not RegionEnum.NULL")
|
raise TypeError("region is not RegionEnum.NULL")
|
||||||
|
if genshin_cache:
|
||||||
|
client.cache = genshin_cache
|
||||||
return client
|
return client
|
||||||
|
|
||||||
|
|
||||||
@ -130,6 +138,8 @@ async def get_public_genshin_client(user_id: int) -> Tuple[Client, Optional[int]
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
raise TypeError("region is not RegionEnum.NULL")
|
raise TypeError("region is not RegionEnum.NULL")
|
||||||
|
if genshin_cache:
|
||||||
|
client.cache = genshin_cache
|
||||||
return client, uid
|
return client, uid
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user