forked from dzhalaevd/Donatello
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
50 lines (41 loc) · 1.34 KB
/
Copy pathapp.py
File metadata and controls
50 lines (41 loc) · 1.34 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
# noinspection PyUnresolvedReferences
import logging
import os
import django
from aiogram import executor
# noinspection PyUnresolvedReferences
import filters
# noinspection PyUnresolvedReferences
from django_project.telegrambot.telegrambot import settings
# noinspection PyUnresolvedReferences
from loader import dp, db, scheduler
from utils.db_api.db_commands import reset_view_limit
from utils.logger import setup_logger
from utils.notify_admins import AdminNotification
from utils.set_bot_commands import set_default_commands
async def on_startup(dispatcher) -> None:
await set_default_commands(dispatcher)
scheduler.add_job(
func=reset_view_limit,
trigger="cron",
hour=0,
id="reset_view_limit",
replace_existing=True
)
await AdminNotification.send(dispatcher)
def setup_django():
os.environ.setdefault(
"DJANGO_SETTINGS_MODULE",
"django_project.telegrambot.telegrambot.settings"
)
os.environ.update({'DJANGO_ALLOW_ASYNC_UNSAFE': "true"})
django.setup()
if __name__ == '__main__':
setup_django()
setup_logger("INFO", ["aiogram.bot.api"])
# noinspection PyUnresolvedReferences
import middlewares
# noinspection PyUnresolvedReferences
import handlers
scheduler.start()
executor.start_polling(dp, on_startup=on_startup, skip_updates=True)