Skip to content

Commit

Permalink
fix: IH attempting to dual respond
Browse files Browse the repository at this point in the history
  • Loading branch information
Skelmis committed Mar 29, 2024
1 parent ae031be commit 68b617f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
8 changes: 8 additions & 0 deletions suggestions/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import aiohttp
import alaric
import commons
import disnake
from alaric import Cursor
from bot_base.wraps import WrappedChannel
Expand Down Expand Up @@ -614,6 +615,13 @@ async def on_slash_command_error(
ephemeral=True,
)

logger.critical(
"Unhandled error encountered",
extra_metadata={
"error_name": exception.__class__.__name__,
"traceback": commons.exception_as_string(exception),
},
)
raise exception

async def on_button_error(
Expand Down
4 changes: 3 additions & 1 deletion suggestions/cogs/suggestion_cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,9 @@ async def suggest(
)
await suggestion.setup_initial_messages(
guild_config=guild_config,
ih=await InteractionHandler.new_handler(interaction),
ih=await InteractionHandler.new_handler(
interaction, i_just_want_an_instance=True
),
cog=self,
guild=guild,
icon_url=icon_url,
Expand Down
26 changes: 18 additions & 8 deletions suggestions/interaction_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,19 @@ class InteractionHandler:

def __init__(
self,
interaction: disnake.Interaction
| disnake.GuildCommandInteraction
| disnake.MessageInteraction,
interaction: (
disnake.Interaction
| disnake.GuildCommandInteraction
| disnake.MessageInteraction
),
ephemeral: bool,
with_message: bool,
):
self.interaction: disnake.Interaction | disnake.GuildCommandInteraction | disnake.MessageInteraction = (
interaction
)
self.interaction: (
disnake.Interaction
| disnake.GuildCommandInteraction
| disnake.MessageInteraction
) = interaction
self.ephemeral: bool = ephemeral
self.with_message: bool = with_message
self.is_deferred: bool = False
Expand Down Expand Up @@ -83,11 +87,17 @@ async def new_handler(
*,
ephemeral: bool = True,
with_message: bool = True,
i_just_want_an_instance: bool = False,
) -> InteractionHandler:
"""Generate a new instance and defer the interaction."""
instance = cls(interaction, ephemeral, with_message)
await interaction.response.defer(ephemeral=ephemeral, with_message=with_message)
instance.is_deferred = True

if not i_just_want_an_instance:
# TODO Remove this once BT-10 is resolved
await interaction.response.defer(
ephemeral=ephemeral, with_message=with_message
)
instance.is_deferred = True

# Register this on the bot instance so other areas can
# request the interaction handler, such as error handlers
Expand Down

0 comments on commit 68b617f

Please sign in to comment.