feat: handle CataloggerError results in interaction responder
This commit is contained in:
parent
8a4e3ff184
commit
24f6aee57d
1 changed files with 38 additions and 2 deletions
|
|
@ -19,17 +19,21 @@ using Remora.Commands.Services;
|
||||||
using Remora.Commands.Tokenization;
|
using Remora.Commands.Tokenization;
|
||||||
using Remora.Commands.Trees;
|
using Remora.Commands.Trees;
|
||||||
using Remora.Discord.API.Abstractions.Gateway.Events;
|
using Remora.Discord.API.Abstractions.Gateway.Events;
|
||||||
|
using Remora.Discord.API.Abstractions.Objects;
|
||||||
using Remora.Discord.API.Abstractions.Rest;
|
using Remora.Discord.API.Abstractions.Rest;
|
||||||
|
using Remora.Discord.API.Objects;
|
||||||
using Remora.Discord.Commands.Responders;
|
using Remora.Discord.Commands.Responders;
|
||||||
using Remora.Discord.Commands.Services;
|
using Remora.Discord.Commands.Services;
|
||||||
using Remora.Discord.Gateway.Responders;
|
using Remora.Discord.Gateway.Responders;
|
||||||
|
using Remora.Rest.Core;
|
||||||
using Remora.Results;
|
using Remora.Results;
|
||||||
using Serilog.Context;
|
using Serilog.Context;
|
||||||
|
|
||||||
namespace Catalogger.Backend.Bot.Responders;
|
namespace Catalogger.Backend.Bot.Responders;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Wrapper for Remora.Discord's default interaction responder, that ignores all events if test mode is enabled.
|
/// Wrapper for Remora.Discord's default interaction responder, that ignores all events if test mode is enabled,
|
||||||
|
/// and handles <see cref="CataloggerError" /> results returned by commands.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class CustomInteractionResponder(
|
public class CustomInteractionResponder(
|
||||||
Config config,
|
Config config,
|
||||||
|
|
@ -87,6 +91,38 @@ public class CustomInteractionResponder(
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
return await _inner.RespondAsync(evt, ct);
|
var result = await _inner.RespondAsync(evt, ct);
|
||||||
|
if (result.Error is not CataloggerError cataloggerError)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
return await interactionAPI.CreateInteractionResponseAsync(
|
||||||
|
evt.ID,
|
||||||
|
evt.Token,
|
||||||
|
new InteractionResponse(
|
||||||
|
Type: InteractionCallbackType.ChannelMessageWithSource,
|
||||||
|
Data: new Optional<OneOf.OneOf<
|
||||||
|
IInteractionMessageCallbackData,
|
||||||
|
IInteractionAutocompleteCallbackData,
|
||||||
|
IInteractionModalCallbackData
|
||||||
|
>>(
|
||||||
|
new InteractionMessageCallbackData(
|
||||||
|
Embeds: new Optional<IReadOnlyList<IEmbed>>(
|
||||||
|
[
|
||||||
|
new Embed(
|
||||||
|
Colour: DiscordUtils.Red,
|
||||||
|
Title: "Something went wrong",
|
||||||
|
Description: $"""
|
||||||
|
Something went wrong while running this command.
|
||||||
|
> {cataloggerError.Message}
|
||||||
|
Please try again later.
|
||||||
|
"""
|
||||||
|
),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
ct: ct
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue