-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
67 lines (47 loc) · 1.43 KB
/
main.py
File metadata and controls
67 lines (47 loc) · 1.43 KB
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
60
61
62
63
64
65
66
67
import logging
import asyncio
from aiogram import Bot, Dispatcher
from aiogram.client.default import DefaultBotProperties
from aiogram.enums import ParseMode
from aiogram.fsm.storage.redis import RedisStorage, Redis
from config.config import Config, load_config
from handlers.user import user_router
from handlers.admin import admin_router
from keyboards.main_menu import set_main_menu
from db.models import create_tables
# Logger initialization
logger = logging.getLogger(__name__)
async def main() -> None:
# Config Logger
logging.basicConfig(
level=logging.DEBUG,
format='%(filename)s:%(lineno)d #%(levelname)-8s [%(asctime)s] - %(name)s - %(message)s'
)
logger.info('Starting Bot')
# Create db sheets
await create_tables()
# Load config
config: Config = load_config(".env")
# Redis Storage
redis = Redis(host="localhost")
storage = RedisStorage(redis=redis)
# Bot and Dispatcher initialization
bot = Bot(
token=config.tg_bot.token,
default=DefaultBotProperties(parse_mode=ParseMode.HTML)
)
dp = Dispatcher(storage=storage)
# Admins list
admin_ids = config.tg_bot.admin_ids
dp.workflow_data.update({'admin_ids': admin_ids})
# Setting main menu
await set_main_menu(bot)
# Register Routers
dp.include_router(admin_router)
dp.include_router(user_router)
# Start polling
await bot.delete_webhook(drop_pending_updates=True)
await dp.start_polling(bot)
# Running main
if __name__ == "__main__":
asyncio.run(main())