From 493f604bb1fed2182e98c184c8e44b4c9cb2f536 Mon Sep 17 00:00:00 2001
From: SaculRennorb <18741506+SaculRennorb@users.noreply.github.com>
Date: Sat, 21 Jan 2023 11:53:58 +0100
Subject: [PATCH] [Bugfix] fixed an NRE when event was changed from in channel
to external or vice versa (#2483)
* fixed an issue when event was cahnged from in channel to external or vice versa
* simplidied location field
---
.../AuditLogs/DataTypes/ScheduledEventInfo.cs | 8 ++++----
.../DataTypes/ScheduledEventUpdateAuditLogData.cs | 13 +++++--------
2 files changed, 9 insertions(+), 12 deletions(-)
diff --git a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/ScheduledEventInfo.cs b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/ScheduledEventInfo.cs
index a45956546..98112edb9 100644
--- a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/ScheduledEventInfo.cs
+++ b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/ScheduledEventInfo.cs
@@ -12,7 +12,7 @@ namespace Discord.Rest
///
public ulong? GuildId { get; }
///
- /// Gets the snowflake id of the channel the event is associated with.
+ /// Gets the snowflake id of the channel the event is associated with. 0 for events with external location.
///
public ulong? ChannelId { get; }
///
@@ -48,9 +48,9 @@ namespace Discord.Rest
///
public ulong? EntityId { get; }
///
- /// Gets the metadata for the entity associated with the event.
+ /// Gets the metadata for the entity associated with the event. if there was no change.
///
- public string Location { get; }
+ public Optional Location { get; }
///
/// Gets the count of users interested in this event.
///
@@ -60,7 +60,7 @@ namespace Discord.Rest
///
public string Image { get; }
- internal ScheduledEventInfo(ulong? guildId, ulong? channelId, string name, string description, DateTimeOffset? scheduledStartTime, DateTimeOffset? scheduledEndTime, GuildScheduledEventPrivacyLevel? privacyLevel, GuildScheduledEventStatus? status, GuildScheduledEventType? entityType, ulong? entityId, string location, int? userCount, string image)
+ internal ScheduledEventInfo(ulong? guildId, ulong? channelId, string name, string description, DateTimeOffset? scheduledStartTime, DateTimeOffset? scheduledEndTime, GuildScheduledEventPrivacyLevel? privacyLevel, GuildScheduledEventStatus? status, GuildScheduledEventType? entityType, ulong? entityId, Optional location, int? userCount, string image)
{
GuildId = guildId ;
ChannelId = channelId ;
diff --git a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/ScheduledEventUpdateAuditLogData.cs b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/ScheduledEventUpdateAuditLogData.cs
index 2ef2ccff8..042cfd1c7 100644
--- a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/ScheduledEventUpdateAuditLogData.cs
+++ b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/ScheduledEventUpdateAuditLogData.cs
@@ -1,6 +1,5 @@
using System;
using System.Linq;
-using Discord.API;
using Model = Discord.API.AuditLog;
using EntryModel = Discord.API.AuditLogEntry;
@@ -35,13 +34,13 @@ namespace Discord.Rest
var status = entry.Changes.FirstOrDefault(x => x.ChangedProperty == "status");
var entityType = entry.Changes.FirstOrDefault(x => x.ChangedProperty == "entity_type");
var entityId = entry.Changes.FirstOrDefault(x => x.ChangedProperty == "entity_id");
- var entityMetadata = entry.Changes.FirstOrDefault(x => x.ChangedProperty == "entity_metadata");
+ var location = entry.Changes.FirstOrDefault(x => x.ChangedProperty == "location");
var userCount = entry.Changes.FirstOrDefault(x => x.ChangedProperty == "user_count");
var image = entry.Changes.FirstOrDefault(x => x.ChangedProperty == "image");
var before = new ScheduledEventInfo(
guildId?.OldValue.ToObject(discord.ApiClient.Serializer),
- channelId?.OldValue.ToObject(discord.ApiClient.Serializer),
+ channelId == null ? null : channelId.OldValue?.ToObject(discord.ApiClient.Serializer) ?? 0,
name?.OldValue.ToObject(discord.ApiClient.Serializer),
description?.OldValue.ToObject>(discord.ApiClient.Serializer)
.GetValueOrDefault(),
@@ -51,8 +50,7 @@ namespace Discord.Rest
status?.OldValue.ToObject(discord.ApiClient.Serializer),
entityType?.OldValue.ToObject(discord.ApiClient.Serializer),
entityId?.OldValue.ToObject(discord.ApiClient.Serializer),
- entityMetadata?.OldValue.ToObject(discord.ApiClient.Serializer)
- ?.Location.GetValueOrDefault(),
+ location == null ? Optional.Unspecified : new Optional(location.OldValue?.ToObject(discord.ApiClient.Serializer)),
userCount?.OldValue.ToObject>(discord.ApiClient.Serializer)
.GetValueOrDefault(),
image?.OldValue.ToObject>(discord.ApiClient.Serializer)
@@ -60,7 +58,7 @@ namespace Discord.Rest
);
var after = new ScheduledEventInfo(
guildId?.NewValue.ToObject(discord.ApiClient.Serializer),
- channelId?.NewValue.ToObject(discord.ApiClient.Serializer),
+ channelId == null ? null : channelId.NewValue?.ToObject(discord.ApiClient.Serializer) ?? 0,
name?.NewValue.ToObject(discord.ApiClient.Serializer),
description?.NewValue.ToObject>(discord.ApiClient.Serializer)
.GetValueOrDefault(),
@@ -70,8 +68,7 @@ namespace Discord.Rest
status?.NewValue.ToObject(discord.ApiClient.Serializer),
entityType?.NewValue.ToObject(discord.ApiClient.Serializer),
entityId?.NewValue.ToObject(discord.ApiClient.Serializer),
- entityMetadata?.NewValue.ToObject(discord.ApiClient.Serializer)
- ?.Location.GetValueOrDefault(),
+ location == null ? Optional.Unspecified : new Optional(location.NewValue?.ToObject(discord.ApiClient.Serializer)),
userCount?.NewValue.ToObject>(discord.ApiClient.Serializer)
.GetValueOrDefault(),
image?.NewValue.ToObject>(discord.ApiClient.Serializer)