forked from TeamInklings/Octobot
Add a JSON deserialization constructor for ScheduledEventData (#92)
This PR fixes an exception that would occur when deserialization of ScheduledEventData would be attempted. The exception is fixed by providing a constructor containing all properties and adding the `[JsonConstructor]` attribute. Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
parent
ef5410b7bb
commit
0bf61ecf39
3 changed files with 19 additions and 5 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
using Remora.Discord.API.Abstractions.Objects;
|
using Remora.Discord.API.Abstractions.Objects;
|
||||||
|
|
||||||
namespace Boyfriend.Data;
|
namespace Boyfriend.Data;
|
||||||
|
@ -8,13 +9,26 @@ namespace Boyfriend.Data;
|
||||||
/// <remarks>This information is stored on disk as a JSON file.</remarks>
|
/// <remarks>This information is stored on disk as a JSON file.</remarks>
|
||||||
public sealed class ScheduledEventData
|
public sealed class ScheduledEventData
|
||||||
{
|
{
|
||||||
public ScheduledEventData(ulong id, string name, GuildScheduledEventStatus status,
|
public ScheduledEventData(ulong id, string name, DateTimeOffset scheduledStartTime,
|
||||||
DateTimeOffset scheduledStartTime)
|
GuildScheduledEventStatus status)
|
||||||
{
|
{
|
||||||
Id = id;
|
Id = id;
|
||||||
Name = name;
|
Name = name;
|
||||||
Status = status;
|
|
||||||
ScheduledStartTime = scheduledStartTime;
|
ScheduledStartTime = scheduledStartTime;
|
||||||
|
Status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
[JsonConstructor]
|
||||||
|
public ScheduledEventData(ulong id, string name, bool earlyNotificationSent, DateTimeOffset scheduledStartTime,
|
||||||
|
DateTimeOffset? actualStartTime, GuildScheduledEventStatus? status, bool scheduleOnStatusUpdated)
|
||||||
|
{
|
||||||
|
Id = id;
|
||||||
|
Name = name;
|
||||||
|
EarlyNotificationSent = earlyNotificationSent;
|
||||||
|
ScheduledStartTime = scheduledStartTime;
|
||||||
|
ActualStartTime = actualStartTime;
|
||||||
|
Status = status;
|
||||||
|
ScheduleOnStatusUpdated = scheduleOnStatusUpdated;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ulong Id { get; }
|
public ulong Id { get; }
|
||||||
|
|
|
@ -55,7 +55,7 @@ public class GuildLoadedResponder : IResponder<IGuildCreate>
|
||||||
if (!data.ScheduledEvents.TryGetValue(schEvent.ID.Value, out var eventData))
|
if (!data.ScheduledEvents.TryGetValue(schEvent.ID.Value, out var eventData))
|
||||||
{
|
{
|
||||||
data.ScheduledEvents.Add(schEvent.ID.Value, new ScheduledEventData(schEvent.ID.Value,
|
data.ScheduledEvents.Add(schEvent.ID.Value, new ScheduledEventData(schEvent.ID.Value,
|
||||||
schEvent.Name, schEvent.Status, schEvent.ScheduledStartTime));
|
schEvent.Name, schEvent.ScheduledStartTime, schEvent.Status));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ public class ScheduledEventCreatedResponder : IResponder<IGuildScheduledEventCre
|
||||||
var data = await _guildData.GetData(gatewayEvent.GuildID, ct);
|
var data = await _guildData.GetData(gatewayEvent.GuildID, ct);
|
||||||
data.ScheduledEvents.Add(gatewayEvent.ID.Value,
|
data.ScheduledEvents.Add(gatewayEvent.ID.Value,
|
||||||
new ScheduledEventData(gatewayEvent.ID.Value,
|
new ScheduledEventData(gatewayEvent.ID.Value,
|
||||||
gatewayEvent.Name, gatewayEvent.Status, gatewayEvent.ScheduledStartTime));
|
gatewayEvent.Name, gatewayEvent.ScheduledStartTime, gatewayEvent.Status));
|
||||||
|
|
||||||
return Result.FromSuccess();
|
return Result.FromSuccess();
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue