forked from AndreyKhlestov/FeedMe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
43 lines (31 loc) · 1.13 KB
/
bot.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
import asyncio
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from aiogram.types import BotCommand
from tg_bot.loader import dp, bot
from tg_bot.config import super_user_name, super_user_pass, logger
from tg_bot.middlewares.blocking import UserMiddleware
from tg_bot.misc.mailing import start_milling
from tg_bot.db.db_commands import create_super_user
async def set_commands():
commands = [BotCommand(command="/start", description="Запустить бота")]
await bot.set_my_commands(commands=commands)
async def main():
logger.info('Запуск бота')
await create_super_user(super_user_name, super_user_pass)
await set_commands()
dp.message.outer_middleware(UserMiddleware())
dp.callback_query.outer_middleware(UserMiddleware())
scheduler = AsyncIOScheduler()
scheduler.add_job(
start_milling,
'interval',
minutes=1,
kwargs={'bot': bot}
)
scheduler.start() # Запуск планировщика
try:
await dp.start_polling(bot)
finally:
await bot.session.close()
if __name__ == "__main__":
asyncio.run(main())