Предприняты попытки получить результаты опроса
Этот коммит содержится в:
родитель
3daf73136c
Коммит
e5e10e927e
57
bot/main.py
57
bot/main.py
@ -1,10 +1,11 @@
|
|||||||
|
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, PollAnswer, InputPollOption
|
||||||
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||||
from redis import Redis
|
|
||||||
|
|
||||||
import config
|
import config
|
||||||
|
|
||||||
@ -16,17 +17,7 @@ dp = Dispatcher()
|
|||||||
async def command_start_handler(
|
async def command_start_handler(
|
||||||
message: Message,
|
message: Message,
|
||||||
):
|
):
|
||||||
with Redis(
|
config.Dynamic.set('chat_id', message.chat.id)
|
||||||
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('Чат успешно зарегистрирован!')
|
||||||
|
|
||||||
|
|
||||||
@ -42,7 +33,7 @@ scheduler = AsyncIOScheduler()
|
|||||||
|
|
||||||
async def send_mood_poll() -> Poll:
|
async def send_mood_poll() -> Poll:
|
||||||
message = await bot.send_poll(
|
message = await bot.send_poll(
|
||||||
chat_id=-1002246469549,
|
chat_id=config.Dynamic.get('chat_id'),
|
||||||
question='Оцените свое состояние на текущую минуту',
|
question='Оцените свое состояние на текущую минуту',
|
||||||
options=[
|
options=[
|
||||||
InputPollOption(
|
InputPollOption(
|
||||||
@ -78,9 +69,9 @@ async def send_mood_poll() -> Poll:
|
|||||||
return message.poll
|
return message.poll
|
||||||
|
|
||||||
|
|
||||||
async def send_dinner_poll() -> Poll:
|
async def send_lunch_poll():
|
||||||
message = await bot.send_poll(
|
message = await bot.send_poll(
|
||||||
chat_id=-1002246469549,
|
chat_id=config.Dynamic.get('chat_id'),
|
||||||
question='Какие у вас планы на обед?',
|
question='Какие у вас планы на обед?',
|
||||||
options=[
|
options=[
|
||||||
InputPollOption(
|
InputPollOption(
|
||||||
@ -101,12 +92,23 @@ async def send_dinner_poll() -> Poll:
|
|||||||
is_closed=False,
|
is_closed=False,
|
||||||
disable_notification=True,
|
disable_notification=True,
|
||||||
)
|
)
|
||||||
return message.poll
|
config.Dynamic.set('lunch_poll', message.poll.id)
|
||||||
|
|
||||||
|
|
||||||
async def send_dinner_delivery_poll() -> Poll:
|
@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(
|
message = await bot.send_poll(
|
||||||
chat_id=-1002246469549,
|
chat_id=config.Dynamic.get('chat_id'),
|
||||||
question='Где будем заказывать?',
|
question='Где будем заказывать?',
|
||||||
options=[
|
options=[
|
||||||
InputPollOption(
|
InputPollOption(
|
||||||
@ -137,16 +139,23 @@ async def on_startup(
|
|||||||
func=send_mood_poll,
|
func=send_mood_poll,
|
||||||
trigger='cron',
|
trigger='cron',
|
||||||
day_of_week='mon-fri',
|
day_of_week='mon-fri',
|
||||||
hour=17,
|
hour=22,
|
||||||
minute=32,
|
minute=35,
|
||||||
)
|
)
|
||||||
scheduler.add_job(
|
scheduler.add_job(
|
||||||
func=send_dinner_poll,
|
func=send_lunch_poll,
|
||||||
trigger='cron',
|
trigger='cron',
|
||||||
day_of_week='mon-fri',
|
day_of_week='mon-fri',
|
||||||
hour=17,
|
hour=23,
|
||||||
minute=17,
|
minute=55,
|
||||||
)
|
)
|
||||||
|
# scheduler.add_job(
|
||||||
|
# func=get_lunch_poll_result,
|
||||||
|
# trigger='cron',
|
||||||
|
# day_of_week='mon-fri',
|
||||||
|
# hour=23,
|
||||||
|
# minute=19,
|
||||||
|
# )
|
||||||
scheduler.start()
|
scheduler.start()
|
||||||
|
|
||||||
|
|
||||||
|
@ -1 +1 @@
|
|||||||
from .main import Telegram
|
from .main import Telegram, Dynamic
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
from configparser import RawConfigParser
|
from configparser import RawConfigParser
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from redis import Redis
|
||||||
|
|
||||||
|
|
||||||
cwd = os.getcwd()
|
cwd = os.getcwd()
|
||||||
config = RawConfigParser()
|
config = RawConfigParser()
|
||||||
@ -17,3 +19,32 @@ class Telegram:
|
|||||||
section='Telegram',
|
section='Telegram',
|
||||||
option='token',
|
option='token',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class Dynamic:
|
||||||
|
@classmethod
|
||||||
|
def get(
|
||||||
|
cls,
|
||||||
|
key: str,
|
||||||
|
):
|
||||||
|
with Redis(
|
||||||
|
db=3,
|
||||||
|
) as redis:
|
||||||
|
return redis.get(
|
||||||
|
name=key,
|
||||||
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def set(
|
||||||
|
cls,
|
||||||
|
key: str,
|
||||||
|
value,
|
||||||
|
):
|
||||||
|
with Redis(
|
||||||
|
db=3,
|
||||||
|
decode_responses=True,
|
||||||
|
) as redis:
|
||||||
|
redis.set(
|
||||||
|
name=key,
|
||||||
|
value=value,
|
||||||
|
)
|
||||||
|
@ -6,4 +6,4 @@ create table polls (
|
|||||||
);
|
);
|
||||||
|
|
||||||
create table mood_polls () inherits (polls);
|
create table mood_polls () inherits (polls);
|
||||||
create table dinner_polls () inherits (polls);
|
create table lunch_polls () inherits (polls);
|
||||||
|
Загрузка…
Ссылка в новой задаче
Block a user