Do not try to send messages in empty EventNotificationChannels ()

This PR fixes an error that would occur if an event was created, was
about to start or started and the EventNotificationChannel was empty.
This commit is contained in:
Octol1ttle 2023-10-17 17:23:14 +05:00 committed by GitHub
parent b30d690113
commit 580cd24810
Signed by: GitHub
GPG key ID: 4AEE18F83AFDEB23

View file

@ -177,6 +177,11 @@ public sealed class ScheduledEventUpdateService : BackgroundService
private async Task<Result> SendScheduledEventCreatedMessage( private async Task<Result> SendScheduledEventCreatedMessage(
IGuildScheduledEvent scheduledEvent, JsonNode settings, CancellationToken ct = default) IGuildScheduledEvent scheduledEvent, JsonNode settings, CancellationToken ct = default)
{ {
if (GuildSettings.EventNotificationChannel.Get(settings).Empty())
{
return Result.FromSuccess();
}
if (!scheduledEvent.Creator.IsDefined(out var creator)) if (!scheduledEvent.Creator.IsDefined(out var creator))
{ {
return new ArgumentNullError(nameof(scheduledEvent.Creator)); return new ArgumentNullError(nameof(scheduledEvent.Creator));
@ -277,6 +282,11 @@ public sealed class ScheduledEventUpdateService : BackgroundService
{ {
data.ScheduledEvents[scheduledEvent.ID.Value].ActualStartTime = DateTimeOffset.UtcNow; data.ScheduledEvents[scheduledEvent.ID.Value].ActualStartTime = DateTimeOffset.UtcNow;
if (GuildSettings.EventNotificationChannel.Get(data.Settings).Empty())
{
return Result.FromSuccess();
}
var embedDescriptionResult = scheduledEvent.EntityType switch var embedDescriptionResult = scheduledEvent.EntityType switch
{ {
GuildScheduledEventEntityType.StageInstance or GuildScheduledEventEntityType.Voice => GuildScheduledEventEntityType.StageInstance or GuildScheduledEventEntityType.Voice =>
@ -297,7 +307,8 @@ public sealed class ScheduledEventUpdateService : BackgroundService
return Result.FromError(embedDescriptionResult); return Result.FromError(embedDescriptionResult);
} }
var startedEmbed = new EmbedBuilder().WithTitle(string.Format(Messages.EventStarted, Markdown.Sanitize(scheduledEvent.Name))) var startedEmbed = new EmbedBuilder()
.WithTitle(string.Format(Messages.EventStarted, Markdown.Sanitize(scheduledEvent.Name)))
.WithDescription(embedDescription) .WithDescription(embedDescription)
.WithColour(ColorsList.Green) .WithColour(ColorsList.Green)
.WithCurrentTimestamp() .WithCurrentTimestamp()
@ -322,7 +333,8 @@ public sealed class ScheduledEventUpdateService : BackgroundService
return Result.FromSuccess(); return Result.FromSuccess();
} }
var completedEmbed = new EmbedBuilder().WithTitle(string.Format(Messages.EventCompleted, Markdown.Sanitize(eventData.Name))) var completedEmbed = new EmbedBuilder()
.WithTitle(string.Format(Messages.EventCompleted, Markdown.Sanitize(eventData.Name)))
.WithDescription( .WithDescription(
string.Format( string.Format(
Messages.EventDuration, Messages.EventDuration,
@ -411,6 +423,11 @@ public sealed class ScheduledEventUpdateService : BackgroundService
private async Task<Result> SendEarlyEventNotificationAsync( private async Task<Result> SendEarlyEventNotificationAsync(
IGuildScheduledEvent scheduledEvent, GuildData data, CancellationToken ct) IGuildScheduledEvent scheduledEvent, GuildData data, CancellationToken ct)
{ {
if (GuildSettings.EventNotificationChannel.Get(data.Settings).Empty())
{
return Result.FromSuccess();
}
var contentResult = await _utility.GetEventNotificationMentions( var contentResult = await _utility.GetEventNotificationMentions(
scheduledEvent, data, ct); scheduledEvent, data, ct);
if (!contentResult.IsDefined(out var content)) if (!contentResult.IsDefined(out var content))