2022-10-16 10:15:23 +00:00
|
|
|
from enum import Enum
|
2022-09-10 15:30:13 +00:00
|
|
|
from pathlib import Path
|
2023-03-14 01:27:22 +00:00
|
|
|
from typing import List, Optional, Union
|
2022-09-08 01:08:37 +00:00
|
|
|
|
|
|
|
import dotenv
|
2023-03-14 01:27:22 +00:00
|
|
|
from pydantic import AnyUrl, Field
|
2022-09-08 01:08:37 +00:00
|
|
|
|
2023-03-14 01:27:22 +00:00
|
|
|
from core.basemodel import Settings
|
2022-09-10 15:30:13 +00:00
|
|
|
from utils.const import PROJECT_ROOT
|
2022-10-28 07:39:17 +00:00
|
|
|
from utils.typedefs import NaturalNumber
|
2022-09-10 15:30:13 +00:00
|
|
|
|
2023-03-14 01:27:22 +00:00
|
|
|
__all__ = ("ApplicationConfig", "config", "JoinGroups")
|
2022-10-13 13:01:45 +00:00
|
|
|
|
2022-09-08 01:08:37 +00:00
|
|
|
dotenv.load_dotenv()
|
|
|
|
|
|
|
|
|
2022-10-16 10:15:23 +00:00
|
|
|
class JoinGroups(str, Enum):
|
|
|
|
NO_ALLOW = "NO_ALLOW"
|
|
|
|
ALLOW_AUTH_USER = "ALLOW_AUTH_USER"
|
2023-01-23 13:34:13 +00:00
|
|
|
ALLOW_USER = "ALLOW_USER"
|
2022-10-16 10:15:23 +00:00
|
|
|
ALLOW_ALL = "ALLOW_ALL"
|
|
|
|
|
|
|
|
|
2022-10-28 07:11:14 +00:00
|
|
|
class MySqlConfig(Settings):
|
2022-09-08 01:08:37 +00:00
|
|
|
host: str = "127.0.0.1"
|
|
|
|
port: int = 3306
|
2023-03-14 01:27:22 +00:00
|
|
|
username: Optional[str] = None
|
|
|
|
password: Optional[str] = None
|
|
|
|
database: Optional[str] = None
|
2022-09-08 01:08:37 +00:00
|
|
|
|
2022-10-28 07:11:14 +00:00
|
|
|
class Config(Settings.Config):
|
|
|
|
env_prefix = "db_"
|
|
|
|
|
2022-09-08 01:08:37 +00:00
|
|
|
|
2022-10-28 07:11:14 +00:00
|
|
|
class RedisConfig(Settings):
|
2022-10-10 05:34:06 +00:00
|
|
|
host: str = "127.0.0.1"
|
2022-10-28 07:11:14 +00:00
|
|
|
port: int = 6379
|
2023-01-05 07:36:10 +00:00
|
|
|
database: int = Field(default=0, env="redis_db")
|
|
|
|
password: Optional[str] = None
|
2022-09-08 01:08:37 +00:00
|
|
|
|
2022-10-28 07:11:14 +00:00
|
|
|
class Config(Settings.Config):
|
|
|
|
env_prefix = "redis_"
|
2022-09-08 01:08:37 +00:00
|
|
|
|
2022-10-28 07:11:14 +00:00
|
|
|
|
|
|
|
class LoggerConfig(Settings):
|
2022-10-23 09:15:09 +00:00
|
|
|
name: str = "TGPaimon"
|
2023-03-14 01:27:22 +00:00
|
|
|
width: Optional[int] = None
|
2022-09-10 15:30:13 +00:00
|
|
|
time_format: str = "[%Y-%m-%d %X]"
|
|
|
|
traceback_max_frames: int = 20
|
2022-10-10 05:34:06 +00:00
|
|
|
path: Path = PROJECT_ROOT / "logs"
|
|
|
|
render_keywords: List[str] = ["BOT"]
|
2022-10-13 13:01:45 +00:00
|
|
|
locals_max_length: int = 10
|
|
|
|
locals_max_string: int = 80
|
2022-10-28 07:39:17 +00:00
|
|
|
locals_max_depth: Optional[NaturalNumber] = None
|
2022-10-23 09:15:09 +00:00
|
|
|
filtered_names: List[str] = ["uvicorn"]
|
2022-10-13 13:01:45 +00:00
|
|
|
|
2022-10-28 07:11:14 +00:00
|
|
|
class Config(Settings.Config):
|
|
|
|
env_prefix = "logger_"
|
|
|
|
|
|
|
|
|
|
|
|
class MTProtoConfig(Settings):
|
|
|
|
api_id: Optional[int] = None
|
|
|
|
api_hash: Optional[str] = None
|
|
|
|
|
|
|
|
|
|
|
|
class WebServerConfig(Settings):
|
2023-03-14 01:27:22 +00:00
|
|
|
enable: bool = False
|
|
|
|
"""是否启用WebServer"""
|
|
|
|
|
2022-10-28 07:11:14 +00:00
|
|
|
url: AnyUrl = "http://localhost:8080"
|
|
|
|
host: str = "localhost"
|
|
|
|
port: int = 8080
|
|
|
|
|
|
|
|
class Config(Settings.Config):
|
|
|
|
env_prefix = "web_"
|
2022-09-10 15:30:13 +00:00
|
|
|
|
2022-09-11 07:08:02 +00:00
|
|
|
|
2022-10-28 07:11:14 +00:00
|
|
|
class ErrorConfig(Settings):
|
|
|
|
pb_url: str = ""
|
|
|
|
pb_sunset: int = 43200
|
|
|
|
pb_max_lines: int = 1000
|
|
|
|
sentry_dsn: str = ""
|
|
|
|
notification_chat_id: Optional[str] = None
|
|
|
|
|
|
|
|
class Config(Settings.Config):
|
|
|
|
env_prefix = "error_"
|
|
|
|
|
|
|
|
|
2023-03-14 01:27:22 +00:00
|
|
|
class ReloadConfig(Settings):
|
|
|
|
delay: float = 0.25
|
|
|
|
dirs: List[str] = []
|
|
|
|
include: List[str] = []
|
|
|
|
exclude: List[str] = []
|
2023-01-07 20:01:28 +00:00
|
|
|
|
|
|
|
class Config(Settings.Config):
|
2023-03-14 01:27:22 +00:00
|
|
|
env_prefix = "reload_"
|
2023-01-07 20:01:28 +00:00
|
|
|
|
|
|
|
|
2023-03-14 01:27:22 +00:00
|
|
|
class NoticeConfig(Settings):
|
|
|
|
user_mismatch: str = "再乱点我叫西风骑士团、千岩军、天领奉行、三十人团和风纪官了!"
|
2023-02-18 05:03:58 +00:00
|
|
|
|
|
|
|
class Config(Settings.Config):
|
2023-03-14 01:27:22 +00:00
|
|
|
env_prefix = "notice_"
|
2023-02-18 05:03:58 +00:00
|
|
|
|
|
|
|
|
2023-03-14 01:27:22 +00:00
|
|
|
class ApplicationConfig(Settings):
|
2022-10-28 07:11:14 +00:00
|
|
|
debug: bool = False
|
2023-03-14 01:27:22 +00:00
|
|
|
"""debug 开关"""
|
|
|
|
retry: int = 5
|
|
|
|
"""重试次数"""
|
|
|
|
auto_reload: bool = False
|
|
|
|
"""自动重载"""
|
|
|
|
|
|
|
|
proxy_url: Optional[AnyUrl] = None
|
|
|
|
"""代理链接"""
|
2022-10-28 07:11:14 +00:00
|
|
|
|
|
|
|
bot_token: str = ""
|
2023-03-14 01:27:22 +00:00
|
|
|
"""BOT的token"""
|
|
|
|
|
|
|
|
owner: Optional[int] = None
|
|
|
|
|
|
|
|
channels: List[int] = []
|
|
|
|
"""文章推送群组"""
|
2022-10-28 07:11:14 +00:00
|
|
|
|
|
|
|
verify_groups: List[Union[int, str]] = []
|
2023-03-14 01:27:22 +00:00
|
|
|
"""启用群验证功能的群组"""
|
2022-10-28 07:11:14 +00:00
|
|
|
join_groups: Optional[JoinGroups] = JoinGroups.NO_ALLOW
|
2023-03-14 01:27:22 +00:00
|
|
|
"""是否允许机器人被邀请到其它群组"""
|
2022-10-28 07:11:14 +00:00
|
|
|
|
|
|
|
timeout: int = 10
|
2023-03-14 01:27:22 +00:00
|
|
|
connection_pool_size: int = 256
|
2023-02-19 12:40:27 +00:00
|
|
|
read_timeout: Optional[float] = None
|
2022-10-28 07:11:14 +00:00
|
|
|
write_timeout: Optional[float] = None
|
|
|
|
connect_timeout: Optional[float] = None
|
|
|
|
pool_timeout: Optional[float] = None
|
2023-02-19 12:40:27 +00:00
|
|
|
update_read_timeout: Optional[float] = None
|
|
|
|
update_write_timeout: Optional[float] = None
|
|
|
|
update_connect_timeout: Optional[float] = None
|
|
|
|
update_pool_timeout: Optional[float] = None
|
2022-10-28 07:11:14 +00:00
|
|
|
|
|
|
|
genshin_ttl: Optional[int] = None
|
|
|
|
|
|
|
|
enka_network_api_agent: str = ""
|
|
|
|
pass_challenge_api: str = ""
|
|
|
|
pass_challenge_app_key: str = ""
|
2022-10-30 08:46:07 +00:00
|
|
|
pass_challenge_user_web: str = ""
|
2022-09-11 07:08:02 +00:00
|
|
|
|
2023-03-14 01:27:22 +00:00
|
|
|
reload: ReloadConfig = ReloadConfig()
|
2022-10-28 07:11:14 +00:00
|
|
|
mysql: MySqlConfig = MySqlConfig()
|
|
|
|
logger: LoggerConfig = LoggerConfig()
|
|
|
|
webserver: WebServerConfig = WebServerConfig()
|
|
|
|
redis: RedisConfig = RedisConfig()
|
|
|
|
mtproto: MTProtoConfig = MTProtoConfig()
|
|
|
|
error: ErrorConfig = ErrorConfig()
|
2023-01-07 20:01:28 +00:00
|
|
|
notice: NoticeConfig = NoticeConfig()
|
2022-10-12 13:39:47 +00:00
|
|
|
|
|
|
|
|
2023-03-14 01:27:22 +00:00
|
|
|
ApplicationConfig.update_forward_refs()
|
|
|
|
config = ApplicationConfig()
|