mirror of
https://github.com/PaiGramTeam/PaiGram.git
synced 2024-11-16 04:35:49 +00:00
🐛 Fix region class error
This commit is contained in:
parent
18a0cb5597
commit
e9992969fa
@ -12,6 +12,8 @@ from simnet.errors import (
|
||||
InvalidCookies,
|
||||
TooManyRequests,
|
||||
CookieException,
|
||||
TimedOut as SIMNetTimedOut,
|
||||
SIMNetException,
|
||||
)
|
||||
from telegram import ReplyKeyboardRemove, Update, InlineKeyboardMarkup, InlineKeyboardButton
|
||||
from telegram.constants import ParseMode
|
||||
@ -106,10 +108,16 @@ class ErrorHandler(Plugin):
|
||||
|
||||
@error_handler()
|
||||
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
|
||||
exc = context.error
|
||||
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):
|
||||
notice = self.ERROR_MSG_PREFIX + "Cookie 无效,请尝试重新绑定"
|
||||
elif isinstance(exc, InvalidCookies):
|
||||
|
@ -3,6 +3,7 @@ from typing import Tuple, Optional
|
||||
from simnet import Region
|
||||
from simnet.errors import BadRequest as SIMNetBadRequest
|
||||
|
||||
from core.basemodel import RegionEnum
|
||||
from core.dependence.redisdb import RedisDB
|
||||
from core.plugin import Plugin
|
||||
from core.services.cookies import CookiesService
|
||||
@ -92,7 +93,7 @@ class ChallengeSystem(Plugin):
|
||||
player = await self.players_service.get_player(user_id)
|
||||
if player is None:
|
||||
raise ChallengeSystemException("用户未找到")
|
||||
if player.region != Region.CHINESE:
|
||||
if player.region != RegionEnum.HYPERION:
|
||||
raise ChallengeSystemException("非法用户")
|
||||
cookie_model = await self.cookies_service.get(player.user_id, player.account_id, player.region)
|
||||
if cookie_model is None:
|
||||
|
@ -5,10 +5,9 @@ import time
|
||||
from enum import Enum
|
||||
from typing import Optional, Tuple, List, TYPE_CHECKING
|
||||
|
||||
from aiohttp import ClientConnectorError
|
||||
from httpx import TimeoutException
|
||||
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 telegram import InlineKeyboardButton, InlineKeyboardMarkup
|
||||
from telegram.constants import ParseMode
|
||||
@ -299,7 +298,7 @@ class SignSystem(Plugin):
|
||||
except SimnetBadRequest as exc:
|
||||
text = f"自动签到执行失败,API返回信息为 {str(exc)}"
|
||||
sign_db.status = SignStatusEnum.GENSHIN_EXCEPTION
|
||||
except ClientConnectorError:
|
||||
except SimnetTimedOut:
|
||||
text = "签到失败了呜呜呜 ~ 服务器连接超时 服务器熟啦 ~ "
|
||||
sign_db.status = SignStatusEnum.TIMEOUT_ERROR
|
||||
except NeedChallenge:
|
||||
|
@ -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
24
utils/patch/simnet.py
Normal 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,
|
||||
)
|
Loading…
Reference in New Issue
Block a user