Browse Source

[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
pull/2572/head
SaculRennorb GitHub 2 years ago
parent
commit
493f604bb1
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 12 deletions
  1. +4
    -4
      src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/ScheduledEventInfo.cs
  2. +5
    -8
      src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/ScheduledEventUpdateAuditLogData.cs

+ 4
- 4
src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/ScheduledEventInfo.cs View File

@@ -12,7 +12,7 @@ namespace Discord.Rest
/// </summary>
public ulong? GuildId { get; }
/// <summary>
/// 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.
/// </summary>
public ulong? ChannelId { get; }
/// <summary>
@@ -48,9 +48,9 @@ namespace Discord.Rest
/// </summary>
public ulong? EntityId { get; }
/// <summary>
/// Gets the metadata for the entity associated with the event.
/// Gets the metadata for the entity associated with the event. <see cref="Optional{T}.Unspecified"/> if there was no change.
/// </summary>
public string Location { get; }
public Optional<string> Location { get; }
/// <summary>
/// Gets the count of users interested in this event.
/// </summary>
@@ -60,7 +60,7 @@ namespace Discord.Rest
/// </summary>
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<string> location, int? userCount, string image)
{
GuildId = guildId ;
ChannelId = channelId ;


+ 5
- 8
src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/ScheduledEventUpdateAuditLogData.cs View File

@@ -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<ulong>(discord.ApiClient.Serializer),
channelId?.OldValue.ToObject<ulong?>(discord.ApiClient.Serializer),
channelId == null ? null : channelId.OldValue?.ToObject<ulong?>(discord.ApiClient.Serializer) ?? 0,
name?.OldValue.ToObject<string>(discord.ApiClient.Serializer),
description?.OldValue.ToObject<Optional<string>>(discord.ApiClient.Serializer)
.GetValueOrDefault(),
@@ -51,8 +50,7 @@ namespace Discord.Rest
status?.OldValue.ToObject<GuildScheduledEventStatus>(discord.ApiClient.Serializer),
entityType?.OldValue.ToObject<GuildScheduledEventType>(discord.ApiClient.Serializer),
entityId?.OldValue.ToObject<ulong?>(discord.ApiClient.Serializer),
entityMetadata?.OldValue.ToObject<GuildScheduledEventEntityMetadata>(discord.ApiClient.Serializer)
?.Location.GetValueOrDefault(),
location == null ? Optional<string>.Unspecified : new Optional<string>(location.OldValue?.ToObject<string>(discord.ApiClient.Serializer)),
userCount?.OldValue.ToObject<Optional<int>>(discord.ApiClient.Serializer)
.GetValueOrDefault(),
image?.OldValue.ToObject<Optional<string>>(discord.ApiClient.Serializer)
@@ -60,7 +58,7 @@ namespace Discord.Rest
);
var after = new ScheduledEventInfo(
guildId?.NewValue.ToObject<ulong>(discord.ApiClient.Serializer),
channelId?.NewValue.ToObject<ulong?>(discord.ApiClient.Serializer),
channelId == null ? null : channelId.NewValue?.ToObject<ulong?>(discord.ApiClient.Serializer) ?? 0,
name?.NewValue.ToObject<string>(discord.ApiClient.Serializer),
description?.NewValue.ToObject<Optional<string>>(discord.ApiClient.Serializer)
.GetValueOrDefault(),
@@ -70,8 +68,7 @@ namespace Discord.Rest
status?.NewValue.ToObject<GuildScheduledEventStatus>(discord.ApiClient.Serializer),
entityType?.NewValue.ToObject<GuildScheduledEventType>(discord.ApiClient.Serializer),
entityId?.NewValue.ToObject<ulong?>(discord.ApiClient.Serializer),
entityMetadata?.NewValue.ToObject<GuildScheduledEventEntityMetadata>(discord.ApiClient.Serializer)
?.Location.GetValueOrDefault(),
location == null ? Optional<string>.Unspecified : new Optional<string>(location.NewValue?.ToObject<string>(discord.ApiClient.Serializer)),
userCount?.NewValue.ToObject<Optional<int>>(discord.ApiClient.Serializer)
.GetValueOrDefault(),
image?.NewValue.ToObject<Optional<string>>(discord.ApiClient.Serializer)


Loading…
Cancel
Save