From 97e585572d8ffbe34a3790fe6e546f8d945d2b0c Mon Sep 17 00:00:00 2001 From: Rennorb Date: Mon, 26 Sep 2022 19:58:06 +0200 Subject: [PATCH] fixed an issue when event was cahnged from in channel to external or vice versa --- .../AuditLogs/DataTypes/ScheduledEventInfo.cs | 6 +++--- .../DataTypes/ScheduledEventUpdateAuditLogData.cs | 13 ++++++------- 2 files changed, 9 insertions(+), 10 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..20a17b8b3 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; } /// @@ -50,7 +50,7 @@ namespace Discord.Rest /// /// Gets the metadata for the entity associated with the event. /// - 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..2ea970780 100644 --- a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/ScheduledEventUpdateAuditLogData.cs +++ b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/ScheduledEventUpdateAuditLogData.cs @@ -4,6 +4,7 @@ using Discord.API; using Model = Discord.API.AuditLog; using EntryModel = Discord.API.AuditLogEntry; +using Newtonsoft.Json.Linq; namespace Discord.Rest { @@ -35,13 +36,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 +52,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 ? null : location.OldValue?.ToObject(discord.ApiClient.Serializer) ?? Optional.Unspecified, userCount?.OldValue.ToObject>(discord.ApiClient.Serializer) .GetValueOrDefault(), image?.OldValue.ToObject>(discord.ApiClient.Serializer) @@ -60,7 +60,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 +70,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 ? null : location.NewValue?.ToObject(discord.ApiClient.Serializer) ?? Optional.Unspecified, userCount?.NewValue.ToObject>(discord.ApiClient.Serializer) .GetValueOrDefault(), image?.NewValue.ToObject>(discord.ApiClient.Serializer)