domovoy_bot/handlers/mutual_aid.py

65 lines
2.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
ВЗАИМОВЫРУЧКА ЛКМ37
Локальный шеринг и помощь соседям.
"""
from aiogram import Router, F
from aiogram.types import Message, CallbackQuery, InlineKeyboardButton
from aiogram.utils.keyboard import InlineKeyboardBuilder
from aiogram.filters import Command
from aiogram.fsm.state import State, StatesGroup
from aiogram.fsm.context import FSMContext
from utils.ui_styles import fmt_msg
import config
router = Router()
class HelpState(StatesGroup):
waiting_for_text = State()
@router.callback_query(F.data == "mutual_aid")
async def start_help(callback: CallbackQuery):
kb = InlineKeyboardBuilder()
kb.row(InlineKeyboardButton(text="🆘 МНЕ НУЖНА ПОМОЩЬ", callback_data="need_help"))
kb.row(InlineKeyboardButton(text="🤝 Я МОГУ ПОМОЧЬ", callback_data="can_help"))
text = (
f"{fmt_msg('ВЗАИМОВЫРУЧКА ЛКМ37', 'resident')}\n\n"
"Соседи — это сила! Здесь вы можете попросить о помощи или предложить свою.\n"
"<i>Например: одолжить дрель, соль, помочь с тяжелыми сумками.</i>"
)
await callback.message.answer(text, reply_markup=kb.as_markup())
await callback.answer()
@router.callback_query(F.data == "need_help")
async def need_help_start(callback: CallbackQuery, state: FSMContext):
await callback.message.answer("Опишите коротко, что вам нужно:\n<i>Например: 'Нужна дрель на 10 минут'</i>")
await state.set_state(HelpState.waiting_for_text)
await callback.answer()
@router.message(HelpState.waiting_for_text)
async def process_help_request(message: Message, state: FSMContext):
help_text = message.text
user_id = message.from_user.id
# Публикуем в общий чат
alert_text = (
f"🆘 <b>НУЖНА ПОМОЩЬ СОСЕДЕЙ!</b>\n\n"
f"👤 Субъект: ID{user_id}\n"
f"💬 Запрос: <i>{help_text}</i>\n\n"
f"Если можете помочь, напишите соседу в личку!"
)
try:
await message.bot.send_message(
chat_id=config.ADMIN_CHAT_ID,
text=alert_text,
parse_mode='HTML',
reply_markup=InlineKeyboardBuilder().row(
InlineKeyboardButton(text="🤝 Помочь", url=f"tg://user?id={user_id}")
).as_markup()
)
await message.answer(f"{fmt_msg('Запрос отправлен в чат дома!', 'system')}")
except Exception as e:
await message.answer("❌ Ошибка при отправке. Попробуйте позже.")
await state.clear()