🐛 Fix region class error

This commit is contained in:
omg-xtao 2023-07-19 20:28:19 +08:00 committed by GitHub
parent 18a0cb5597
commit e9992969fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 39 additions and 7 deletions

View File

@ -12,6 +12,8 @@ from simnet.errors import (
InvalidCookies, InvalidCookies,
TooManyRequests, TooManyRequests,
CookieException, CookieException,
TimedOut as SIMNetTimedOut,
SIMNetException,
) )
from telegram import ReplyKeyboardRemove, Update, InlineKeyboardMarkup, InlineKeyboardButton from telegram import ReplyKeyboardRemove, Update, InlineKeyboardMarkup, InlineKeyboardButton
from telegram.constants import ParseMode from telegram.constants import ParseMode
@ -106,10 +108,16 @@ class ErrorHandler(Plugin):
@error_handler() @error_handler()
async def process_genshin_exception(self, update: object, context: CallbackContext): async def process_genshin_exception(self, update: object, context: CallbackContext):
if not isinstance(context.error, SIMNetBadRequest) or not isinstance(update, Update): if not isinstance(context.error, SIMNetException) or not isinstance(update, Update):
return return
exc = context.error exc = context.error
notice: Optional[str] = None notice: Optional[str] = None
if isinstance(exc, SIMNetTimedOut):
notice = self.ERROR_MSG_PREFIX + " 服务器熟啦 ~ 请稍后再试"
self.create_notice_task(update, context, notice)
raise ApplicationHandlerStop
if not isinstance(exc, SIMNetBadRequest) or not isinstance(update, Update):
return
if isinstance(exc, TooManyRequests): if isinstance(exc, TooManyRequests):
notice = self.ERROR_MSG_PREFIX + "Cookie 无效,请尝试重新绑定" notice = self.ERROR_MSG_PREFIX + "Cookie 无效,请尝试重新绑定"
elif isinstance(exc, InvalidCookies): elif isinstance(exc, InvalidCookies):

View File

@ -3,6 +3,7 @@ from typing import Tuple, Optional
from simnet import Region from simnet import Region
from simnet.errors import BadRequest as SIMNetBadRequest from simnet.errors import BadRequest as SIMNetBadRequest
from core.basemodel import RegionEnum
from core.dependence.redisdb import RedisDB from core.dependence.redisdb import RedisDB
from core.plugin import Plugin from core.plugin import Plugin
from core.services.cookies import CookiesService from core.services.cookies import CookiesService
@ -92,7 +93,7 @@ class ChallengeSystem(Plugin):
player = await self.players_service.get_player(user_id) player = await self.players_service.get_player(user_id)
if player is None: if player is None:
raise ChallengeSystemException("用户未找到") raise ChallengeSystemException("用户未找到")
if player.region != Region.CHINESE: if player.region != RegionEnum.HYPERION:
raise ChallengeSystemException("非法用户") raise ChallengeSystemException("非法用户")
cookie_model = await self.cookies_service.get(player.user_id, player.account_id, player.region) cookie_model = await self.cookies_service.get(player.user_id, player.account_id, player.region)
if cookie_model is None: if cookie_model is None:

View File

@ -5,10 +5,9 @@ import time
from enum import Enum from enum import Enum
from typing import Optional, Tuple, List, TYPE_CHECKING from typing import Optional, Tuple, List, TYPE_CHECKING
from aiohttp import ClientConnectorError
from httpx import TimeoutException from httpx import TimeoutException
from simnet import Game from simnet import Game
from simnet.errors import BadRequest as SimnetBadRequest, AlreadyClaimed, InvalidCookies from simnet.errors import BadRequest as SimnetBadRequest, AlreadyClaimed, InvalidCookies, TimedOut as SimnetTimedOut
from simnet.utils.player import recognize_genshin_server from simnet.utils.player import recognize_genshin_server
from telegram import InlineKeyboardButton, InlineKeyboardMarkup from telegram import InlineKeyboardButton, InlineKeyboardMarkup
from telegram.constants import ParseMode from telegram.constants import ParseMode
@ -299,7 +298,7 @@ class SignSystem(Plugin):
except SimnetBadRequest as exc: except SimnetBadRequest as exc:
text = f"自动签到执行失败API返回信息为 {str(exc)}" text = f"自动签到执行失败API返回信息为 {str(exc)}"
sign_db.status = SignStatusEnum.GENSHIN_EXCEPTION sign_db.status = SignStatusEnum.GENSHIN_EXCEPTION
except ClientConnectorError: except SimnetTimedOut:
text = "签到失败了呜呜呜 ~ 服务器连接超时 服务器熟啦 ~ " text = "签到失败了呜呜呜 ~ 服务器连接超时 服务器熟啦 ~ "
sign_db.status = SignStatusEnum.TIMEOUT_ERROR sign_db.status = SignStatusEnum.TIMEOUT_ERROR
except NeedChallenge: except NeedChallenge:

View File

@ -1,3 +1,3 @@
from utils.patch import aiohttp from utils.patch import aiohttp, simnet
__all__ = ["aiohttp"] __all__ = ["aiohttp", "simnet"]

24
utils/patch/simnet.py Normal file
View File

@ -0,0 +1,24 @@
import simnet
from httpx import AsyncClient, Timeout, Limits
from core.config import config
from utils.patch.methods import patch, patchable
@patch(simnet.GenshinClient)
class GenshinClient:
@patchable
def __init__(self, *args, **kwargs):
self.old___init__(*args, **kwargs)
self.client: AsyncClient
if config.connect_timeout and config.read_timeout and config.write_timeout and config.pool_timeout:
self.client.timeout = Timeout(
connect=config.connect_timeout,
read=config.read_timeout,
write=config.write_timeout,
pool=config.pool_timeout,
)
self.client.limits = Limits(
max_connections=config.connection_pool_size,
max_keepalive_connections=config.connection_pool_size,
)