better structure

This commit is contained in:
Crystal Melting Dot 2021-02-21 13:14:55 +03:00
parent 723172387b
commit 784cae145d
3 changed files with 13 additions and 5 deletions

View File

@ -10,4 +10,4 @@ RUN apk update \
COPY . .
WORKDIR tgbot
RUN pip install --upgrade pip; pip install poetry; poetry config virtualenvs.create false; poetry install
CMD poetry shell; python bot.py
CMD poetry run tgbot

View File

@ -23,3 +23,6 @@ flake8 = "^3.8.4"
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
[tool.poetry.scripts]
tgbot = "tgbot.bot:main"

View File

@ -1,12 +1,12 @@
from aiogram import Bot, Dispatcher, executor
from aiogram.contrib.fsm_storage.memory import MemoryStorage
from tgbot.middlewares import UserMiddleware, WriteCommandMetric, LoggingMiddleware, ThrottlingMiddleware
from .middlewares import UserMiddleware, WriteCommandMetric, LoggingMiddleware, ThrottlingMiddleware
from tortoise import Tortoise
from tortoise.exceptions import DBConnectionError
from loguru import logger
from asyncio import sleep
import tgbot.config as config
import tgbot.handlers as handlers
from . import config
from . import handlers
storage = MemoryStorage()
telegram_bot = Bot(token=config.TELEGRAM_BOT_TOKEN)
@ -42,5 +42,10 @@ async def on_startup(disp: Dispatcher):
disp.middleware.setup(LoggingMiddleware())
disp.middleware.setup(UserMiddleware())
if __name__ == '__main__':
def main():
executor.start_polling(dp, skip_updates=True, on_startup=on_startup)
if __name__ == '__main__':
main()