Подключено хранилище Redis, внесены мелкие правки
Этот коммит содержится в:
родитель
a763de4335
Коммит
3daf73136c
24
bot/main.py
24
bot/main.py
@ -1,24 +1,32 @@
|
|||||||
import asyncio
|
|
||||||
|
|
||||||
from aiogram import Bot, Dispatcher
|
from aiogram import Bot, Dispatcher
|
||||||
from aiogram.client.default import DefaultBotProperties
|
from aiogram.client.default import DefaultBotProperties
|
||||||
from aiogram.enums import ParseMode
|
from aiogram.enums import ParseMode
|
||||||
from aiogram.filters import CommandStart
|
from aiogram.filters import CommandStart
|
||||||
from aiogram.types import Message, Poll, InputPollOption
|
from aiogram.types import Message, Poll, InputPollOption
|
||||||
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||||
|
from redis import Redis
|
||||||
|
|
||||||
import config
|
import config
|
||||||
|
|
||||||
|
|
||||||
dp = Dispatcher()
|
dp = Dispatcher()
|
||||||
loop = asyncio.get_event_loop()
|
|
||||||
|
|
||||||
|
|
||||||
@dp.message(CommandStart())
|
@dp.message(CommandStart())
|
||||||
async def command_start_handler(
|
async def command_start_handler(
|
||||||
message: Message,
|
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('Чат успешно зарегистрирован!')
|
await message.answer('Чат успешно зарегистрирован!')
|
||||||
|
|
||||||
|
|
||||||
@ -33,7 +41,7 @@ scheduler = AsyncIOScheduler()
|
|||||||
|
|
||||||
|
|
||||||
async def send_mood_poll() -> Poll:
|
async def send_mood_poll() -> Poll:
|
||||||
await bot.send_poll(
|
message = await bot.send_poll(
|
||||||
chat_id=-1002246469549,
|
chat_id=-1002246469549,
|
||||||
question='Оцените свое состояние на текущую минуту',
|
question='Оцените свое состояние на текущую минуту',
|
||||||
options=[
|
options=[
|
||||||
@ -67,6 +75,7 @@ async def send_mood_poll() -> Poll:
|
|||||||
is_closed=False,
|
is_closed=False,
|
||||||
disable_notification=True,
|
disable_notification=True,
|
||||||
)
|
)
|
||||||
|
return message.poll
|
||||||
|
|
||||||
|
|
||||||
async def send_dinner_poll() -> Poll:
|
async def send_dinner_poll() -> Poll:
|
||||||
@ -96,7 +105,7 @@ async def send_dinner_poll() -> Poll:
|
|||||||
|
|
||||||
|
|
||||||
async def send_dinner_delivery_poll() -> Poll:
|
async def send_dinner_delivery_poll() -> Poll:
|
||||||
await bot.send_poll(
|
message = await bot.send_poll(
|
||||||
chat_id=-1002246469549,
|
chat_id=-1002246469549,
|
||||||
question='Где будем заказывать?',
|
question='Где будем заказывать?',
|
||||||
options=[
|
options=[
|
||||||
@ -118,6 +127,7 @@ async def send_dinner_delivery_poll() -> Poll:
|
|||||||
is_closed=False,
|
is_closed=False,
|
||||||
disable_notification=True,
|
disable_notification=True,
|
||||||
)
|
)
|
||||||
|
return message.poll
|
||||||
|
|
||||||
|
|
||||||
async def on_startup(
|
async def on_startup(
|
||||||
@ -128,7 +138,7 @@ async def on_startup(
|
|||||||
trigger='cron',
|
trigger='cron',
|
||||||
day_of_week='mon-fri',
|
day_of_week='mon-fri',
|
||||||
hour=17,
|
hour=17,
|
||||||
minute=14,
|
minute=32,
|
||||||
)
|
)
|
||||||
scheduler.add_job(
|
scheduler.add_job(
|
||||||
func=send_dinner_poll,
|
func=send_dinner_poll,
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
aiogram
|
aiogram
|
||||||
APScheduler
|
APScheduler
|
||||||
psycopg[binary]
|
psycopg[binary]
|
||||||
|
redis
|
||||||
|
Загрузка…
Ссылка в новой задаче
Block a user