This commit is contained in:
2026-05-01 18:55:23 +03:00

31
bot.py
View File

@@ -3,6 +3,7 @@ import logging
import re import re
import httpx import httpx
import random import random
import random
from aiogram import Bot, Dispatcher, types from aiogram import Bot, Dispatcher, types
from aiogram.filters import Command, CommandObject from aiogram.filters import Command, CommandObject
from aiogram.client.default import DefaultBotProperties from aiogram.client.default import DefaultBotProperties
@@ -109,10 +110,38 @@ async def handle_vn(message: types.Message, command: CommandObject):
) )
await send_result(message, text, img) await send_result(message, text, img)
@dp.message(Command("random"))
async def handle_random(message: types.Message):
"""Выбирает случайную новеллу из 50 популярных с высоким рейтингом."""
# Фильтр: рейтинг > 75, популярность высокая
res = await fetch_vndb("vn", ["rating", ">=", 75], "id, title, image{url}, rating, description", sort="votecount", results=50)
if not res: return await message.answer("❌ API error")
v = random.choice(res)
text = (
f"🎲 <b>RANDOM VN PICK</b>\n\n"
f"<b>TITLE:</b> {v['title']}\n"
f"<b>RATING:</b> {v['rating']/10}\n\n"
f"<b>DESCRIPTION:</b>\n<i>{clean_text(v.get('description'), 300)}</i>\n\n"
f"<b>VNDB:</b> https://vndb.org/{v['id']}"
)
await send_result(message, text, v.get('image', {}).get('url'))
@dp.message(Command("top"))
async def handle_top(message: types.Message):
"""Выводит топ-10 новелл по рейтингу."""
res = await fetch_vndb("vn", ["votecount", ">", 1000], "id, title, rating", sort="rating", results=10)
if not res: return await message.answer("❌ API error")
out = ["🏆 <b>TOP RATED VISUAL NOVELS</b>\n"]
for i, v in enumerate(res, 1):
out.append(f"{i}. {v['title']} — <b>{v['rating']/10}</b> (<code>{v['id']}</code>)")
await message.answer("\n".join(out))
@dp.message(Command("char")) @dp.message(Command("char"))
async def handle_char(message: types.Message, command: CommandObject): async def handle_char(message: types.Message, command: CommandObject):
if not command.args: return await message.answer("Usage: /char <name/id>") if not command.args: return await message.answer("Usage: /char <name/id>")
is_id = command.args.startswith('c') and command.args[1:].isdigit() is_id = command.args.startswith('c') and command.args[1:].isdigit()
filt = ["id", "=", command.args] if is_id else ["search", "=", command.args] filt = ["id", "=", command.args] if is_id else ["search", "=", command.args]
fields = "id, name, original, description, gender, age, blood_type, image{url}" fields = "id, name, original, description, gender, age, blood_type, image{url}"