From 6c039ebfa6023e7a0e8649b7a34f4b9ed2c11f9f Mon Sep 17 00:00:00 2001 From: Oleksii Holub <1935960+Tyrrrz@users.noreply.github.com> Date: Fri, 19 Aug 2022 18:39:11 +0300 Subject: [PATCH] Filter out categories when displaying channels --- .../Commands/ExportDirectMessagesCommand.cs | 8 ++++++-- DiscordChatExporter.Cli/Commands/ExportGuildCommand.cs | 9 +++++++-- DiscordChatExporter.Cli/Commands/GetChannelsCommand.cs | 2 ++ .../Commands/GetDirectMessageChannelsCommand.cs | 1 + .../ViewModels/Components/DashboardViewModel.cs | 6 +++++- 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/DiscordChatExporter.Cli/Commands/ExportDirectMessagesCommand.cs b/DiscordChatExporter.Cli/Commands/ExportDirectMessagesCommand.cs index 608adcbf..a7ab35dc 100644 --- a/DiscordChatExporter.Cli/Commands/ExportDirectMessagesCommand.cs +++ b/DiscordChatExporter.Cli/Commands/ExportDirectMessagesCommand.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System.Linq; +using System.Threading.Tasks; using CliFx.Attributes; using CliFx.Infrastructure; using DiscordChatExporter.Cli.Commands.Base; @@ -17,7 +18,10 @@ public class ExportDirectMessagesCommand : ExportCommandBase var cancellationToken = console.RegisterCancellationHandler(); await console.Output.WriteLineAsync("Fetching channels..."); - var channels = await Discord.GetGuildChannelsAsync(Guild.DirectMessages.Id, cancellationToken); + + var channels = (await Discord.GetGuildChannelsAsync(Guild.DirectMessages.Id, cancellationToken)) + .Where(c => c.Kind != ChannelKind.GuildCategory) + .ToArray(); await base.ExecuteAsync(console, channels); } diff --git a/DiscordChatExporter.Cli/Commands/ExportGuildCommand.cs b/DiscordChatExporter.Cli/Commands/ExportGuildCommand.cs index be9fc016..77f43778 100644 --- a/DiscordChatExporter.Cli/Commands/ExportGuildCommand.cs +++ b/DiscordChatExporter.Cli/Commands/ExportGuildCommand.cs @@ -1,8 +1,10 @@ -using System.Threading.Tasks; +using System.Linq; +using System.Threading.Tasks; using CliFx.Attributes; using CliFx.Infrastructure; using DiscordChatExporter.Cli.Commands.Base; using DiscordChatExporter.Core.Discord; +using DiscordChatExporter.Core.Discord.Data; using DiscordChatExporter.Core.Utils.Extensions; namespace DiscordChatExporter.Cli.Commands; @@ -25,7 +27,10 @@ public class ExportGuildCommand : ExportCommandBase var cancellationToken = console.RegisterCancellationHandler(); await console.Output.WriteLineAsync("Fetching channels..."); - var channels = await Discord.GetGuildChannelsAsync(GuildId, cancellationToken); + + var channels = (await Discord.GetGuildChannelsAsync(GuildId, cancellationToken)) + .Where(c => c.Kind != ChannelKind.GuildCategory) + .ToArray(); await base.ExecuteAsync(console, channels); } diff --git a/DiscordChatExporter.Cli/Commands/GetChannelsCommand.cs b/DiscordChatExporter.Cli/Commands/GetChannelsCommand.cs index 1ff1d080..187ef4ba 100644 --- a/DiscordChatExporter.Cli/Commands/GetChannelsCommand.cs +++ b/DiscordChatExporter.Cli/Commands/GetChannelsCommand.cs @@ -5,6 +5,7 @@ using CliFx.Attributes; using CliFx.Infrastructure; using DiscordChatExporter.Cli.Commands.Base; using DiscordChatExporter.Core.Discord; +using DiscordChatExporter.Core.Discord.Data; using DiscordChatExporter.Core.Utils.Extensions; namespace DiscordChatExporter.Cli.Commands; @@ -25,6 +26,7 @@ public class GetChannelsCommand : TokenCommandBase var cancellationToken = console.RegisterCancellationHandler(); var channels = (await Discord.GetGuildChannelsAsync(GuildId, cancellationToken)) + .Where(c => c.Kind != ChannelKind.GuildCategory) .OrderBy(c => c.Category.Position) .ThenBy(c => c.Name) .ToArray(); diff --git a/DiscordChatExporter.Cli/Commands/GetDirectMessageChannelsCommand.cs b/DiscordChatExporter.Cli/Commands/GetDirectMessageChannelsCommand.cs index 03265d1c..2d7742ab 100644 --- a/DiscordChatExporter.Cli/Commands/GetDirectMessageChannelsCommand.cs +++ b/DiscordChatExporter.Cli/Commands/GetDirectMessageChannelsCommand.cs @@ -17,6 +17,7 @@ public class GetDirectMessageChannelsCommand : TokenCommandBase var cancellationToken = console.RegisterCancellationHandler(); var channels = (await Discord.GetGuildChannelsAsync(Guild.DirectMessages.Id, cancellationToken)) + .Where(c => c.Kind != ChannelKind.GuildCategory) .OrderByDescending(c => c.LastMessageId) .ThenBy(c => c.Name) .ToArray(); diff --git a/DiscordChatExporter.Gui/ViewModels/Components/DashboardViewModel.cs b/DiscordChatExporter.Gui/ViewModels/Components/DashboardViewModel.cs index a0d058f7..2209cd71 100644 --- a/DiscordChatExporter.Gui/ViewModels/Components/DashboardViewModel.cs +++ b/DiscordChatExporter.Gui/ViewModels/Components/DashboardViewModel.cs @@ -105,7 +105,11 @@ public class DashboardViewModel : PropertyChangedBase var guildChannelMap = new Dictionary>(); await foreach (var guild in discord.GetUserGuildsAsync()) - guildChannelMap[guild] = await discord.GetGuildChannelsAsync(guild.Id); + { + guildChannelMap[guild] = (await discord.GetGuildChannelsAsync(guild.Id)) + .Where(c => c.Kind != ChannelKind.GuildCategory) + .ToArray(); + } _discord = discord; GuildChannelMap = guildChannelMap;