handlers.py: проверка статуса модерации при входе и перед отправкой
This commit is contained in:
+43
-1
@@ -109,6 +109,27 @@ async def handle_photo_error(msg: Message, user_id: str, action: str, error_deta
|
|||||||
await msg.answer(photo_error_handling(), parse_mode="html")
|
await msg.answer(photo_error_handling(), parse_mode="html")
|
||||||
|
|
||||||
|
|
||||||
|
async def check_moderation_status(user_id: str) -> dict:
|
||||||
|
"""Проверяет текущий статус модерации пользователя через API"""
|
||||||
|
from photo_bot.photo_processor import API_URL, API_KEY
|
||||||
|
import requests
|
||||||
|
|
||||||
|
status_url = API_URL.replace("/upload/", "/status/")
|
||||||
|
try:
|
||||||
|
response = requests.get(
|
||||||
|
status_url,
|
||||||
|
params={"user_id": user_id},
|
||||||
|
headers={"X-API-Key": API_KEY},
|
||||||
|
timeout=15,
|
||||||
|
verify=False
|
||||||
|
)
|
||||||
|
response.raise_for_status()
|
||||||
|
return response.json()
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Ошибка проверки статуса модерации: {e}")
|
||||||
|
return {"status": "error", "reason": str(e)}
|
||||||
|
|
||||||
|
|
||||||
# =========================================================
|
# =========================================================
|
||||||
# ОСНОВНОЙ ОБРАБОТЧИК
|
# ОСНОВНОЙ ОБРАБОТЧИК
|
||||||
# =========================================================
|
# =========================================================
|
||||||
@@ -149,6 +170,22 @@ async def photo_module_handler(msg: Message):
|
|||||||
await msg.answer(MENU_TEXT, parse_mode="html")
|
await msg.answer(MENU_TEXT, parse_mode="html")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# --- ПЕРВАЯ ПРОВЕРКА: если нет фото в pending_photos, проверяем статус модерации ---
|
||||||
|
if user_id not in pending_photos and not is_attachment:
|
||||||
|
status = await check_moderation_status(user_id)
|
||||||
|
if status.get("status") == "ok" and status.get("moderation_status") == "pending":
|
||||||
|
photo_id = status.get("photo_id", "???")
|
||||||
|
await msg.answer(
|
||||||
|
f"⏳ <b>У вас уже есть фото на модерации (ID: {photo_id}).</b>\n\n"
|
||||||
|
f"Ожидайте решения модератора.\n\n"
|
||||||
|
f"{EMOJI_DIGITS['0']} — В главное меню",
|
||||||
|
parse_mode="html"
|
||||||
|
)
|
||||||
|
return
|
||||||
|
elif status.get("status") != "ok":
|
||||||
|
# Ошибка проверки — не блокируем, просто логируем
|
||||||
|
logger.warning(f"Не удалось проверить статус модерации для {user_id}: {status.get('reason')}")
|
||||||
|
|
||||||
# --- ПОДТВЕРЖДЕНИЕ ОТПРАВКИ (Кнопка 1) ---
|
# --- ПОДТВЕРЖДЕНИЕ ОТПРАВКИ (Кнопка 1) ---
|
||||||
if not is_attachment and user_id in pending_photos:
|
if not is_attachment and user_id in pending_photos:
|
||||||
if cmd == "1":
|
if cmd == "1":
|
||||||
@@ -175,7 +212,12 @@ async def photo_module_handler(msg: Message):
|
|||||||
msg_text = result.get("message", "Фото обработано")
|
msg_text = result.get("message", "Фото обработано")
|
||||||
await msg.answer(f"✅ {msg_text}", parse_mode="html")
|
await msg.answer(f"✅ {msg_text}", parse_mode="html")
|
||||||
else:
|
else:
|
||||||
# Любая ошибка API — системная заглушка
|
error_msg = result.get("error", "Неизвестная ошибка")
|
||||||
|
# Если фото уже на модерации — показываем конкретное сообщение
|
||||||
|
if "уже есть фото на модерации" in error_msg:
|
||||||
|
log_menu_stats(user_id, "Photo Bot", "Попытка повторной загрузки на модерации")
|
||||||
|
await msg.answer(photo_error_already_pending(), parse_mode="html")
|
||||||
|
else:
|
||||||
await msg.answer(photo_error_handling(), parse_mode="html")
|
await msg.answer(photo_error_handling(), parse_mode="html")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
await handle_photo_error(msg, user_id, "Отправка фото через API", str(e))
|
await handle_photo_error(msg, user_id, "Отправка фото через API", str(e))
|
||||||
|
|||||||
Reference in New Issue
Block a user