import asyncio from aiogram import Bot, Dispatcher from aiogram.client.default import DefaultBotProperties from aiogram.enums import ParseMode from aiogram.filters import CommandStart from aiogram.types import Message, Poll, PollAnswer, InputPollOption from apscheduler.schedulers.asyncio import AsyncIOScheduler import config dp = Dispatcher() @dp.message(CommandStart()) async def command_start_handler( message: Message, ): config.Dynamic.set('chat_id', message.chat.id) await message.answer('Чат успешно зарегистрирован!') bot = Bot( token=config.Telegram.token, default=DefaultBotProperties( parse_mode=ParseMode.HTML, ), ) scheduler = AsyncIOScheduler() async def send_mood_poll() -> Poll: message = await bot.send_poll( chat_id=config.Dynamic.get('chat_id'), question='Оцените свое состояние на текущую минуту', options=[ InputPollOption( text='😄', ), InputPollOption( text='🤪', ), InputPollOption( text='🫠', ), InputPollOption( text='☠️', ), InputPollOption( text='🤡', ), InputPollOption( text='😟', ), InputPollOption( text='😩', ), InputPollOption( text='😡', ), ], is_anonymous=False, allows_multiple_answers=False, is_closed=False, disable_notification=True, ) return message.poll async def send_lunch_poll(): message = await bot.send_poll( chat_id=config.Dynamic.get('chat_id'), question='Какие у вас планы на обед?', options=[ InputPollOption( text='🍽️ Пойду в общепит', ), InputPollOption( text='📦 Хочу заказать в офис', ), InputPollOption( text='🥪 Всё своё ношу с собой', ), InputPollOption( text='😴 Хочу спать', ), ], is_anonymous=False, allows_multiple_answers=False, is_closed=False, disable_notification=True, ) config.Dynamic.set('lunch_poll', message.poll.id) @dp.poll_answer() async def get_lunch_poll_result( poll_answer: PollAnswer, ): if poll_answer.poll_id == config.Dynamic.get('lunch_poll'): await bot.send_message( chat_id=config.Dynamic.get('chat_id'), text='%s, %s' % (poll_answer.user.first_name, poll_answer.option_ids), ) async def send_lunch_delivery_poll() -> Poll: message = await bot.send_poll( chat_id=config.Dynamic.get('chat_id'), question='Где будем заказывать?', options=[ InputPollOption( text='Dark Side', ), InputPollOption( text='Самокат', ), InputPollOption( text='...', ), InputPollOption( text='...', ), ], is_anonymous=False, allows_multiple_answers=False, is_closed=False, disable_notification=True, ) return message.poll async def on_startup( dispatcher: Dispatcher, ): scheduler.add_job( func=send_mood_poll, trigger='cron', day_of_week='mon-fri', hour=22, minute=35, ) scheduler.add_job( func=send_lunch_poll, trigger='cron', day_of_week='mon-fri', hour=23, minute=55, ) # scheduler.add_job( # func=get_lunch_poll_result, # trigger='cron', # day_of_week='mon-fri', # hour=23, # minute=19, # ) scheduler.start() dp.startup.register(on_startup)