mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-05-10 07:53:15 +03:00
Add ChannelApiExtensions (#217)
This PR adds an extension method to make it easier to pass Result<Embed> to CreateMessageAsync --------- Co-authored-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
parent
9a23e1d533
commit
541e18fff0
10 changed files with 64 additions and 102 deletions
|
@ -236,16 +236,11 @@ public sealed partial class MemberUpdateService : BackgroundService
|
|||
.WithColour(ColorsList.Magenta)
|
||||
.Build();
|
||||
|
||||
if (!embed.IsDefined(out var built))
|
||||
{
|
||||
return Result.FromError(embed);
|
||||
}
|
||||
|
||||
var messageResult = await _channelApi.CreateMessageAsync(
|
||||
reminder.ChannelId.ToSnowflake(), Mention.User(user), embeds: new[] { built }, ct: ct);
|
||||
var messageResult = await _channelApi.CreateMessageWithEmbedResultAsync(
|
||||
reminder.ChannelId.ToSnowflake(), Mention.User(user), embedResult: embed, ct: ct);
|
||||
if (!messageResult.IsSuccess)
|
||||
{
|
||||
return Result.FromError(messageResult);
|
||||
return messageResult;
|
||||
}
|
||||
|
||||
data.Reminders.Remove(reminder);
|
||||
|
|
|
@ -215,10 +215,6 @@ public sealed class ScheduledEventUpdateService : BackgroundService
|
|||
.WithCurrentTimestamp()
|
||||
.WithColour(ColorsList.White)
|
||||
.Build();
|
||||
if (!embed.IsDefined(out var built))
|
||||
{
|
||||
return Result.FromError(embed);
|
||||
}
|
||||
|
||||
var roleMention = !GuildSettings.EventNotificationRole.Get(settings).Empty()
|
||||
? Mention.Role(GuildSettings.EventNotificationRole.Get(settings))
|
||||
|
@ -231,8 +227,8 @@ public sealed class ScheduledEventUpdateService : BackgroundService
|
|||
URL: $"https://discord.com/events/{scheduledEvent.GuildID}/{scheduledEvent.ID}"
|
||||
);
|
||||
|
||||
return (Result)await _channelApi.CreateMessageAsync(
|
||||
GuildSettings.EventNotificationChannel.Get(settings), roleMention, embeds: new[] { built },
|
||||
return await _channelApi.CreateMessageWithEmbedResultAsync(
|
||||
GuildSettings.EventNotificationChannel.Get(settings), roleMention, embedResult: embed,
|
||||
components: new[] { new ActionRowComponent(new[] { button }) }, ct: ct);
|
||||
}
|
||||
|
||||
|
@ -317,14 +313,9 @@ public sealed class ScheduledEventUpdateService : BackgroundService
|
|||
.WithCurrentTimestamp()
|
||||
.Build();
|
||||
|
||||
if (!startedEmbed.IsDefined(out var startedBuilt))
|
||||
{
|
||||
return Result.FromError(startedEmbed);
|
||||
}
|
||||
|
||||
return (Result)await _channelApi.CreateMessageAsync(
|
||||
return await _channelApi.CreateMessageWithEmbedResultAsync(
|
||||
GuildSettings.EventNotificationChannel.Get(data.Settings),
|
||||
content, embeds: new[] { startedBuilt }, ct: ct);
|
||||
content, embedResult: startedEmbed, ct: ct);
|
||||
}
|
||||
|
||||
private async Task<Result> SendScheduledEventCompletedMessage(ScheduledEventData eventData, GuildData data,
|
||||
|
@ -348,14 +339,9 @@ public sealed class ScheduledEventUpdateService : BackgroundService
|
|||
.WithCurrentTimestamp()
|
||||
.Build();
|
||||
|
||||
if (!completedEmbed.IsDefined(out var completedBuilt))
|
||||
{
|
||||
return Result.FromError(completedEmbed);
|
||||
}
|
||||
|
||||
var createResult = (Result)await _channelApi.CreateMessageAsync(
|
||||
var createResult = await _channelApi.CreateMessageWithEmbedResultAsync(
|
||||
GuildSettings.EventNotificationChannel.Get(data.Settings),
|
||||
embeds: new[] { completedBuilt }, ct: ct);
|
||||
embedResult: completedEmbed, ct: ct);
|
||||
if (createResult.IsSuccess)
|
||||
{
|
||||
data.ScheduledEvents.Remove(eventData.Id);
|
||||
|
@ -380,13 +366,8 @@ public sealed class ScheduledEventUpdateService : BackgroundService
|
|||
.WithCurrentTimestamp()
|
||||
.Build();
|
||||
|
||||
if (!embed.IsDefined(out var built))
|
||||
{
|
||||
return Result.FromError(embed);
|
||||
}
|
||||
|
||||
var createResult = (Result)await _channelApi.CreateMessageAsync(
|
||||
GuildSettings.EventNotificationChannel.Get(data.Settings), embeds: new[] { built }, ct: ct);
|
||||
var createResult = await _channelApi.CreateMessageWithEmbedResultAsync(
|
||||
GuildSettings.EventNotificationChannel.Get(data.Settings), embedResult: embed, ct: ct);
|
||||
if (createResult.IsSuccess)
|
||||
{
|
||||
data.ScheduledEvents.Remove(eventData.Id);
|
||||
|
@ -445,14 +426,9 @@ public sealed class ScheduledEventUpdateService : BackgroundService
|
|||
.WithColour(ColorsList.Default)
|
||||
.Build();
|
||||
|
||||
if (!earlyResult.IsDefined(out var earlyBuilt))
|
||||
{
|
||||
return Result.FromError(earlyResult);
|
||||
}
|
||||
|
||||
return (Result)await _channelApi.CreateMessageAsync(
|
||||
return await _channelApi.CreateMessageWithEmbedResultAsync(
|
||||
GuildSettings.EventNotificationChannel.Get(data.Settings),
|
||||
content,
|
||||
embeds: new[] { earlyBuilt }, ct: ct);
|
||||
embedResult: earlyResult, ct: ct);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -226,26 +226,19 @@ public sealed class UtilityService : IHostedService
|
|||
.WithColour(color)
|
||||
.Build();
|
||||
|
||||
if (!logEmbed.IsDefined(out var logBuilt))
|
||||
{
|
||||
return Result.FromError(logEmbed);
|
||||
}
|
||||
|
||||
var builtArray = new[] { logBuilt };
|
||||
|
||||
// Not awaiting to reduce response time
|
||||
if (isPublic && publicChannel != channelId)
|
||||
{
|
||||
_ = _channelApi.CreateMessageAsync(
|
||||
publicChannel, embeds: builtArray,
|
||||
_ = _channelApi.CreateMessageWithEmbedResultAsync(
|
||||
publicChannel, embedResult: logEmbed,
|
||||
ct: ct);
|
||||
}
|
||||
|
||||
if (privateChannel != publicChannel
|
||||
&& privateChannel != channelId)
|
||||
{
|
||||
_ = _channelApi.CreateMessageAsync(
|
||||
privateChannel, embeds: builtArray,
|
||||
_ = _channelApi.CreateMessageWithEmbedResultAsync(
|
||||
privateChannel, embedResult: logEmbed,
|
||||
ct: ct);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue