From bc37362959319a081e79dcfd504ff9a273b090d8 Mon Sep 17 00:00:00 2001 From: deadzilla Date: Sat, 11 Jul 2026 23:47:00 +0500 Subject: [PATCH] =?UTF-8?q?fix:=20!nw=20=D0=B8=D1=81=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D1=8C=D0=B7=D1=83=D0=B5=D1=82=20asyncio.gather()=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=BF=D0=B0=D1=80=D0=B0=D0=BB=D0=BB=D0=B5=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D0=BE=D0=B9=20=D0=B7=D0=B0=D0=B3=D1=80=D1=83=D0=B7?= =?UTF-8?q?=D0=BA=D0=B8=20RSS=20=D0=B2=D0=BC=D0=B5=D1=81=D1=82=D0=BE=20?= =?UTF-8?q?=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=D0=B4=D0=BE=D0=B2=D0=B0=D1=82?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BD=D0=BE=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- commands/news.py | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/commands/news.py b/commands/news.py index de64aeb..eaaf5ab 100644 --- a/commands/news.py +++ b/commands/news.py @@ -1,3 +1,4 @@ +import asyncio import logging from discord.ext import commands from utils.news import ( @@ -17,29 +18,31 @@ class News(commands.Cog): @commands.command(name="nw") async def nw(self, ctx: commands.Context) -> None: """Топ-5 свежих статей и новостей по AI с Habr""" - articles = await fetch_rss(RSS_URL_ARTICLES) + articles, posts = await asyncio.gather( + fetch_rss(RSS_URL_ARTICLES), + fetch_rss(RSS_URL_POSTS), + ) + + parts: list[str] = [] + + # --- Статьи --- if articles is None: logger.warning( "%s: !nw — не удалось получить статьи (API вернул None)", ctx.author ) - await ctx.send("Не удалось получить новости. Попробуйте позже.") - return - - if not articles: + parts.append("Не удалось получить статьи.") + elif articles: + articles_text = format_articles( + articles, + "Лучшие статьи за сутки / Искусственный интеллект / Хабr", + "https://habr.com/ru/hubs/artificial_intelligence/articles/top/daily/", + ) + parts.append("\n".join(articles_text)) + else: logger.info("%s: !nw — статей нет в RSS", ctx.author) - await ctx.send("Новостей пока нет.") - return - - articles_text = format_articles( - articles, - "Лучшие статьи за сутки / Искусственный интеллект / Хабr", - "https://habr.com/ru/hubs/artificial_intelligence/articles/top/daily/", - ) - - posts = await fetch_rss(RSS_URL_POSTS) - - parts = ["\n".join(articles_text)] + parts.append("Статей пока нет.") + # --- Посты --- if posts is None: logger.warning( "%s: !nw — не удалось получить посты (API вернул None)", ctx.author @@ -61,6 +64,6 @@ class News(commands.Cog): logger.info( "%s: !nw выполнена (статей: %d, постов: %d)", ctx.author, - len(articles), + len(articles) if articles else 0, len(posts) if posts else 0, )