From 3f416e9fe059a9a0f5ad8e7e776cf44e591b3c8c Mon Sep 17 00:00:00 2001 From: itexpert228 <67105314+fdaser1337@users.noreply.github.com> Date: Fri, 24 Apr 2026 12:15:31 +0300 Subject: [PATCH] Revert "delete govnshe ebanoe" This reverts commit 628099b4430768ad10725144fd880123901caea7. --- games/uwu.py | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 games/uwu.py diff --git a/games/uwu.py b/games/uwu.py new file mode 100644 index 0000000..634e4f1 --- /dev/null +++ b/games/uwu.py @@ -0,0 +1,87 @@ +import aiohttp +from aiogram import types +import config +import logging +import random + +logger = logging.getLogger(__name__) + +CAPTIONS = [ + "Ня :3", + "uwu" +] + +async def handle_uwu_cmd(message: types.Message): + args = message.text.split(maxsplit=1) + + if len(args) > 1 and args[1].strip() == "-h": + help_msg = ( + "🐈 Справка по тегам e621:\n\n" + "Перечислите любые теги через пробел после команды.\n" + "• rating: rating:safe (безопасные), rating:questionable, rating:explicit (NSFW)\n" + "• score: score:>500 (искать популярные посты с рейтингом больше 500)\n" + "• Исключить тег: поставьте минус, например -fox\n\n" + "Пример: /uwu wolf -rating:explicit score:>100\n" + "По умолчанию: rating:safe score:>500 -animated" + ) + await message.reply(help_msg, parse_mode="HTML") + return + + tags = "rating:safe score:>500 -animated" + if len(args) > 1: + tags = args[1].strip() + + tags += " order:random" + + url = "https://e621.net/posts.json" + params = { + "tags": tags, + "limit": 1 + } + + auth = None + if config.E621_LOGIN and config.E621_API_KEY: + auth = aiohttp.BasicAuth(config.E621_LOGIN, config.E621_API_KEY) + + headers = { + "User-Agent": f"Sex Bomba TG Bot/1.0 (by {config.E621_LOGIN or 'unknown'} on e621)" + } + + try: + async with aiohttp.ClientSession() as session: + async with session.get(url, params=params, headers=headers, auth=auth) as resp: + if resp.status != 200: + logger.error(f"e621 API Error: {resp.status}") + await message.reply("Не удалось получить картинку от сервера :(") + return + data = await resp.json() + + posts = data.get("posts", []) + if not posts: + await message.reply("Ничего не найдено по этим тегам :(") + return + + post = posts[0] + file_url = post.get("file", {}).get("url") + ext = post.get("file", {}).get("ext", "png") + if not file_url: + await message.reply("У найденного поста нет прямого URL изображения :(") + return + + caption = random.choice(CAPTIONS) + if ext in ("gif", "webm", "mp4"): + # Для анимаций: отправляем caption отдельным сообщением, + # а саму гифку/видео через URL напрямую — так Telegram + # корректно показывает её как анимацию, а не как файл + await message.answer(caption) + await message.answer_animation(animation=file_url) + elif ext in ("png", "jpg", "jpeg", "webp"): + input_file = types.URLInputFile(file_url) + await message.answer_photo(photo=input_file, caption=caption) + else: + input_file = types.URLInputFile(file_url) + await message.answer_document(document=input_file, caption=caption) + + except Exception as e: + logger.exception("Error in uwu command") + await message.reply("Произошла ошибка при обращении к API :(")