-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
39 lines (30 loc) · 1.13 KB
/
main.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
from datetime import datetime
from aiogram import Bot
from aiogram.dispatcher import Dispatcher
from aiogram.utils import executor
from aiogram.contrib.fsm_storage.memory import MemoryStorage
from bot_files.handlers import FSM_handlers, general_handlers
from config.env import BOT_TOKEN
bot = Bot(token=BOT_TOKEN)
storage = MemoryStorage()
dp = Dispatcher(bot, storage=storage)
# Registers all the handlers defined in bot_files package.
FSM_handlers.register_FSM_handlers(dp)
general_handlers.register_general_handlers(dp)
async def on_startup(_):
"""Prints to stdout when the bot has started, passing by the logs.
"""
today = str(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
return print(f"Bot started on {today}.")
async def on_shutdown(_):
"""Prints to stdout when the bot has stopped, passing by the logs.
"""
today = str(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
return print(f"Bot stopped on {today}.")
if __name__ == "__main__":
executor.start_polling(
dp,
skip_updates=True,
on_startup=on_startup,
on_shutdown=on_shutdown,
)