mirror of
https://github.com/ijaric/voice_assistant.git
synced 2025-12-19 01:36:18 +00:00
feat: [#49] tg_bot
This commit is contained in:
7
src/bot_aiogram/tgbot/split_settings/__init__.py
Normal file
7
src/bot_aiogram/tgbot/split_settings/__init__.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from .api import *
|
||||
from .tgbot import *
|
||||
|
||||
__all__ = [
|
||||
"ApiSettings",
|
||||
"TgBotSettings",
|
||||
]
|
||||
20
src/bot_aiogram/tgbot/split_settings/api.py
Normal file
20
src/bot_aiogram/tgbot/split_settings/api.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import pydantic_settings
|
||||
|
||||
import tgbot.split_settings.utils as split_settings_utils
|
||||
|
||||
|
||||
class ApiSettings(pydantic_settings.BaseSettings):
|
||||
model_config = pydantic_settings.SettingsConfigDict(
|
||||
env_file=split_settings_utils.ENV_PATH,
|
||||
env_prefix="API_",
|
||||
env_file_encoding="utf-8",
|
||||
extra="ignore",
|
||||
)
|
||||
|
||||
url: str
|
||||
port: int
|
||||
protocol: str
|
||||
|
||||
@property
|
||||
def api_url(self) -> str:
|
||||
return f"{self.protocol}://{self.url}:{self.port}"
|
||||
22
src/bot_aiogram/tgbot/split_settings/tgbot.py
Normal file
22
src/bot_aiogram/tgbot/split_settings/tgbot.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import pydantic
|
||||
import pydantic_settings
|
||||
|
||||
import tgbot.split_settings.utils as split_settings_utils
|
||||
|
||||
|
||||
class TgBotSettings(pydantic_settings.BaseSettings):
|
||||
model_config = pydantic_settings.SettingsConfigDict(
|
||||
env_file=split_settings_utils.ENV_PATH,
|
||||
env_prefix="BOT_",
|
||||
env_file_encoding="utf-8",
|
||||
extra="ignore",
|
||||
)
|
||||
|
||||
token: pydantic.SecretStr = pydantic.Field(
|
||||
default=..., validation_alias=pydantic.AliasChoices("token", "bot_token")
|
||||
)
|
||||
admins: str = pydantic.Field(default="")
|
||||
|
||||
@pydantic.field_validator("admins")
|
||||
def validate_bot_admins(cls, v: str) -> list[int]:
|
||||
return list(map(int, v.split(",")))
|
||||
4
src/bot_aiogram/tgbot/split_settings/utils.py
Normal file
4
src/bot_aiogram/tgbot/split_settings/utils.py
Normal file
@@ -0,0 +1,4 @@
|
||||
import pathlib
|
||||
|
||||
BASE_PATH = pathlib.Path(__file__).parent.parent.parent.resolve()
|
||||
ENV_PATH = BASE_PATH / ".env"
|
||||
Reference in New Issue
Block a user