mirror of
https://github.com/koloideal/Quizzi.git
synced 2026-06-10 18:35:28 +03:00
Initial commit
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
[bot]
|
[bot]
|
||||||
token = "1234567890:ABCdefGHIjklMNOpqrsTUVwxyz"
|
token = "1234567890:ABCdefGHIjklMNOpqrsTUVwxyz"
|
||||||
|
creator_id = 123456789
|
||||||
|
|
||||||
[database]
|
[database]
|
||||||
host = "localhost"
|
host = "localhost"
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ set windows-shell := ["powershell.exe", "-NoLogo", "-Command"]
|
|||||||
set shell := ["bash", "-c"]
|
set shell := ["bash", "-c"]
|
||||||
|
|
||||||
dev:
|
dev:
|
||||||
watchfiles --filter python "python -m trudex.application" src
|
watchfiles --filter python ".venv/Scripts/python -m trudex.application" src
|
||||||
|
|
||||||
run:
|
run:
|
||||||
python -m trudex
|
python -m trudex
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
import asyncio
|
|
||||||
import logging
|
|
||||||
|
|
||||||
from aiogram import Bot, Dispatcher
|
|
||||||
|
|
||||||
from trudex.infrastructure.utils.config import Config
|
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
|
||||||
logging.basicConfig(level=logging.INFO)
|
|
||||||
|
|
||||||
config = Config.from_toml("config.toml")
|
|
||||||
|
|
||||||
logging.info("Бот запущен")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
asyncio.run(main())
|
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
import asyncio
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from aiogram import Bot, Dispatcher
|
||||||
|
from aiogram.client.default import DefaultBotProperties
|
||||||
|
from aiogram.enums import ParseMode
|
||||||
|
from dishka import make_async_container
|
||||||
|
from dishka.integrations.aiogram import setup_dishka
|
||||||
|
|
||||||
|
from trudex.application.bot.handlers import router
|
||||||
|
from trudex.infrastructure.di import DatabaseProvider
|
||||||
|
from trudex.infrastructure.utils.config import Config
|
||||||
|
|
||||||
|
|
||||||
|
async def main() -> None:
|
||||||
|
logging.basicConfig(
|
||||||
|
level=logging.INFO,
|
||||||
|
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|
||||||
|
)
|
||||||
|
|
||||||
|
config = Config.from_toml("config.toml")
|
||||||
|
|
||||||
|
bot = Bot(
|
||||||
|
token=config.bot.token,
|
||||||
|
default=DefaultBotProperties(parse_mode=ParseMode.HTML)
|
||||||
|
)
|
||||||
|
|
||||||
|
dp = Dispatcher()
|
||||||
|
dp.include_router(router)
|
||||||
|
|
||||||
|
container = make_async_container(DatabaseProvider())
|
||||||
|
setup_dishka(container, dp)
|
||||||
|
|
||||||
|
logging.info("Бот запущен")
|
||||||
|
|
||||||
|
try:
|
||||||
|
await dp.start_polling(bot)
|
||||||
|
finally:
|
||||||
|
await bot.session.close()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(main())
|
||||||
@@ -1,3 +1,9 @@
|
|||||||
from aiogram import Router
|
from aiogram import Router
|
||||||
|
from aiogram.filters import CommandStart
|
||||||
|
from aiogram.types import Message
|
||||||
|
|
||||||
router = Router()
|
router = Router()
|
||||||
|
|
||||||
|
@router.message(CommandStart())
|
||||||
|
async def start_handler(message: Message) -> None:
|
||||||
|
await message.answer("Привет! Я бот для тестирования по охране труда.")
|
||||||
|
|||||||
@@ -14,6 +14,10 @@ from trudex.infrastructure.utils.config import Config
|
|||||||
|
|
||||||
|
|
||||||
class DatabaseProvider(Provider):
|
class DatabaseProvider(Provider):
|
||||||
|
@provide(scope=Scope.APP)
|
||||||
|
def get_config(self) -> Config:
|
||||||
|
return Config.from_toml("config.toml")
|
||||||
|
|
||||||
@provide(scope=Scope.APP)
|
@provide(scope=Scope.APP)
|
||||||
def get_session_maker(self, config: Config) -> async_sessionmaker[AsyncSession]:
|
def get_session_maker(self, config: Config) -> async_sessionmaker[AsyncSession]:
|
||||||
return new_session_maker(config.database.url)
|
return new_session_maker(config.database.url)
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ from typing import Self
|
|||||||
@dataclass
|
@dataclass
|
||||||
class BotConfig:
|
class BotConfig:
|
||||||
token: str
|
token: str
|
||||||
|
creator_id: int
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@@ -30,20 +31,21 @@ class Config:
|
|||||||
@classmethod
|
@classmethod
|
||||||
def from_toml(cls, path: str | Path) -> Self:
|
def from_toml(cls, path: str | Path) -> Self:
|
||||||
with open(path, "rb") as f:
|
with open(path, "rb") as f:
|
||||||
data: dict[str, dict[str, str]] = tomllib.load(f)
|
data: dict[str, dict[str, str | int]] = tomllib.load(f)
|
||||||
|
|
||||||
bot_data: dict[str, str] = data["bot"]
|
bot_data: dict[str, str | int] = data["bot"]
|
||||||
db_data: dict[str, str] = data["database"]
|
db_data: dict[str, str | int] = data["database"]
|
||||||
|
|
||||||
return cls(
|
return cls(
|
||||||
bot=BotConfig(
|
bot=BotConfig(
|
||||||
token=bot_data["token"]
|
token=str(bot_data["token"]),
|
||||||
|
creator_id=int(bot_data["creator_id"])
|
||||||
),
|
),
|
||||||
database=DatabaseConfig(
|
database=DatabaseConfig(
|
||||||
host=db_data["host"],
|
host=str(db_data["host"]),
|
||||||
port=db_data["port"],
|
port=db_data["port"],
|
||||||
user=db_data["user"],
|
user=str(db_data["user"]),
|
||||||
password=db_data["password"],
|
password=str(db_data["password"]),
|
||||||
database=db_data["database"]
|
database=str(db_data["database"])
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user