2024-08-13 00:00:41 +03:00
|
|
|
import asyncio
|
|
|
|
|
2024-08-12 17:25:30 +03:00
|
|
|
from aiogram import Bot, Dispatcher
|
|
|
|
from aiogram.client.default import DefaultBotProperties
|
|
|
|
from aiogram.enums import ParseMode
|
|
|
|
from aiogram.filters import CommandStart
|
2024-08-13 00:00:41 +03:00
|
|
|
from aiogram.types import Message, Poll, PollAnswer, InputPollOption
|
2024-08-12 17:25:30 +03:00
|
|
|
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
|
|
|
|
|
|
|
import config
|
|
|
|
|
|
|
|
|
|
|
|
dp = Dispatcher()
|
|
|
|
|
|
|
|
|
|
|
|
@dp.message(CommandStart())
|
|
|
|
async def command_start_handler(
|
|
|
|
message: Message,
|
|
|
|
):
|
2024-08-13 00:00:41 +03:00
|
|
|
config.Dynamic.set('chat_id', message.chat.id)
|
2024-08-12 17:25:30 +03:00
|
|
|
await message.answer('Чат успешно зарегистрирован!')
|
|
|
|
|
|
|
|
|
|
|
|
bot = Bot(
|
|
|
|
token=config.Telegram.token,
|
|
|
|
default=DefaultBotProperties(
|
|
|
|
parse_mode=ParseMode.HTML,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
scheduler = AsyncIOScheduler()
|
|
|
|
|
|
|
|
|
|
|
|
async def send_mood_poll() -> Poll:
|
2024-08-12 17:55:07 +03:00
|
|
|
message = await bot.send_poll(
|
2024-08-13 00:00:41 +03:00
|
|
|
chat_id=config.Dynamic.get('chat_id'),
|
2024-08-12 17:25:30 +03:00
|
|
|
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,
|
|
|
|
)
|
2024-08-12 17:55:07 +03:00
|
|
|
return message.poll
|
2024-08-12 17:25:30 +03:00
|
|
|
|
|
|
|
|
2024-08-13 00:00:41 +03:00
|
|
|
async def send_lunch_poll():
|
2024-08-12 17:25:30 +03:00
|
|
|
message = await bot.send_poll(
|
2024-08-13 00:00:41 +03:00
|
|
|
chat_id=config.Dynamic.get('chat_id'),
|
2024-08-12 17:25:30 +03:00
|
|
|
question='Какие у вас планы на обед?',
|
|
|
|
options=[
|
|
|
|
InputPollOption(
|
|
|
|
text='🍽️ Пойду в общепит',
|
|
|
|
),
|
|
|
|
InputPollOption(
|
|
|
|
text='📦 Хочу заказать в офис',
|
|
|
|
),
|
|
|
|
InputPollOption(
|
|
|
|
text='🥪 Всё своё ношу с собой',
|
|
|
|
),
|
|
|
|
InputPollOption(
|
|
|
|
text='😴 Хочу спать',
|
|
|
|
),
|
|
|
|
],
|
|
|
|
is_anonymous=False,
|
|
|
|
allows_multiple_answers=False,
|
|
|
|
is_closed=False,
|
|
|
|
disable_notification=True,
|
|
|
|
)
|
2024-08-13 00:00:41 +03:00
|
|
|
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),
|
|
|
|
)
|
2024-08-12 17:25:30 +03:00
|
|
|
|
|
|
|
|
2024-08-13 00:00:41 +03:00
|
|
|
async def send_lunch_delivery_poll() -> Poll:
|
2024-08-12 17:55:07 +03:00
|
|
|
message = await bot.send_poll(
|
2024-08-13 00:00:41 +03:00
|
|
|
chat_id=config.Dynamic.get('chat_id'),
|
2024-08-12 17:25:30 +03:00
|
|
|
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,
|
|
|
|
)
|
2024-08-12 17:55:07 +03:00
|
|
|
return message.poll
|
2024-08-12 17:25:30 +03:00
|
|
|
|
|
|
|
|
|
|
|
async def on_startup(
|
|
|
|
dispatcher: Dispatcher,
|
|
|
|
):
|
|
|
|
scheduler.add_job(
|
|
|
|
func=send_mood_poll,
|
|
|
|
trigger='cron',
|
|
|
|
day_of_week='mon-fri',
|
2024-08-13 00:00:41 +03:00
|
|
|
hour=22,
|
|
|
|
minute=35,
|
2024-08-12 17:25:30 +03:00
|
|
|
)
|
|
|
|
scheduler.add_job(
|
2024-08-13 00:00:41 +03:00
|
|
|
func=send_lunch_poll,
|
2024-08-12 17:25:30 +03:00
|
|
|
trigger='cron',
|
|
|
|
day_of_week='mon-fri',
|
2024-08-13 00:00:41 +03:00
|
|
|
hour=23,
|
|
|
|
minute=55,
|
2024-08-12 17:25:30 +03:00
|
|
|
)
|
2024-08-13 00:00:41 +03:00
|
|
|
# scheduler.add_job(
|
|
|
|
# func=get_lunch_poll_result,
|
|
|
|
# trigger='cron',
|
|
|
|
# day_of_week='mon-fri',
|
|
|
|
# hour=23,
|
|
|
|
# minute=19,
|
|
|
|
# )
|
2024-08-12 17:25:30 +03:00
|
|
|
scheduler.start()
|
|
|
|
|
|
|
|
|
|
|
|
dp.startup.register(on_startup)
|