Skip to content

Commit

Permalink
Improve news command
Browse files Browse the repository at this point in the history
  • Loading branch information
MycroftKang committed May 12, 2024
1 parent dafdadb commit 1e45d58
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions src/bot/core/controllers/discord/news.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1e45d58

Please sign in to comment.