Skip to content

Commit

Permalink
Change defer location
Browse files Browse the repository at this point in the history
  • Loading branch information
TLNBS2405 committed Mar 13, 2024
1 parent 993901b commit b808aba
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/heihachi/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@ async def on_ready(self) -> None:

def _character_command_factory(self, name: str) -> Callable[[Interaction, str], Coroutine[Any, Any, None]]:
async def command(interaction: discord.Interaction, move: str) -> None:
await interaction.response.defer()
if not (self._is_user_blacklisted(str(interaction.user.id)) or self._is_author_newly_created(interaction)):
logger.info(
f"Received character command from {interaction.user.name} in {interaction.guild}: /fd {name} {move}"
)
embed = get_frame_data_embed(self.framedb, self.frame_service, name, move)

await interaction.response.defer()

await asyncio.sleep(0)
await interaction.followup.send(embed=embed, ephemeral=False)

Expand Down Expand Up @@ -122,25 +123,28 @@ def _add_bot_commands(self) -> None:
@self.tree.command(name="fd", description="Frame data from a character move")
@discord.app_commands.autocomplete(character=self._character_name_autocomplete)
async def _frame_data_cmd(interaction: discord.Interaction, character: str, move: str) -> None:
await interaction.response.defer()
logger.info(f"Received command from {interaction.user.name} in {interaction.guild}: /fd {character} {move}")
character_name_query = character
move_query = move
if not (self._is_user_blacklisted(str(interaction.user.id)) or self._is_author_newly_created(interaction)):
embed = get_frame_data_embed(self.framedb, self.frame_service, character_name_query, move_query)

await interaction.response.defer()

await asyncio.sleep(0)
await interaction.followup.send(embed=embed, ephemeral=False)

if self.config.feedback_channel_id and self.config.action_channel_id:

@self.tree.command(name="feedback", description="Send feedback to the authors in case of incorrect data")
async def _feedback_cmd(interaction: discord.Interaction, message: str) -> None:
await interaction.response.defer()
logger.info(f"Received command from {interaction.user.name} in {interaction.guild}: /feedback {message}")
if not (self._is_user_blacklisted(str(interaction.user.id)) or self._is_author_newly_created(interaction)):
# TODO: possible way to refactor these checks using discord.py library?
# discord.ext.commands.Bot.check()
try:

feedback_message = "Feedback from **{}** with ID **{}** in **{}** \n- {}\n".format(
str(interaction.user.name),
interaction.user.id,
Expand All @@ -161,17 +165,19 @@ async def _feedback_cmd(interaction: discord.Interaction, message: str) -> None:
except Exception as e:
result = embed.get_error_embed(f"Feedback couldn't be sent, caused by: {traceback.format_exc()}")

await interaction.response.defer()

await asyncio.sleep(0)
await interaction.followup.send(embed=result, ephemeral=False)
else:
logger.warning("Feedback or Action channel ID is not set. Disabling feedback command.")

@self.tree.command(name="help", description="Show help")
async def _help_command(interaction: discord.Interaction) -> None:
await interaction.response.defer()
logger.info(f"Received command from {interaction.user.name} in {interaction.guild}: /help")
if not (self._is_user_blacklisted(str(interaction.user.id)) or self._is_author_newly_created(interaction)):

help_embed = embed.get_help_embed(self.frame_service)
await interaction.response.defer()

await asyncio.sleep(0)
await interaction.followup.send(embed=help_embed, ephemeral=False)

0 comments on commit b808aba

Please sign in to comment.