parent
6d2880ce26
commit
91f4f02a35
@ -1,33 +1,36 @@
|
|||||||
using System.Linq;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using CliFx;
|
using CliFx;
|
||||||
using CliFx.Attributes;
|
using CliFx.Attributes;
|
||||||
using DiscordChatExporter.Cli.Commands.Base;
|
using DiscordChatExporter.Cli.Commands.Base;
|
||||||
using DiscordChatExporter.Domain.Discord.Models;
|
using DiscordChatExporter.Domain.Discord.Models;
|
||||||
using DiscordChatExporter.Domain.Utilities;
|
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Commands
|
namespace DiscordChatExporter.Cli.Commands
|
||||||
{
|
{
|
||||||
[Command("exportall", Description = "Export all direct messages and all channels within all guilds.")]
|
[Command("exportall", Description = "Export all accessible channels.")]
|
||||||
public class ExportAllCommand : ExportMultipleCommandBase
|
public class ExportAllCommand : ExportMultipleCommandBase
|
||||||
{
|
{
|
||||||
[CommandOption("exclude-dm", 'e', Description = "If this flag is present, direct messages will not be exported.")]
|
[CommandOption("include-dm", Description = "Whether to also export direct message channels.")]
|
||||||
public bool ExcludeDMs { get; set; }
|
public bool IncludeDirectMessages { get; set; } = true;
|
||||||
|
|
||||||
public override async ValueTask ExecuteAsync(IConsole console)
|
public override async ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
|
var channels = new List<Channel>();
|
||||||
|
|
||||||
if(!ExcludeDMs){
|
// Aggregate channels from all guilds
|
||||||
var dmChannels = await GetDiscordClient().GetGuildChannelsAsync(Guild.DirectMessages.Id);
|
await foreach (var guild in GetDiscordClient().GetUserGuildsAsync())
|
||||||
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);
|
// Skip DMs if instructed to
|
||||||
await ExportMultipleAsync(console, guildChannels);
|
if (!IncludeDirectMessages && guild.Id == Guild.DirectMessages.Id)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
await foreach (var channel in GetDiscordClient().GetGuildChannelsAsync(guild.Id))
|
||||||
|
{
|
||||||
|
channels.Add(channel);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await ExportMultipleAsync(console, channels);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in new issue