diff --git a/plugins/genshin/avatar_list.py b/plugins/genshin/avatar_list.py index 52d0d51c..d98c177d 100644 --- a/plugins/genshin/avatar_list.py +++ b/plugins/genshin/avatar_list.py @@ -4,7 +4,7 @@ from typing import Iterable, List, Optional, Sequence from aiohttp import ClientConnectorError from arkowrapper import ArkoWrapper -from enkanetwork import Assets as EnkaAssets, EnkaNetworkAPI, VaildateUIDError, UIDNotFounded, HTTPException +from enkanetwork import Assets as EnkaAssets, EnkaNetworkAPI, VaildateUIDError, HTTPException, EnkaPlayerNotFound from genshin import Client, GenshinException, InvalidCookies from genshin.models import CalculatorCharacterDetails, CalculatorTalent, Character from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Message, Update, User @@ -65,7 +65,7 @@ class AvatarListPlugin(Plugin, BasePlugin): self.cookies_service = cookies_service self.assets_service = assets_service self.template_service = template_service - self.enka_client = EnkaNetworkAPI(lang="chs", agent=config.enka_network_api_agent) + self.enka_client = EnkaNetworkAPI(lang="chs", user_agent=config.enka_network_api_agent) self.enka_client.set_cache(RedisCache(redis.client, key="plugin:avatar_list:enka_network", ttl=60 * 60 * 3)) self.enka_assets = EnkaAssets(lang="chs") @@ -184,7 +184,7 @@ class AvatarListPlugin(Plugin, BasePlugin): else: rarity = {k: v["rank"] for k, v in AVATAR_DATA.items()}[str(response.player.avatar.id)] return name_card, avatar, nickname, rarity - except (VaildateUIDError, UIDNotFounded, HTTPException) as exc: + except (VaildateUIDError, EnkaPlayerNotFound, HTTPException) as exc: logger.warning("EnkaNetwork 请求失败: %s", str(exc)) except (AioHttpTimeoutException, ClientConnectorError) as exc: logger.warning("EnkaNetwork 请求超时: %s", str(exc)) diff --git a/plugins/genshin/player_cards.py b/plugins/genshin/player_cards.py index 66728180..ffe3f3a5 100644 --- a/plugins/genshin/player_cards.py +++ b/plugins/genshin/player_cards.py @@ -11,12 +11,13 @@ from enkanetwork import ( Equipments, EquipmentsStats, EquipmentsType, - Forbidden, HTTPException, Stats, StatsPercentage, - UIDNotFounded, VaildateUIDError, + EnkaServerMaintanance, + EnkaServerUnknown, + EnkaServerRateLimit, ) from pydantic import BaseModel from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update @@ -50,7 +51,7 @@ class PlayerCards(Plugin, BasePlugin): self, user_service: UserService = None, template_service: TemplateService = None, redis: RedisDB = None ): self.user_service = user_service - self.client = EnkaNetworkAPI(lang="chs", agent=config.enka_network_api_agent, cache=False) + self.client = EnkaNetworkAPI(lang="chs", user_agent=config.enka_network_api_agent, cache=False) self.cache = RedisCache(redis.client, key="plugin:player_cards:enka_network") self.player_cards_file = PlayerCardsFile() self.template_service = template_service @@ -61,22 +62,26 @@ class PlayerCards(Plugin, BasePlugin): data = await self.cache.get(uid) if data is not None: return EnkaNetworkResponse.parse_obj(data) - user = await self.client.http.fetch_user(uid) + user = await self.client.http.fetch_user_by_uid(uid) data = user["content"].decode("utf-8", "surrogatepass") # type: ignore data = ujson.loads(data) data = await self.player_cards_file.merge_info(uid, data) await self.cache.set(uid, data) return EnkaNetworkResponse.parse_obj(data) - except EnkaServerError: - error = "Enka.Network 服务请求错误,请稍后重试" - except Forbidden: - error = "Enka.Network 服务请求被拒绝,请稍后重试" except AioHttpTimeoutException: error = "Enka.Network 服务请求超时,请稍后重试" + except EnkaServerRateLimit: + error = "Enka.Network 已对此API进行速率限制,请稍后重试" + except EnkaServerMaintanance: + error = "Enka.Network 正在维护,请等待5-8小时或1天" + except EnkaServerError: + error = "Enka.Network 服务请求错误,请稍后重试" + except EnkaServerUnknown: + error = "Enka.Network 服务瞬间爆炸,请稍后重试" + except (VaildateUIDError, VaildateUIDError): + error = "UID 未找到,可能为服务器抽风,请稍后重试" except HTTPException: error = "Enka.Network HTTP 服务请求错误,请稍后重试" - except (UIDNotFounded, VaildateUIDError): - error = "UID 未找到,可能为服务器抽风,请稍后重试" old_data = await self.player_cards_file.load_history_info(uid) if old_data is not None: logger.warning("UID %s | 角色卡片使用历史数据 | %s", uid, error)