1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-04-19 16:33:36 +03:00

Add ChannelApiExtensions

This commit is contained in:
Macintxsh 2023-12-17 18:02:02 +03:00
parent b284ac28d5
commit 1629623dcf
Signed by: mctaylors
GPG key ID: 7181BEBE676903C1
6 changed files with 33 additions and 10 deletions

View file

@ -0,0 +1,23 @@
using OneOf;
using Remora.Discord.API.Abstractions.Objects;
using Remora.Discord.API.Abstractions.Rest;
using Remora.Rest.Core;
using Remora.Results;
namespace Octobot.Extensions;
public static class ChannelApiExtensions
{
public static async Task<Result> CreateMessageResultAsync(this IDiscordRestChannelAPI channelApi,
Snowflake channelId, Optional<string> message = default, Optional<string> nonce = default,
Optional<bool> isTextToSpeech = default, Optional<IReadOnlyList<IEmbed>> embeds = 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)
{
return (Result)await channelApi.CreateMessageAsync(channelId, message, nonce, isTextToSpeech, embeds,
allowedMentions, messageRefenence, components, stickerIds, attachments, flags, ct);
}
}

View file

@ -97,7 +97,7 @@ public class GuildLoadedResponder : IResponder<IGuildCreate>
return Result.FromError(embed); return Result.FromError(embed);
} }
return (Result)await _channelApi.CreateMessageAsync( return await _channelApi.CreateMessageResultAsync(
GuildSettings.PrivateFeedbackChannel.Get(cfg), embeds: new[] { built }, ct: ct); GuildSettings.PrivateFeedbackChannel.Get(cfg), embeds: new[] { built }, ct: ct);
} }
@ -121,7 +121,7 @@ public class GuildLoadedResponder : IResponder<IGuildCreate>
return Result.FromError(channelResult); return Result.FromError(channelResult);
} }
return (Result)await _channelApi.CreateMessageAsync( return await _channelApi.CreateMessageResultAsync(
channel, embeds: new[] { errorBuilt }, ct: ct); channel, embeds: new[] { errorBuilt }, ct: ct);
} }
} }

View file

@ -77,7 +77,7 @@ public class GuildMemberJoinedResponder : IResponder<IGuildMemberAdd>
return Result.FromError(embed); return Result.FromError(embed);
} }
return (Result)await _channelApi.CreateMessageAsync( return await _channelApi.CreateMessageResultAsync(
GuildSettings.PublicFeedbackChannel.Get(cfg), embeds: new[] { built }, GuildSettings.PublicFeedbackChannel.Get(cfg), embeds: new[] { built },
allowedMentions: Octobot.NoMentions, ct: ct); allowedMentions: Octobot.NoMentions, ct: ct);
} }

View file

@ -103,7 +103,7 @@ public class MessageDeletedResponder : IResponder<IMessageDelete>
return Result.FromError(embed); return Result.FromError(embed);
} }
return (Result)await _channelApi.CreateMessageAsync( return await _channelApi.CreateMessageResultAsync(
GuildSettings.PrivateFeedbackChannel.Get(cfg), embeds: new[] { built }, GuildSettings.PrivateFeedbackChannel.Get(cfg), embeds: new[] { built },
allowedMentions: Octobot.NoMentions, ct: ct); allowedMentions: Octobot.NoMentions, ct: ct);
} }

View file

@ -112,7 +112,7 @@ public class MessageEditedResponder : IResponder<IMessageUpdate>
return Result.FromError(embed); return Result.FromError(embed);
} }
return (Result)await _channelApi.CreateMessageAsync( return await _channelApi.CreateMessageResultAsync(
GuildSettings.PrivateFeedbackChannel.Get(cfg), embeds: new[] { built }, GuildSettings.PrivateFeedbackChannel.Get(cfg), embeds: new[] { built },
allowedMentions: Octobot.NoMentions, ct: ct); allowedMentions: Octobot.NoMentions, ct: ct);
} }

View file

@ -231,7 +231,7 @@ public sealed class ScheduledEventUpdateService : BackgroundService
URL: $"https://discord.com/events/{scheduledEvent.GuildID}/{scheduledEvent.ID}" URL: $"https://discord.com/events/{scheduledEvent.GuildID}/{scheduledEvent.ID}"
); );
return (Result)await _channelApi.CreateMessageAsync( return await _channelApi.CreateMessageResultAsync(
GuildSettings.EventNotificationChannel.Get(settings), roleMention, embeds: new[] { built }, GuildSettings.EventNotificationChannel.Get(settings), roleMention, embeds: new[] { built },
components: new[] { new ActionRowComponent(new[] { button }) }, ct: ct); components: new[] { new ActionRowComponent(new[] { button }) }, ct: ct);
} }
@ -322,7 +322,7 @@ public sealed class ScheduledEventUpdateService : BackgroundService
return Result.FromError(startedEmbed); return Result.FromError(startedEmbed);
} }
return (Result)await _channelApi.CreateMessageAsync( return await _channelApi.CreateMessageResultAsync(
GuildSettings.EventNotificationChannel.Get(data.Settings), GuildSettings.EventNotificationChannel.Get(data.Settings),
content, embeds: new[] { startedBuilt }, ct: ct); content, embeds: new[] { startedBuilt }, ct: ct);
} }
@ -353,7 +353,7 @@ public sealed class ScheduledEventUpdateService : BackgroundService
return Result.FromError(completedEmbed); return Result.FromError(completedEmbed);
} }
var createResult = (Result)await _channelApi.CreateMessageAsync( var createResult = await _channelApi.CreateMessageResultAsync(
GuildSettings.EventNotificationChannel.Get(data.Settings), GuildSettings.EventNotificationChannel.Get(data.Settings),
embeds: new[] { completedBuilt }, ct: ct); embeds: new[] { completedBuilt }, ct: ct);
if (createResult.IsSuccess) if (createResult.IsSuccess)
@ -385,7 +385,7 @@ public sealed class ScheduledEventUpdateService : BackgroundService
return Result.FromError(embed); return Result.FromError(embed);
} }
var createResult = (Result)await _channelApi.CreateMessageAsync( var createResult = await _channelApi.CreateMessageResultAsync(
GuildSettings.EventNotificationChannel.Get(data.Settings), embeds: new[] { built }, ct: ct); GuildSettings.EventNotificationChannel.Get(data.Settings), embeds: new[] { built }, ct: ct);
if (createResult.IsSuccess) if (createResult.IsSuccess)
{ {
@ -450,7 +450,7 @@ public sealed class ScheduledEventUpdateService : BackgroundService
return Result.FromError(earlyResult); return Result.FromError(earlyResult);
} }
return (Result)await _channelApi.CreateMessageAsync( return await _channelApi.CreateMessageResultAsync(
GuildSettings.EventNotificationChannel.Get(data.Settings), GuildSettings.EventNotificationChannel.Get(data.Settings),
content, content,
embeds: new[] { earlyBuilt }, ct: ct); embeds: new[] { earlyBuilt }, ct: ct);