🔧 支持使用配置文件是否启用 genshin.py 模块的缓存

This commit is contained in:
洛水居室 2022-10-22 23:51:39 +08:00
parent bf90ca55f9
commit 291b21f674
No known key found for this signature in database
GPG Key ID: C9DE87DA724B88FC
3 changed files with 15 additions and 9 deletions

View File

@ -53,6 +53,9 @@ LOGGER_LOCALS_MAX_STRING=80
# CONNECT_TIMEOUT = 10
# POOL_TIMEOUT = 10
# genshin.py 缓存配置 可选配置项
# GENSHIN_TTL = 3600
# mtp 客户端 可选配置项
# API_ID=12345
# API_HASH="abcdefg"

View File

@ -63,6 +63,8 @@ class BotConfig(BaseSettings):
connect_timeout: Optional[float] = None
pool_timeout: Optional[float] = None
genshin_ttl: Optional[int] = None
enka_network_api_agent: str = ""
pass_challenge_api: str = ""
pass_challenge_app_key: str = ""

View File

@ -18,6 +18,7 @@ from typing_extensions import ParamSpec
from core.base.redisdb import RedisDB
from core.bot import bot
from core.config import config
from core.cookies.services import CookiesService, PublicCookiesService
from core.error import ServiceNotFoundError
from core.user.services import UserService
@ -47,8 +48,8 @@ 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)
if redis_db and config.genshin_ttl:
genshin_cache = genshin.RedisCache(redis_db.client, ttl=config.genshin_ttl)
REGION_MAP = {
"1": RegionEnum.HYPERION,