deadzilla d4bf8ca45d fix: исправить блокировку event loop и добавить retry задержку
- Добавить экспоненциальную задержку между попытками retry (1с, 2с, 4с) в pogoda.py
- Заменить time.sleep на await asyncio.sleep для неблокирующих ожиданий
- Обернуть requests.get в asyncio.to_thread для предотвращения блокировки event loop (news.py, cat.py, pogoda.py)
- Добавить правило AGENTS.md: не использовать эмодзи
- Добавить ISSUES.md с фиксацией проблем проекта
2026-05-26 10:24:26 +05:00

31 lines
988 B
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 discord
from discord.ext import commands
import asyncio
import requests
class Cat(commands.Cog):
"""Команда !cat — случайный котик"""
@commands.command(name="cat")
async def cat(self, ctx):
"""Получить случайного котика"""
try:
response = await asyncio.to_thread(
requests.get,
"https://api.thecatapi.com/v1/images/search",
timeout=10
)
response.raise_for_status()
data = response.json()
url = data[0]["url"]
embed = discord.Embed(
title="🐱 Котик для тебя!",
color=discord.Color.orange()
)
embed.set_image(url=url)
await ctx.send(embed=embed)
except requests.RequestException:
await ctx.send("Не удалось получить котика. Попробуйте позже.")