-
Notifications
You must be signed in to change notification settings - Fork 0
/
loader.py
58 lines (44 loc) · 1.39 KB
/
loader.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
import os
from contextlib import asynccontextmanager
from aiogram import Bot, Dispatcher
from aiogram.types import Update
from dotenv import load_dotenv
from fastapi import FastAPI
from motor.motor_asyncio import AsyncIOMotorClient
from handlers import (
games,
horo,
lightning,
smart,
weather,
cubic_game_main,
start,
)
from handlers.sovmest import sovmest
from misk.commands import set_bot_commands
load_dotenv()
cluster = AsyncIOMotorClient(
f'mongodb+srv://kerrek8:{str(os.getenv("MDBPASSWORD"))}@aiogrambot.2vjshy0.mongodb.net/''?retryWrites=true&w=majority')
db = cluster.aiogram3bot
bot = Bot(os.getenv("TOKEN"))
webhook_uri = 'https://aio3bot.onrender.com' + '/' + str(os.getenv('TOKEN'))
dp = Dispatcher(db=db, bot=bot)
dp.include_routers(
games.router, horo.router, smart.router, lightning.router, weather.router, sovmest.router,
start.router, cubic_game_main.router
)
async def start():
await set_bot_commands(bot)
@asynccontextmanager
async def lifespan(app: FastAPI):
await start()
print(await bot.set_webhook(url=webhook_uri, allowed_updates=[]), 'webhook was set')
yield
app = FastAPI(docs_url=None, lifespan=lifespan)
@app.post('/' + str(os.getenv("TOKEN")))
async def webhook_response(update: dict):
return await dp.feed_update(bot=bot, update=Update(**update))
@app.head('/')
@app.get('/')
async def alive():
return "Alive"