MibooGram/core/config.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

141 lines
3.2 KiB
Python
Raw Normal View History

from enum import Enum
from pathlib import Path
from typing import (
List,
Optional,
Union,
)
import dotenv
from pydantic import AnyUrl, BaseModel, Field
from utils.const import PROJECT_ROOT
2022-10-28 07:11:14 +00:00
from utils.models.base import Settings
from utils.typedefs import NaturalNumber
__all__ = ["BotConfig", "config", "JoinGroups"]
2022-10-13 13:01:45 +00:00
dotenv.load_dotenv()
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"
ALLOW_ALL = "ALLOW_ALL"
class ConfigChannel(BaseModel):
name: str
chat_id: int
class ConfigUser(BaseModel):
username: Optional[str]
user_id: int
2022-10-28 07:11:14 +00:00
class MySqlConfig(Settings):
host: str = "127.0.0.1"
port: int = 3306
2022-11-04 10:07:11 +00:00
username: str = None
password: str = None
database: str = None
2022-10-28 07:11:14 +00:00
class Config(Settings.Config):
env_prefix = "db_"
2022-10-28 07:11:14 +00:00
class RedisConfig(Settings):
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-10-28 07:11:14 +00:00
class Config(Settings.Config):
env_prefix = "redis_"
2022-10-28 07:11:14 +00:00
class LoggerConfig(Settings):
2022-10-23 09:15:09 +00:00
name: str = "TGPaimon"
width: int = 180
time_format: str = "[%Y-%m-%d %X]"
traceback_max_frames: int = 20
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
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):
url: AnyUrl = "http://localhost:8080"
host: str = "localhost"
port: int = 8080
class Config(Settings.Config):
env_prefix = "web_"
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_"
class NoticeConfig(Settings):
user_mismatch: str = "再乱点我叫西风骑士团、千岩军、天领奉行、三十人团和风纪官了!"
class Config(Settings.Config):
env_prefix = "notice_"
2022-10-28 07:11:14 +00:00
class BotConfig(Settings):
debug: bool = False
bot_token: str = ""
channels: List["ConfigChannel"] = []
admins: List["ConfigUser"] = []
verify_groups: List[Union[int, str]] = []
join_groups: Optional[JoinGroups] = JoinGroups.NO_ALLOW
timeout: int = 10
read_timeout: float = 2
write_timeout: Optional[float] = None
connect_timeout: Optional[float] = None
pool_timeout: Optional[float] = None
genshin_ttl: Optional[int] = None
enka_network_api_agent: str = ""
pass_challenge_api: str = ""
pass_challenge_app_key: str = ""
pass_challenge_user_web: str = ""
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()
notice: NoticeConfig = NoticeConfig()
BotConfig.update_forward_refs()
config = BotConfig()