First commit
This commit is contained in:
29
bot/handlers/form_utils/topic_replies.py
Normal file
29
bot/handlers/form_utils/topic_replies.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from aiogram import Router, F
|
||||
from aiogram.types import Message
|
||||
from bot.data.topic_map import user_topic_map
|
||||
|
||||
router: Router = Router(name="topic_replies")
|
||||
|
||||
@router.message(F.is_topic_message, F.reply_to_message, ~F.from_user.is_bot)
|
||||
async def forward_reply_to_user(message: Message):
|
||||
thread_id = message.message_thread_id
|
||||
if thread_id is None:
|
||||
return # нет thread_id, выходим
|
||||
|
||||
# Найдем user_id по thread_id
|
||||
user_id = None
|
||||
for (uid, kind), tid in user_topic_map.items():
|
||||
if tid == thread_id:
|
||||
user_id = uid
|
||||
break
|
||||
|
||||
if user_id is None:
|
||||
return # Топик не зарегистрирован
|
||||
|
||||
reply_text = f"<b>Ответ администратора:</b>\n{message.html_text}"
|
||||
|
||||
try:
|
||||
await message.bot.send_message(chat_id=user_id, text=reply_text, parse_mode="HTML")
|
||||
except Exception as e:
|
||||
await message.reply(f"⚠️ Не удалось отправить сообщение пользователю: {e}")
|
||||
|
||||
Reference in New Issue
Block a user