feat: add /uwu command for e621.net

This commit is contained in:
furrexwolfy 2026-03-21 12:56:05 +03:00
parent 107a0647d1
commit 967cfb4a6d
3 changed files with 62 additions and 0 deletions

View file

@ -27,6 +27,10 @@ POLYCHAETSI_IMAGE_PATH = BASE_DIR / "maket" / "cvetok.jpg"
# --- Казино ---
CASINO_MAX_BET = 1.0
# --- E621 API ---
E621_LOGIN = os.getenv("E621_LOGIN", "")
E621_API_KEY = os.getenv("E621_API_KEY", "")
# --- Ставки на матчи ---
ODDS_API_KEY = os.getenv("ODDS_API_KEY", "")
ODDS_API_BASE = "https://api.the-odds-api.com/v4"
@ -209,6 +213,7 @@ def get_hint_text(templates_str: str) -> str:
"• /bet [спорт] [номер] [исход] [ставка] — поставить см.\n"
"• /mybets — мои ставки.\n"
"• /ebalnik — включить/выключить автоответы в чате.\n"
"• /uwu [теги] — случайная картинка с e621.\n"
"• /polychaetsi — топ по слову «получается».\n"
"• /prices /fetch — цены и остатки Магнита.\n"
"Подсказка: в группах пиши /команда@username_бота."

54
games/uwu.py Normal file
View file

@ -0,0 +1,54 @@
import aiohttp
from aiogram import types
import config
import logging
logger = logging.getLogger(__name__)
async def handle_uwu_cmd(message: types.Message):
args = message.text.split(maxsplit=1)
tags = "rating:safe score:>500"
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")
if not file_url:
await message.reply("У найденного поста нет прямого URL изображения :(")
return
await message.answer_photo(photo=types.URLInputFile(file_url), caption="Ня :3")
except Exception as e:
logger.exception("Error in uwu command")
await message.reply("Произошла ошибка при обращении к API :(")

View file

@ -22,6 +22,7 @@ from aiogram.client.default import DefaultBotProperties
from AI.talk_handler import handle_talk, generate_autoreply, push_message
from games.casino import play_casino
from games.fortune import generate_fortune
from games.uwu import handle_uwu_cmd
from games.betting import (
clear_user_sport_context,
describe_match_outcomes,
@ -1367,6 +1368,7 @@ def main():
dp.message.register(handle_bet_cmd, Command("bet"))
dp.message.register(handle_mybets_cmd, Command("mybets"))
dp.message.register(handle_gen_mem, Command("gen_mem"))
dp.message.register(handle_uwu_cmd, Command("uwu"))
dp.message.register(handle_keywords, F.text)
async def on_startup(bot: Bot):
@ -1393,6 +1395,7 @@ def main():
BotCommand(command="bet", description="поставить см на матч"),
BotCommand(command="mybets", description="мои ставки"),
BotCommand(command="svodka", description="СВО: итоги"),
BotCommand(command="uwu", description="Случайная картинка с e621"),
]
scopes = (
BotCommandScopeDefault(),