From abf44075aa2dd84554a881606b244d4abc79d4bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=9B=E6=B0=B4=E5=B1=85=E5=AE=A4?= Date: Sat, 22 Oct 2022 16:29:10 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20=E7=BB=99=20`genshin.py`=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20Redis=20cache?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/helpers.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/utils/helpers.py b/utils/helpers.py index c0fbc4f..16a890f 100644 --- a/utils/helpers.py +++ b/utils/helpers.py @@ -16,6 +16,7 @@ from genshin import Client, types from httpx import UnsupportedProtocol from typing_extensions import ParamSpec +from core.base.redisdb import RedisDB from core.bot import bot from core.cookies.services import CookiesService, PublicCookiesService from core.error import ServiceNotFoundError @@ -43,6 +44,11 @@ user_service = bot.services.get(UserService) user_service = cast(UserService, user_service) public_cookies_service = bot.services.get(PublicCookiesService) 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 = { "1": RegionEnum.HYPERION, @@ -109,6 +115,8 @@ async def get_genshin_client(user_id: int, region: Optional[RegionEnum] = None, ) else: raise TypeError("region is not RegionEnum.NULL") + if genshin_cache: + client.cache = genshin_cache return client @@ -130,6 +138,8 @@ async def get_public_genshin_client(user_id: int) -> Tuple[Client, Optional[int] ) else: raise TypeError("region is not RegionEnum.NULL") + if genshin_cache: + client.cache = genshin_cache return client, uid