Files
limoka/Ruslan-Isaev/modules/DogPic.py
2025-07-10 21:02:34 +03:00

45 lines
1.4 KiB
Python
Raw Permalink 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.

version = (1, 0, 0)
# meta developer: @RUIS_VlP
import asyncio
from .. import loader, utils
import aiohttp
import asyncio
API_KEY = 'live_AQldtIr1OR2HIwnXKIONXtGRhEvVd0ZDKBthbAwlC3UgFbxwYFwsEDm4fCcWgSfP'
URL = 'https://api.thedogapi.com/v1/images/search'
async def get_image():
headers = {'x-api-key': API_KEY}
async with aiohttp.ClientSession() as session:
async with session.get(URL, headers=headers) as response:
if response.status == 200:
data = await response.json()
image_url = data[0]['url']
return image_url, 0
else:
return response.status, 1
@loader.tds
class DogPicMod(loader.Module):
"""Модуль для фотографий с милыми собачками"""
strings = {
"name": "DogPic",
}
@loader.command()
async def dogpic(self, message):
"""картинка с собачкой"""
await utils.answer(message, "🔎 <b>Ищу лучшую картинку</b>")
try:
link, exitcode = await get_image()
if exitcode == 0:
await message.delete()
await utils.answer_file(message, link)
else:
await utils.answer(message, f"❌ <b>Ошибка!</b>\n\n<code>{link}</code>")
except Exception as e:
await utils.answer(message, f"❌ <b>Ошибка!</b>\n\n<code>{e}</code>")