Catalogger.NET/Catalogger.Backend/Extensions/DiscordRestExtensions.cs

69 lines
2.5 KiB
C#
Raw Normal View History

// Copyright (C) 2021-present sam (starshines.gay)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
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
}