2023-10-12 18:37:25 +03:00
|
|
|
|
using Remora.Discord.API.Abstractions.Objects;
|
|
|
|
|
using Remora.Rest.Core;
|
|
|
|
|
using Remora.Results;
|
|
|
|
|
|
2024-05-16 18:34:26 +03:00
|
|
|
|
namespace TeamOctolings.Octobot.Extensions;
|
2023-10-12 18:37:25 +03:00
|
|
|
|
|
|
|
|
|
public static class GuildScheduledEventExtensions
|
|
|
|
|
{
|
|
|
|
|
public static Result TryGetExternalEventData(this IGuildScheduledEvent scheduledEvent, out DateTimeOffset endTime,
|
|
|
|
|
out string? location)
|
|
|
|
|
{
|
|
|
|
|
endTime = default;
|
|
|
|
|
location = default;
|
|
|
|
|
if (!scheduledEvent.EntityMetadata.AsOptional().IsDefined(out var metadata))
|
|
|
|
|
{
|
|
|
|
|
return new ArgumentNullError(nameof(scheduledEvent.EntityMetadata));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!metadata.Location.IsDefined(out location))
|
|
|
|
|
{
|
|
|
|
|
return new ArgumentNullError(nameof(metadata.Location));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return scheduledEvent.ScheduledEndTime.AsOptional().IsDefined(out endTime)
|
2024-03-21 18:55:34 +03:00
|
|
|
|
? Result.Success
|
2023-10-12 18:37:25 +03:00
|
|
|
|
: new ArgumentNullError(nameof(scheduledEvent.ScheduledEndTime));
|
|
|
|
|
}
|
|
|
|
|
}
|