Упрощение обработчиков для детального просмотра: удаление изображений и улучшение текстовых сообщений

This commit is contained in:
2026-05-01 17:48:26 +03:00
parent ea5c1b55fc
commit 6e6ee8ff40

View File

@@ -1,10 +1,9 @@
"""
Inline handlers for detailed item viewing with images (FIXED VERSION)
Inline handlers for detailed item viewing (NO IMAGES VERSION - STABLE)
"""
from telegram import Update
from telegram.ext import ContextTypes, CommandHandler
from vndb_client import VndbClient
from utils import ImageHandler
from config import Config
import logging
@@ -21,29 +20,31 @@ class DetailedHandlers:
async def view_vn_detail(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
try:
if not context.args:
await update.message.reply_text(
"❌ Укажи ID VN\nПример: /vn_detail v2002"
)
await update.message.reply_text("❌ Пример: /vn_detail v2002")
return
vn_id = context.args[0].strip()
await update.message.reply_text(
f"⏳ Загружаю информацию о {vn_id}..."
)
await update.message.reply_text(f"⏳ Загружаю {vn_id}...")
results = await vndb_client.query_vn(
filters=["id", "=", vn_id],
fields=[
"id", "title", "original", "released",
"rating", "votecount", "description",
"length", "developer", "image{url,dims}"
"id",
"title",
"original",
"released",
"rating",
"votecount",
"description",
"length",
"developer"
],
results=1
)
if not results.get("results"):
await update.message.reply_text(f"😞 VN {vn_id} не найдена")
await update.message.reply_text("😞 VN не найдена")
return
vn = results["results"][0]
@@ -51,27 +52,22 @@ class DetailedHandlers:
text = f"🎮 {vn.get('title','Unknown')} (`{vn_id}`)\n"
if vn.get("original"):
text += f"Оригинал: {vn['original']}\n"
text += f"{vn['original']}\n"
text += f"Релиз: {vn.get('released','?')}\n"
text += f"Рейтинг: {vn.get('rating',0)/10:.1f} ({vn.get('votecount',0)} голосов)\n"
if vn.get("length"):
text += f"Длина: {vn['length']}\n"
if vn.get("developer"):
text += f"Разработчик: {vn['developer']}\n"
if vn.get("description"):
desc = vn["description"][:300]
text += f"\nОписание:\n{desc}...\n"
text += f"\nОписание:\n{vn['description'][:300]}...\n"
text += f"\nhttps://vndb.org/{vn_id}"
img = vn.get("image")
if img:
url = ImageHandler.get_image_url(img)
if url:
await update.message.reply_photo(photo=url, caption=text)
return
await update.message.reply_text(text)
except Exception as e:
@@ -96,10 +92,12 @@ class DetailedHandlers:
results = await vndb_client.query_character(
filters=["id", "=", char_id],
fields=[
"id", "name", "original",
"gender", "bloodtype",
"description", "image{url,dims}",
"vn"
"id",
"name",
"original",
"gender",
"bloodtype",
"description"
],
results=1
)
@@ -121,24 +119,11 @@ class DetailedHandlers:
if c.get("bloodtype"):
text += f"Кровь: {c['bloodtype']}\n"
if c.get("vn"):
text += "\nVN:\n"
for vn in c["vn"][:5]:
if vn.get("id"):
text += f"{vn['id']}\n"
if c.get("description"):
text += f"\n{c['description'][:300]}...\n"
text += f"\nОписание:\n{c['description'][:300]}...\n"
text += f"\nhttps://vndb.org/{char_id}"
img = c.get("image")
if img:
url = ImageHandler.get_image_url(img)
if url:
await update.message.reply_photo(photo=url, caption=text)
return
await update.message.reply_text(text)
except Exception as e:
@@ -163,12 +148,14 @@ class DetailedHandlers:
results = await vndb_client.query_release(
filters=["id", "=", release_id],
fields=[
"id", "title", "original",
"released", "platform",
"type", "language",
"description",
"image{url,dims}",
"vn"
"id",
"title",
"original",
"released",
"platform",
"type",
"language",
"description"
],
results=1
)
@@ -191,24 +178,11 @@ class DetailedHandlers:
if r.get("language"):
text += f"Языки: {', '.join(r['language'])}\n"
if r.get("vn"):
text += "\nVN:\n"
for vn in r["vn"][:3]:
if vn.get("id"):
text += f"{vn['id']}\n"
if r.get("description"):
text += f"\n{r['description'][:200]}...\n"
text += f"\nОписание:\n{r['description'][:200]}...\n"
text += f"\nhttps://vndb.org/{release_id}"
img = r.get("image")
if img:
url = ImageHandler.get_image_url(img)
if url:
await update.message.reply_photo(photo=url, caption=text)
return
await update.message.reply_text(text)
except Exception as e: