-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
56 lines (42 loc) · 1.5 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import asyncio
import logging
import os
import sys
from aiogram import Bot, Dispatcher
from aiogram.client.default import DefaultBotProperties
from aiogram.enums import ParseMode
from aiogram.fsm.storage.memory import MemoryStorage
from aiogram.types import BotCommand
from app import database as db
from router import r
logging.basicConfig(
format="%(levelname)s (%(asctime)s): %(message)s (Line: %(lineno)d [%(filename)s])", datefmt="%d/%m/%Y %I:%M:%S %p",
level=logging.INFO,
filename="bot_logs.log",
filemode="w",
)
logging.getLogger().addHandler(logging.StreamHandler(sys.stdout))
bot = Bot(token=os.getenv("BOT_TOKEN"), default=DefaultBotProperties(parse_mode=ParseMode.HTML))
dp = Dispatcher(storage=MemoryStorage())
dp.include_router(r)
"""async def on_startup() -> None:
await db.db_start()
logging.info("Database started")"""
async def on_shutdown() -> None:
await bot.session.close()
#await script.bot.session.close()
logging.info("Bot session closed")
async def set_bot_commands() -> None:
commands = [
BotCommand(command="start", description="Start creating your DnD character's form"),
]
await bot.set_my_commands(commands)
async def main() -> None:
#dp.startup.register(on_startup)
await set_bot_commands()
await dp.start_polling(bot, on_shutdown=on_shutdown)
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO, stream=sys.stdout)
logging.info("Bot launched")
asyncio.run(main())
logging.info("Bot shut down")