2024-10-12 23:28:15 +02:00
|
|
|
using OneOf;
|
|
|
|
|
using Remora.Discord.API.Abstractions.Objects;
|
|
|
|
|
using Remora.Discord.API.Abstractions.Rest;
|
|
|
|
|
using Remora.Discord.API.Objects;
|
2024-10-14 00:26:17 +02:00
|
|
|
using Remora.Discord.Commands.Feedback.Messages;
|
|
|
|
|
using Remora.Discord.Commands.Feedback.Services;
|
2024-10-12 23:28:15 +02:00
|
|
|
using Remora.Rest.Core;
|
|
|
|
|
using Remora.Results;
|
|
|
|
|
|
|
|
|
|
namespace Catalogger.Backend.Extensions;
|
|
|
|
|
|
|
|
|
|
public static class DiscordRestExtensions
|
|
|
|
|
{
|
|
|
|
|
public static async Task<Result> UpdateMessageAsync(
|
|
|
|
|
this IDiscordRestInteractionAPI interactionApi,
|
|
|
|
|
IInteraction interaction,
|
|
|
|
|
InteractionMessageCallbackData data
|
|
|
|
|
) =>
|
|
|
|
|
await interactionApi.CreateInteractionResponseAsync(
|
|
|
|
|
interaction.ID,
|
|
|
|
|
interaction.Token,
|
|
|
|
|
new InteractionResponse(
|
|
|
|
|
InteractionCallbackType.UpdateMessage,
|
|
|
|
|
new Optional<
|
|
|
|
|
OneOf<
|
|
|
|
|
IInteractionMessageCallbackData,
|
|
|
|
|
IInteractionAutocompleteCallbackData,
|
|
|
|
|
IInteractionModalCallbackData
|
|
|
|
|
>
|
|
|
|
|
>(data)
|
|
|
|
|
)
|
|
|
|
|
);
|
2024-10-14 00:26:17 +02:00
|
|
|
|
|
|
|
|
public static async Task<Result<IMessage>> ReplyAsync(
|
|
|
|
|
this IFeedbackService feedbackService,
|
|
|
|
|
Optional<string> content = default,
|
|
|
|
|
IEnumerable<IEmbed>? embeds = null,
|
|
|
|
|
bool isEphemeral = false
|
|
|
|
|
) =>
|
|
|
|
|
await feedbackService.SendContextualAsync(
|
|
|
|
|
content,
|
|
|
|
|
embeds != null
|
|
|
|
|
? new Optional<IReadOnlyList<IEmbed>>(embeds.ToList())
|
|
|
|
|
: new Optional<IReadOnlyList<IEmbed>>(),
|
|
|
|
|
options: new FeedbackMessageOptions(
|
|
|
|
|
MessageFlags: isEphemeral ? MessageFlags.Ephemeral : 0,
|
|
|
|
|
AllowedMentions: new AllowedMentions(
|
|
|
|
|
Parse: new List<MentionType>(),
|
|
|
|
|
MentionRepliedUser: true
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
);
|
2024-10-12 23:28:15 +02:00
|
|
|
}
|