From 6d2880ce26d5e1bd0ccb7d803784643df092f7bb Mon Sep 17 00:00:00 2001 From: wyattscarpenter Date: Fri, 4 Sep 2020 16:23:06 -0500 Subject: [PATCH] [CLI] Add command to export all channels across all guilds (#373) --- .../Commands/ExportAllCommand.cs | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 DiscordChatExporter.Cli/Commands/ExportAllCommand.cs diff --git a/DiscordChatExporter.Cli/Commands/ExportAllCommand.cs b/DiscordChatExporter.Cli/Commands/ExportAllCommand.cs new file mode 100644 index 0000000..8e79241 --- /dev/null +++ b/DiscordChatExporter.Cli/Commands/ExportAllCommand.cs @@ -0,0 +1,33 @@ +using System.Linq; +using System.Threading.Tasks; +using CliFx; +using CliFx.Attributes; +using DiscordChatExporter.Cli.Commands.Base; +using DiscordChatExporter.Domain.Discord.Models; +using DiscordChatExporter.Domain.Utilities; + +namespace DiscordChatExporter.Cli.Commands +{ + [Command("exportall", Description = "Export all direct messages and all channels within all guilds.")] + public class ExportAllCommand : ExportMultipleCommandBase + { + [CommandOption("exclude-dm", 'e', Description = "If this flag is present, direct messages will not be exported.")] + public bool ExcludeDMs { get; set; } + + public override async ValueTask ExecuteAsync(IConsole console) + { + + if(!ExcludeDMs){ + var dmChannels = await GetDiscordClient().GetGuildChannelsAsync(Guild.DirectMessages.Id); + await ExportMultipleAsync(console, dmChannels); + } + + var guilds = await GetDiscordClient().GetUserGuildsAsync(); + foreach (var guild in guilds.OrderBy(g => g.Name)) + { + var guildChannels = await GetDiscordClient().GetGuildChannelsAsync(guild.Id); + await ExportMultipleAsync(console, guildChannels); + } + } + } +}