This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathapp.py
55 lines (46 loc) · 1.45 KB
/
app.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
from aiogram import executor, types
from loguru import logger
import filters
import middlewares
from data.config import SKIP_UPDATES, WEBHOOK_HOST, WEBAPP_PORT, WEBHOOK, WEBHOOK_PATH
from handlers import register_all_handlers
from loader import db, dp
from utils.notify_admins import on_startup_notify
from utils.set_bot_commands import set_default_commands
async def on_startup(dp):
if WEBHOOK:
await dp.bot.set_webhook(
url=WEBHOOK_HOST + WEBHOOK_PATH,
allowed_updates=types.AllowedUpdates.all()
)
status = await dp.bot.get_webhook_info()
logger.info(f"Webhook status: {status}")
await set_default_commands(dp)
await on_startup_notify(dp)
try:
db.create_table_stickers()
db.create_table_chat_admins()
db.create_table_rating_users()
except Exception as err:
print(err)
logger.info("Бот запущен")
if __name__ == "__main__":
middlewares.setup(dp)
filters.setup(dp)
register_all_handlers(dp)
if WEBHOOK:
executor.start_webhook(
dispatcher=dp,
check_ip=True,
webhook_path=WEBHOOK_PATH,
on_startup=on_startup,
host='0.0.0.0',
port=WEBAPP_PORT,
)
else:
executor.start_polling(
dispatcher=dp,
on_startup=on_startup,
skip_updates=SKIP_UPDATES,
allowed_updates=types.AllowedUpdates.all()
)