From 51192425b712dd1f2e531879a7c01f8dbc3d9f2a Mon Sep 17 00:00:00 2001 From: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com> Date: Sat, 8 Jul 2023 19:21:00 +0300 Subject: [PATCH] Expect channel parents to be null --- DiscordChatExporter.Core/Discord/Data/Channel.cs | 4 ++-- DiscordChatExporter.Core/Discord/Data/ChannelThread.cs | 3 +-- DiscordChatExporter.Core/Discord/Data/Common/IChannel.cs | 4 ++-- DiscordChatExporter.Core/Exporting/ExportRequest.cs | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/DiscordChatExporter.Core/Discord/Data/Channel.cs b/DiscordChatExporter.Core/Discord/Data/Channel.cs index 81b25319..d55f8fcf 100644 --- a/DiscordChatExporter.Core/Discord/Data/Channel.cs +++ b/DiscordChatExporter.Core/Discord/Data/Channel.cs @@ -11,7 +11,7 @@ public partial record Channel( Snowflake Id, ChannelKind Kind, Snowflake GuildId, - Snowflake ParentId, + Snowflake? ParentId, string? ParentName, int? ParentPosition, ChannelCategory Category, @@ -36,7 +36,7 @@ public partial record Channel json.GetPropertyOrNull("guild_id")?.GetNonWhiteSpaceStringOrNull()?.Pipe(Snowflake.Parse) ?? Guild.DirectMessages.Id; - var parentId = json.GetProperty("parent_id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse); + var parentId = json.GetPropertyOrNull("parent_id")?.GetNonWhiteSpaceStringOrNull()?.Pipe(Snowflake.Parse); var category = categoryHint ?? ChannelCategory.CreateDefault(kind); diff --git a/DiscordChatExporter.Core/Discord/Data/ChannelThread.cs b/DiscordChatExporter.Core/Discord/Data/ChannelThread.cs index 412d9233..51070230 100644 --- a/DiscordChatExporter.Core/Discord/Data/ChannelThread.cs +++ b/DiscordChatExporter.Core/Discord/Data/ChannelThread.cs @@ -10,7 +10,7 @@ public record ChannelThread( Snowflake Id, ChannelKind Kind, Snowflake GuildId, - Snowflake ParentId, + Snowflake? ParentId, string? ParentName, string Name, bool IsActive, @@ -29,7 +29,6 @@ public record ChannelThread( var parentId = json.GetProperty("parent_id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse); var name = json.GetProperty("name").GetNonWhiteSpaceString(); - var isActive = !json .GetPropertyOrNull("thread_metadata")? .GetPropertyOrNull("archived")? diff --git a/DiscordChatExporter.Core/Discord/Data/Common/IChannel.cs b/DiscordChatExporter.Core/Discord/Data/Common/IChannel.cs index cba97b5c..2aa36bd2 100644 --- a/DiscordChatExporter.Core/Discord/Data/Common/IChannel.cs +++ b/DiscordChatExporter.Core/Discord/Data/Common/IChannel.cs @@ -4,7 +4,7 @@ public interface IChannel : IHasId { ChannelKind Kind { get; } Snowflake GuildId { get; } - Snowflake ParentId { get; } + Snowflake? ParentId { get; } string? ParentName { get; } int? ParentPosition { get; } string Name { get; } @@ -12,4 +12,4 @@ public interface IChannel : IHasId string? IconUrl { get; } string? Topic { get; } Snowflake? LastMessageId { get; } -} +} \ No newline at end of file diff --git a/DiscordChatExporter.Core/Exporting/ExportRequest.cs b/DiscordChatExporter.Core/Exporting/ExportRequest.cs index 982cf5da..1fd7dcba 100644 --- a/DiscordChatExporter.Core/Exporting/ExportRequest.cs +++ b/DiscordChatExporter.Core/Exporting/ExportRequest.cs @@ -149,7 +149,7 @@ public partial class ExportRequest { "%g" => guild.Id.ToString(), "%G" => guild.Name, - "%t" => channel.ParentId.ToString(), + "%t" => channel.ParentId.ToString() ?? "", "%T" => channel.ParentName ?? "", "%c" => channel.Id.ToString(), "%C" => channel.Name,