Skip to content

Commit

Permalink
refactor(topic): better warning if index out of range
Browse files Browse the repository at this point in the history
#
  • Loading branch information
Pukimaa committed Feb 2, 2023
1 parent c2bdbb4 commit edf461f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions cogs/misc/revive.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import i18n
import discord
from asyncio import sleep
from random import randint
from .topics import questions
from discord import app_commands
Expand All @@ -21,7 +22,6 @@ async def topic(
id: int | None = None,
):
locale = get_language(self.bot, interaction.guild_id)
original_id = id
id = randint(0, len(questions)) if id is None else id
index = id - 1
embeds = []
Expand All @@ -44,12 +44,14 @@ async def topic(
if not valid_topic:
embed2, file = error_embed(
self.bot,
i18n.t("misc.topic_invalid_title", locale=locale, id=original_id),
i18n.t("misc.topic_invalid", locale=locale),
i18n.t("misc.topic_invalid_title", locale=locale),
i18n.t("misc.topic_invalid", amount=len(questions), locale=locale),
interaction.guild_id,
style="warning",
)
embeds = [embed2, embed]
files.append(file)

await interaction.response.send_message(embeds=embeds, files=files)
await sleep(5)
await interaction.edit_original_response(embed=embed, attachments=[])
4 changes: 2 additions & 2 deletions i18n/misc/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ en:
auto_translate_delete_original: "Deletion of the original message is now set to %{value}"
topic_title: "Here's your topic:"
topic_footer: "Topic ID: %{id}"
topic_invalid_title: "We couldn't find a Topic with the ID of `%{id}`"
topic_invalid: "We searched far and wide. Unfortunately, no topics were found.\nThat's why we picked a random topic for you. We hope you like it."
topic_invalid_title: "We searched far and wide. Unfortunately, no topics were found."
topic_invalid: "We've selected one of our %{amount} topics at random just for you. We hope you like it."
auto_react_added: "%{emoji} will now be added to every message in %{channel}"
auto_react_removed: "%{emoji} will no longer be added to every message in %{channel}"
auto_react_empty: "No emojis are set to be added to every message in %{channel}"
Expand Down

0 comments on commit edf461f

Please sign in to comment.