-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
41 lines (32 loc) · 1.12 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
import asyncio
from aiogram import Bot, Dispatcher
from aiogram.fsm.storage.redis import RedisStorage
from middlewares import throttling
from handlers import base, administrative, content_filters
from handlers.callbacks import callback_settings, callback_toggles
from utils.commands import set_commands
from models import database
from config import CONFIG
storage = RedisStorage.from_url(CONFIG.redis_url)
db = database.Database(mongodb_url=CONFIG.mongodb.get_secret_value())
bot = Bot(token=CONFIG.bot_token.get_secret_value())
# Bot startup function
async def main():
dp = Dispatcher()
# Setup routers
dp.include_routers(
base.router,
callback_settings.router,
callback_toggles.router,
administrative.router,
content_filters.router,
)
# Setup middlewares
dp.message.middleware.register(throttling.ThrottlingMiddleware(storage=storage))
dp.message.middleware.register(throttling.AntiFloodMiddleware(storage=storage))
# set commands
await set_commands(bot)
# start the Bot
await dp.start_polling(bot)
if __name__ == "__main__":
asyncio.run(main())