-
Notifications
You must be signed in to change notification settings - Fork 29
/
app.py
66 lines (54 loc) · 1.36 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
56
57
58
59
60
61
62
63
64
65
66
# 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,
)
from loader import (
dp,
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)