It's version 0.4
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
def register(dp, state, bot):
|
||||
from . import handlers
|
||||
|
||||
handlers.register_handlers(dp, state, bot)
|
||||
|
||||
|
||||
def unregister(dp):
|
||||
# Здесь можно удалить хендлеры, если нужно
|
||||
dp.message_handlers.handlers.clear()
|
||||
|
||||
+23
-30
@@ -1,6 +1,4 @@
|
||||
from config import Config
|
||||
import aiohttp
|
||||
from aiogram.types import BufferedInputFile
|
||||
from utils.antispam import admin_required
|
||||
from aiogram import Dispatcher, Bot
|
||||
from aiogram.types import Message
|
||||
@@ -11,22 +9,7 @@ from aiogram.types import PollAnswer
|
||||
from storage.message_storage import save_message
|
||||
|
||||
logger = getLogger(__name__)
|
||||
API_URL = "http://127.0.0.1:7700/speak"
|
||||
|
||||
from config import Config
|
||||
import aiohttp
|
||||
from aiogram.types import BufferedInputFile
|
||||
from utils.antispam import admin_required
|
||||
from aiogram import Dispatcher, Bot
|
||||
from aiogram.types import Message
|
||||
from models.state import BotState
|
||||
from aiogram.filters import Command
|
||||
from logging import getLogger
|
||||
from aiogram.types import PollAnswer
|
||||
from storage.message_storage import save_message
|
||||
|
||||
logger = getLogger(__name__)
|
||||
API_URL = "http://127.0.0.1:7700/speak"
|
||||
|
||||
def register_handlers(dp: Dispatcher, state: BotState, bot: Bot):
|
||||
@dp.message(Command("poll"))
|
||||
@@ -37,9 +20,12 @@ def register_handlers(dp: Dispatcher, state: BotState, bot: Bot):
|
||||
poll_msg = await bot.send_poll(
|
||||
chat_id=chat_id,
|
||||
question="Кто опоздает?",
|
||||
options=["Я", "Не знаю", "Наверное"],
|
||||
options=["Я", "Я очень сильно опоздаю", "Наверное"],
|
||||
is_anonymous=False,
|
||||
allows_multiple_answers=False
|
||||
allows_multiple_answers=False,
|
||||
)
|
||||
await bot.pin_chat_message(
|
||||
chat_id, poll_msg.message_id, disable_notification=False
|
||||
)
|
||||
# сохраняем сам опрос
|
||||
save_message(poll_msg.chat.id, poll_msg.message_id)
|
||||
@@ -48,9 +34,6 @@ def register_handlers(dp: Dispatcher, state: BotState, bot: Bot):
|
||||
except Exception as e:
|
||||
logger.error(f"Ошибка при отправке в чат {chat_id}: {e}")
|
||||
|
||||
confirm_msg = await message.answer("✅ Сообщение отправлено.")
|
||||
save_message(confirm_msg.chat.id, confirm_msg.message_id)
|
||||
|
||||
@dp.poll_answer()
|
||||
async def handle_poll_answer(poll_answer: PollAnswer):
|
||||
user = poll_answer.user
|
||||
@@ -60,20 +43,30 @@ def register_handlers(dp: Dispatcher, state: BotState, bot: Bot):
|
||||
username = f"@{user.username}" if user.username else user.first_name
|
||||
|
||||
# всегда пишем в первый чат из Config.CHAT_IDS
|
||||
# 6394047531
|
||||
|
||||
if option_ids and option_ids[0] == 0:
|
||||
msg = await bot.send_message(
|
||||
chat_id=6394047531,
|
||||
text=f"{username} опоздает"
|
||||
chat_id=6394047531, text=f"{username} опоздает"
|
||||
)
|
||||
save_message(msg.chat.id, msg.message_id)
|
||||
elif option_ids and option_ids[0] == 1:
|
||||
msg = await bot.send_message(
|
||||
chat_id=6394047531, text=f"{username} сильно опоздает"
|
||||
)
|
||||
save_message(msg.chat.id, msg.message_id)
|
||||
elif option_ids and option_ids[0] == 2:
|
||||
msg = await bot.send_message(
|
||||
chat_id=6394047531, text=f"{username} возможно опоздает"
|
||||
)
|
||||
save_message(msg.chat.id, msg.message_id)
|
||||
elif not option_ids:
|
||||
msg = await bot.send_message(
|
||||
chat_id=6394047531, text=f"{username} Отменил свой голос"
|
||||
)
|
||||
save_message(msg.chat.id, msg.message_id)
|
||||
else:
|
||||
msg = await bot.send_message(
|
||||
chat_id=6394047531,
|
||||
text=f"{username} выбрал вариант {option_ids}"
|
||||
chat_id=6394047531, text=f"{username} выбрал вариант {option_ids}"
|
||||
)
|
||||
save_message(msg.chat.id, msg.message_id)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user