From 3daf73136cb340f828f851715af61d360fdfb240 Mon Sep 17 00:00:00 2001 From: csasq Date: Mon, 12 Aug 2024 17:55:07 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=B4=D0=BA=D0=BB=D1=8E=D1=87?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=D1=85=D1=80=D0=B0=D0=BD=D0=B8=D0=BB=D0=B8?= =?UTF-8?q?=D1=89=D0=B5=20Redis,=20=D0=B2=D0=BD=D0=B5=D1=81=D0=B5=D0=BD?= =?UTF-8?q?=D1=8B=20=D0=BC=D0=B5=D0=BB=D0=BA=D0=B8=D0=B5=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot/main.py | 24 +++++++++++++++++------- requirements.txt | 1 + 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/bot/main.py b/bot/main.py index e798908..ad09da5 100644 --- a/bot/main.py +++ b/bot/main.py @@ -1,24 +1,32 @@ -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, InputPollOption from apscheduler.schedulers.asyncio import AsyncIOScheduler +from redis import Redis import config dp = Dispatcher() -loop = asyncio.get_event_loop() @dp.message(CommandStart()) async def command_start_handler( message: Message, ): - print(message.chat.id) + with Redis( + db=3, + ) as redis: + redis.set( + name='chat_id', + value=message.chat.id, + ) + chat_id = redis.get( + name='chat_id', + ) + assert int(chat_id) == message.chat.id await message.answer('Чат успешно зарегистрирован!') @@ -33,7 +41,7 @@ scheduler = AsyncIOScheduler() async def send_mood_poll() -> Poll: - await bot.send_poll( + message = await bot.send_poll( chat_id=-1002246469549, question='Оцените свое состояние на текущую минуту', options=[ @@ -67,6 +75,7 @@ async def send_mood_poll() -> Poll: is_closed=False, disable_notification=True, ) + return message.poll async def send_dinner_poll() -> Poll: @@ -96,7 +105,7 @@ async def send_dinner_poll() -> Poll: async def send_dinner_delivery_poll() -> Poll: - await bot.send_poll( + message = await bot.send_poll( chat_id=-1002246469549, question='Где будем заказывать?', options=[ @@ -118,6 +127,7 @@ async def send_dinner_delivery_poll() -> Poll: is_closed=False, disable_notification=True, ) + return message.poll async def on_startup( @@ -128,7 +138,7 @@ async def on_startup( trigger='cron', day_of_week='mon-fri', hour=17, - minute=14, + minute=32, ) scheduler.add_job( func=send_dinner_poll, diff --git a/requirements.txt b/requirements.txt index b10bb02..b2ee50f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ aiogram APScheduler psycopg[binary] +redis