Skip to content

Commit

Permalink
Use defer() in case vServer doesn't response in 3 seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
TLNBS2405 committed Mar 13, 2024
1 parent 57676db commit e4b8d09
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/heihachi/bot.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
import datetime
import logging
import traceback
Expand Down Expand Up @@ -58,7 +59,10 @@ async def command(interaction: discord.Interaction, move: str) -> None:
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.send_message(embed=embed, ephemeral=False)

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

return command

Expand Down Expand Up @@ -121,7 +125,11 @@ async def _frame_data_cmd(interaction: discord.Interaction, character: str, move
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.send_message(embed=embed, ephemeral=False)

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:

Expand Down Expand Up @@ -152,7 +160,9 @@ 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.send_message(embed=result, ephemeral=False)
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.")

Expand All @@ -161,4 +171,6 @@ async def _help_command(interaction: discord.Interaction) -> None:
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.send_message(embed=help_embed, ephemeral=True)
await interaction.response.defer()
await asyncio.sleep(0)
await interaction.followup.send(embed=help_embed, ephemeral=False)

0 comments on commit e4b8d09

Please sign in to comment.