Feat: minimal configuration
This commit is contained in:
@@ -0,0 +1 @@
|
||||
from nwxraybot.config import Settings
|
||||
|
||||
0
nwxraybot/bot.py
Normal file
0
nwxraybot/bot.py
Normal file
@@ -3,4 +3,19 @@ from pydantic_settings import BaseSettings
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
bot_token: SecretStr = Field(..., env="BOT_TOKEN")
|
||||
bot_token: SecretStr = Field('token', env="BOT_TOKEN")
|
||||
debug: bool = Field(False, env="DEBUG")
|
||||
postgres_user: str = Field('user', env="POSTGRES_USER")
|
||||
postgres_password: SecretStr = Field('password', env="POSTGRES_PASSWORD")
|
||||
postgres_db: str = Field('db', env="POSTGRES_DB")
|
||||
postgres_host: str = Field('localhost', env="POSTGRES_HOST")
|
||||
postgres_port: int = Field(15432, env="POSTGRES_PORT")
|
||||
|
||||
@property
|
||||
def postgres_url(self) -> str:
|
||||
return f"postgresql://{self.postgres_user}:{
|
||||
self.postgres_password.get_secret_value()}@{self.postgres_host}:{self.postgres_port}/{self.postgres_db}"
|
||||
|
||||
class Config:
|
||||
env_file = ".env"
|
||||
env_file_encoding = "utf-8"
|
||||
|
||||
1
nwxraybot/handlers/__init__.py
Normal file
1
nwxraybot/handlers/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from nwxraybot.handlers.hello import HelloHandler
|
||||
13
nwxraybot/handlers/hello.py
Normal file
13
nwxraybot/handlers/hello.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from aiogram import types
|
||||
from aiogram.filters import Command
|
||||
|
||||
from nwxraybot.meta import Handler
|
||||
|
||||
|
||||
class HelloHandler(Handler):
|
||||
def __init__(self, bot) -> None:
|
||||
super().__init__(bot)
|
||||
|
||||
@self.router.message(Command("start"))
|
||||
async def hello(message: types.Message):
|
||||
await message.reply("Приветствуем в боте NwXray! Здесь вы сможете получить информацию о своем подключении к NwXray")
|
||||
1
nwxraybot/meta/__init__.py
Normal file
1
nwxraybot/meta/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from nwxraybot.meta.router import Handler
|
||||
14
nwxraybot/meta/router.py
Normal file
14
nwxraybot/meta/router.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from aiogram import Bot, Router
|
||||
|
||||
|
||||
class Handler:
|
||||
bot: Bot
|
||||
router: Router
|
||||
|
||||
def __init__(self, bot: Bot) -> None:
|
||||
assert isinstance(bot, Bot)
|
||||
self.bot = bot
|
||||
self.router = Router()
|
||||
|
||||
def __call__(self) -> Router:
|
||||
return self.router
|
||||
Reference in New Issue
Block a user