From 1e45d58681c89920f16aba71e063dcbe26e5dc6f Mon Sep 17 00:00:00 2001 From: Mycroft Kang Date: Sun, 12 May 2024 21:29:08 +0900 Subject: [PATCH] Improve news command --- src/bot/core/controllers/discord/news.py | 43 +++++++++++++++--------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/src/bot/core/controllers/discord/news.py b/src/bot/core/controllers/discord/news.py index 86bf81cc..dd536446 100644 --- a/src/bot/core/controllers/discord/news.py +++ b/src/bot/core/controllers/discord/news.py @@ -182,19 +182,28 @@ async def news_notify(bot: commands.Bot, data: NewsNotifyData): ) await ch.send( - __("📰 Here is the news related to `{query}`").format(query=data.keyword) + __("🔔 Here is the news🗞️ related to `{query}`").format(query=data.keyword) ) - for result in results: + if results: await ch.send( - embed=MsgFormatter.news( - result.title, - result.description, - f"{result.press} · {result.timestamp}", - result.press_image_url, - thumbnail_url=result.image_url, - url=result.url, - ), + embeds=[ + MsgFormatter.news( + result.title, + result.description, + f"{result.press} · {result.timestamp}", + result.press_image_url, + thumbnail_url=result.image_url, + url=result.url, + ) + for result in results + ] + ) + else: + await ch.send( + content=__("🚫 No results were found for `{query}`").format( + query=data.keyword + ) ) button = NotificationButtonOff(data.keyword, data.provider, data.msg_id) @@ -311,17 +320,19 @@ async def search( content=__("📰 News search results for `{query}`").format(query=query) ) - for result in results: - await ctx.channel.send( - embed=MsgFormatter.news( + await ctx.channel.send( + embeds=[ + MsgFormatter.news( result.title, result.description, f"{result.press} · {result.timestamp}", result.press_image_url, thumbnail_url=result.image_url, url=result.url, - ), - ) + ) + for result in results + ], + ) if subscribed: button = NotificationButtonOff(query, "naver", ctx.message.id) @@ -416,7 +427,6 @@ async def callback(self, interaction: discord.Interaction): self.keyword, self.provider, interaction.user, self.msg_id, self, self.view ) await interaction.response.send_modal(self.fv) - self.view.stop() class NotificationButtonOff(discord.ui.Button): @@ -548,6 +558,7 @@ async def on_submit(self, interaction: discord.Interaction): self.button.style = discord.ButtonStyle.gray await interaction.response.edit_message(view=self.view) + self.view.stop() async def on_error( self, error: Exception, interaction: discord.Interaction