-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
59 lines (42 loc) · 1.47 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!venv/bin/python
import asyncio
import logging
from aiogram import Bot, Dispatcher, types
from aiogram.contrib.fsm_storage.memory import MemoryStorage
from aiogram_dialog import DialogRegistry
from app.config import API_TOKEN
from app.handlers.common import register_common
from app.handlers.poster_creation import register_poster_creation
from app import dialogs
from app.utils.queue_manager import QueueManager
def register_handlers(dp: Dispatcher):
register_common(dp)
register_poster_creation(dp)
def register_dialogs(registry: DialogRegistry):
registry.register(dialogs.poster_creation.dialog)
async def main():
logger = logging.getLogger("main")
logging.basicConfig(level=logging.ERROR)
ch = logging.StreamHandler()
ch.setLevel(logging.INFO)
fh = logging.FileHandler("mapoc-bot-app.log")
fh.setLevel(logging.DEBUG)
formatter = logging.Formatter('[%(asctime)s] [%(levelname)s] %(name)s: %(message)s')
fh.setFormatter(formatter)
ch.setFormatter(formatter)
logger.addHandler(ch)
logger.addHandler(fh)
logger.info("Starting mapoc-bot")
storage = MemoryStorage()
bot = Bot(token=API_TOKEN, parse_mode=types.ParseMode.HTML)
dp = Dispatcher(bot, storage=storage)
registry = DialogRegistry(dp)
register_handlers(dp)
register_dialogs(registry)
q_manager = QueueManager()
try:
await dp.start_polling()
finally:
await bot.close()
if __name__ == "__main__":
asyncio.run(main())