bot_tg/games/nude.py

109 lines
4.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import aiohttp
from aiogram import types
import config
import logging
import random
import re
logger = logging.getLogger(__name__)
CAPTIONS = [
"Hot stuff 🔥",
"Sexy content 😏",
"ШПАЧИХА"
]
async def handle_nude_cmd(message: types.Message):
args = message.text.split(maxsplit=1)
if len(args) > 1 and args[1].strip() == "-h":
help_msg = (
"🔥 <b>Справка по команде /nude:</b>\n\n"
"Получает случайные изображения взрослых женщин из открытых источников.\n"
"• Использует прямое сканирование сайтов для поиска контента\n"
"• По умолчанию ищет популярные изображения\n"
"• Отправляет изображения напрямую\n\n"
"<i>Пример:</i> <code>/nude</code>\n"
"<i>По умолчанию:</i> Случайные изображения с популярных сайтов"
)
await message.reply(help_msg, parse_mode="HTML")
return
# Список сайтов для сканирования
sites = [
"https://www.imagefap.com/gallery.php?pg=random",
"https://xhamster.com/photos?sort=random",
"https://spankbang.com/random"
]
random_site = random.choice(sites)
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"Accept-Language": "en-US,en;q=0.5",
"Accept-Encoding": "gzip, deflate",
"Connection": "keep-alive",
"Upgrade-Insecure-Requests": "1"
}
try:
async with aiohttp.ClientSession() as session:
async with session.get(random_site, headers=headers) as resp:
if resp.status != 200:
logger.error(f"Site access error: {resp.status}")
await message.reply("Не удалось получить доступ к сайту :(")
return
html = await resp.text()
# Ищем URL изображений в HTML
img_patterns = [
r'<img[^>]+src="([^"]+)"',
r'<a[^>]+href="([^"]+\.(jpg|jpeg|png|gif|webp))"',
r'data-src="([^"]+)"'
]
img_urls = []
for pattern in img_patterns:
matches = re.findall(pattern, html, re.IGNORECASE)
img_urls.extend(matches)
if not img_urls:
await message.reply("Изображения не найдены на странице :(")
return
# Фильтруем и выбираем случайное изображение
valid_imgs = []
for img_url in img_urls:
if img_url.startswith('//'):
img_url = 'https:' + img_url
elif img_url.startswith('/'):
if 'imagefap.com' in random_site:
img_url = 'https://www.imagefap.com' + img_url
elif 'xhamster.com' in random_site:
img_url = 'https://xhamster.com' + img_url
elif 'spankbang.com' in random_site:
img_url = 'https://spankbang.com' + img_url
if any(ext in img_url.lower() for ext in ['.jpg', '.jpeg', '.png', '.gif', '.webp']):
valid_imgs.append(img_url)
if not valid_imgs:
await message.reply("Подходящие изображения не найдены :(")
return
final_img_url = random.choice(valid_imgs)
caption = random.choice(CAPTIONS)
# Отправляем изображение
try:
input_file = types.URLInputFile(final_img_url)
await message.answer_photo(photo=input_file, caption=caption)
except Exception as e:
logger.error(f"Error sending photo: {e}")
await message.answer(f"{caption}\n{final_img_url}")
except Exception as e:
logger.exception("Error in nude command")
await message.reply("Произошла ошибка при обработке запроса :(")