2023-12-17 19:47:52 +03:00
|
|
|
|
using OneOf;
|
|
|
|
|
using Remora.Discord.API.Abstractions.Objects;
|
|
|
|
|
using Remora.Discord.API.Abstractions.Rest;
|
|
|
|
|
using Remora.Discord.API.Objects;
|
|
|
|
|
using Remora.Rest.Core;
|
|
|
|
|
using Remora.Results;
|
|
|
|
|
|
2024-05-16 18:34:26 +03:00
|
|
|
|
namespace TeamOctolings.Octobot.Extensions;
|
2023-12-17 19:47:52 +03:00
|
|
|
|
|
|
|
|
|
public static class ChannelApiExtensions
|
|
|
|
|
{
|
|
|
|
|
public static async Task<Result> CreateMessageWithEmbedResultAsync(this IDiscordRestChannelAPI channelApi,
|
|
|
|
|
Snowflake channelId, Optional<string> message = default, Optional<string> nonce = default,
|
|
|
|
|
Optional<bool> isTextToSpeech = default, Optional<Result<Embed>> embedResult = default,
|
|
|
|
|
Optional<IAllowedMentions> allowedMentions = default, Optional<IMessageReference> messageRefenence = default,
|
|
|
|
|
Optional<IReadOnlyList<IMessageComponent>> components = default,
|
|
|
|
|
Optional<IReadOnlyList<Snowflake>> stickerIds = default,
|
|
|
|
|
Optional<IReadOnlyList<OneOf<FileData, IPartialAttachment>>> attachments = default,
|
|
|
|
|
Optional<MessageFlags> flags = default, CancellationToken ct = default)
|
|
|
|
|
{
|
|
|
|
|
if (!embedResult.IsDefined() || !embedResult.Value.IsDefined(out var embed))
|
|
|
|
|
{
|
2024-03-20 21:08:16 +03:00
|
|
|
|
return ResultExtensions.FromError(embedResult.Value);
|
2023-12-17 19:47:52 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (Result)await channelApi.CreateMessageAsync(channelId, message, nonce, isTextToSpeech, new[] { embed },
|
|
|
|
|
allowedMentions, messageRefenence, components, stickerIds, attachments, flags, ct);
|
|
|
|
|
}
|
|
|
|
|
}
|