-
Notifications
You must be signed in to change notification settings - Fork 0
/
tg_bot.py
63 lines (43 loc) · 1.98 KB
/
tg_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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import asyncio
import logging
from aiogram import Bot, Dispatcher
from aiogram.types import BotCommand
from aiogram.fsm.storage.memory import MemoryStorage
from bot.handlers import cb_start_test, common, add_contact, cb_appointment
# from bot.handlers.apshed import create_activity_days_for_next_week, send_message_cron_middleware
# from apscheduler.schedulers.asyncio import AsyncIOScheduler
from conf import TELEGRAM_TOKEN
logger = logging.getLogger(__name__)
async def set_commands(bot: Bot):
commands = [
BotCommand(command="/start", description="Старт"),
BotCommand(command="/info", description="Описание бота"),
BotCommand(command="/cancel", description="Отменить текущее действие")
]
await bot.set_my_commands(commands)
my_bot = Bot(token=TELEGRAM_TOKEN, parse_mode="HTML")
async def main(bot):
logging.basicConfig(
level=logging.WARNING,
format=u"%(filename)s[LINE:%(lineno)d]# %(asctime)s - %(levelname)s - %(name)s - %(message)s",
)
logger.error("Starting bot")
dp = Dispatcher(storage=MemoryStorage())
# scheduler = AsyncIOScheduler(timezone='Europe/Moscow')
# scheduler.add_job(send_message_cron_middleware, 'cron', hour=10, minute=15, kwargs={'bot': bot})
# scheduler.add_job(create_activity_days_for_next_week, 'cron', day_of_week=6, hour=23, minute=30, kwargs={'bot': bot})
dp.include_router(common.router)
dp.include_router(add_contact.router)
dp.include_router(cb_appointment.router)
# dp.include_router(cb_child.router)
dp.include_router(cb_start_test.router)
# dp.include_router(cb_add_child.router)
await set_commands(bot)
await bot.delete_webhook(drop_pending_updates=True)
# scheduler.start()
await dp.start_polling(bot, allowed_updates=dp.resolve_used_update_types())
if __name__ == '__main__':
try:
asyncio.run(main(bot=my_bot))
except (KeyboardInterrupt, SystemExit):
logger.error('Bot stopped!')