diff --git a/.env.example b/.env.example index a21c906..a187cf4 100644 --- a/.env.example +++ b/.env.example @@ -46,6 +46,13 @@ LOGGER_LOCALS_MAX_DEPTH=0 LOGGER_LOCALS_MAX_LENGTH=10 LOGGER_LOCALS_MAX_STRING=80 +# 超时配置 可选配置项 +# TIMEOUT = 10 +# READ_TIMEOUT = 2 +# WRITE_TIMEOUT = 10 +# CONNECT_TIMEOUT = 10 +# POOL_TIMEOUT = 10 + # mtp 客户端 可选配置项 # API_ID=12345 # API_HASH="abcdefg" diff --git a/core/bot.py b/core/bot.py index d923e2a..4d43cee 100644 --- a/core/bot.py +++ b/core/bot.py @@ -243,7 +243,14 @@ class Bot: try: for _ in range(5): try: - self.app.run_polling(close_loop=False, write_timeout=10) + self.app.run_polling( + close_loop=False, + timeout=self.config.timeout, + read_timeout=self.config.read_timeout, + write_timeout=self.config.write_timeout, + connect_timeout=self.config.connect_timeout, + pool_timeout=self.config.pool_timeout, + ) break except TimedOut: logger.warning("连接至 [blue]telegram[/] 服务器失败,正在重试", extra={"markup": True}) diff --git a/core/config.py b/core/config.py index c97e6d2..4e24be7 100644 --- a/core/config.py +++ b/core/config.py @@ -57,6 +57,12 @@ class BotConfig(BaseSettings): logger_locals_max_length: int = 10 logger_locals_max_string: int = 80 + timeout: int = 10 + read_timeout: float = 2 + write_timeout: Optional[float] = None + connect_timeout: Optional[float] = None + pool_timeout: Optional[float] = None + enka_network_api_agent: str = "" pass_challenge_api: str = "" pass_challenge_app_key: str = ""