mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2025-05-30 06:25:22 -04:00
Add --include-threads
and --include-archived-threads
to exportall
Related to #1119
This commit is contained in:
parent
8236ba7c4d
commit
758fb26dad
3 changed files with 65 additions and 14 deletions
|
@ -34,6 +34,18 @@ public class ExportAllCommand : ExportCommandBase
|
||||||
)]
|
)]
|
||||||
public bool IncludeVoiceChannels { get; init; } = true;
|
public bool IncludeVoiceChannels { get; init; } = true;
|
||||||
|
|
||||||
|
[CommandOption(
|
||||||
|
"include-threads",
|
||||||
|
Description = "Include threads."
|
||||||
|
)]
|
||||||
|
public bool IncludeThreads { get; init; } = false;
|
||||||
|
|
||||||
|
[CommandOption(
|
||||||
|
"include-archived-threads",
|
||||||
|
Description = "Include archived threads."
|
||||||
|
)]
|
||||||
|
public bool IncludeArchivedThreads { get; init; } = false;
|
||||||
|
|
||||||
[CommandOption(
|
[CommandOption(
|
||||||
"data-package",
|
"data-package",
|
||||||
Description =
|
Description =
|
||||||
|
@ -46,6 +58,14 @@ public class ExportAllCommand : ExportCommandBase
|
||||||
{
|
{
|
||||||
await base.ExecuteAsync(console);
|
await base.ExecuteAsync(console);
|
||||||
|
|
||||||
|
// Cannot include archived threads without including active threads as well
|
||||||
|
if (IncludeArchivedThreads && !IncludeThreads)
|
||||||
|
{
|
||||||
|
throw new CommandException(
|
||||||
|
"Option --include-archived-threads can only be used when --include-threads is also specified."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
var cancellationToken = console.RegisterCancellationHandler();
|
var cancellationToken = console.RegisterCancellationHandler();
|
||||||
var channels = new List<Channel>();
|
var channels = new List<Channel>();
|
||||||
|
|
||||||
|
@ -56,10 +76,26 @@ public class ExportAllCommand : ExportCommandBase
|
||||||
|
|
||||||
await foreach (var guild in Discord.GetUserGuildsAsync(cancellationToken))
|
await foreach (var guild in Discord.GetUserGuildsAsync(cancellationToken))
|
||||||
{
|
{
|
||||||
|
// Regular channels
|
||||||
await foreach (var channel in Discord.GetGuildChannelsAsync(guild.Id, cancellationToken))
|
await foreach (var channel in Discord.GetGuildChannelsAsync(guild.Id, cancellationToken))
|
||||||
{
|
{
|
||||||
|
if (channel.Kind == ChannelKind.GuildCategory)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!IncludeVoiceChannels && channel.Kind.IsVoice())
|
||||||
|
continue;
|
||||||
|
|
||||||
channels.Add(channel);
|
channels.Add(channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Threads
|
||||||
|
if (IncludeThreads)
|
||||||
|
{
|
||||||
|
await foreach (var thread in Discord.GetGuildThreadsAsync(guild.Id, IncludeArchivedThreads, cancellationToken))
|
||||||
|
{
|
||||||
|
channels.Add(thread);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Pull from the data package
|
// Pull from the data package
|
||||||
|
@ -105,6 +141,10 @@ public class ExportAllCommand : ExportCommandBase
|
||||||
channels.RemoveAll(c => c.Kind.IsGuild());
|
channels.RemoveAll(c => c.Kind.IsGuild());
|
||||||
if (!IncludeVoiceChannels)
|
if (!IncludeVoiceChannels)
|
||||||
channels.RemoveAll(c => c.Kind.IsVoice());
|
channels.RemoveAll(c => c.Kind.IsVoice());
|
||||||
|
if (!IncludeThreads)
|
||||||
|
channels.RemoveAll(c => c.Kind.IsThread());
|
||||||
|
if (!IncludeArchivedThreads)
|
||||||
|
channels.RemoveAll(c => c.Kind.IsThread() && c.IsArchived);
|
||||||
|
|
||||||
await ExportAsync(console, channels);
|
await ExportAsync(console, channels);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using CliFx.Attributes;
|
using CliFx.Attributes;
|
||||||
using CliFx.Exceptions;
|
using CliFx.Exceptions;
|
||||||
|
@ -7,7 +6,6 @@ using CliFx.Infrastructure;
|
||||||
using DiscordChatExporter.Cli.Commands.Base;
|
using DiscordChatExporter.Cli.Commands.Base;
|
||||||
using DiscordChatExporter.Core.Discord;
|
using DiscordChatExporter.Core.Discord;
|
||||||
using DiscordChatExporter.Core.Discord.Data;
|
using DiscordChatExporter.Core.Discord.Data;
|
||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Commands;
|
namespace DiscordChatExporter.Cli.Commands;
|
||||||
|
|
||||||
|
@ -52,21 +50,31 @@ public class ExportGuildCommand : ExportCommandBase
|
||||||
}
|
}
|
||||||
|
|
||||||
var cancellationToken = console.RegisterCancellationHandler();
|
var cancellationToken = console.RegisterCancellationHandler();
|
||||||
|
var channels = new List<Channel>();
|
||||||
|
|
||||||
await console.Output.WriteLineAsync("Fetching channels...");
|
await console.Output.WriteLineAsync("Fetching channels...");
|
||||||
|
|
||||||
var channels = (await Discord.GetGuildChannelsAsync(GuildId, cancellationToken))
|
// Regular channels
|
||||||
.Where(c => c.Kind != ChannelKind.GuildCategory)
|
await foreach (var channel in Discord.GetGuildChannelsAsync(GuildId, cancellationToken))
|
||||||
.Where(c => IncludeVoiceChannels || !c.Kind.IsVoice())
|
{
|
||||||
.ToArray();
|
if (channel.Kind == ChannelKind.GuildCategory)
|
||||||
|
continue;
|
||||||
|
|
||||||
var threads = IncludeThreads
|
if (!IncludeVoiceChannels && channel.Kind.IsVoice())
|
||||||
? await Discord.GetGuildThreadsAsync(GuildId, IncludeArchivedThreads, cancellationToken)
|
continue;
|
||||||
: Array.Empty<Channel>();
|
|
||||||
|
|
||||||
await ExportAsync(
|
channels.Add(channel);
|
||||||
console,
|
}
|
||||||
channels.Concat(threads).ToArray()
|
|
||||||
);
|
// Threads
|
||||||
|
if (IncludeThreads)
|
||||||
|
{
|
||||||
|
await foreach (var thread in Discord.GetGuildThreadsAsync(GuildId, IncludeArchivedThreads, cancellationToken))
|
||||||
|
{
|
||||||
|
channels.Add(thread);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await ExportAsync(console, channels);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -27,4 +27,7 @@ public static class ChannelKindExtensions
|
||||||
|
|
||||||
public static bool IsVoice(this ChannelKind kind) =>
|
public static bool IsVoice(this ChannelKind kind) =>
|
||||||
kind is ChannelKind.GuildVoiceChat or ChannelKind.GuildStageVoice;
|
kind is ChannelKind.GuildVoiceChat or ChannelKind.GuildStageVoice;
|
||||||
|
|
||||||
|
public static bool IsThread(this ChannelKind kind) =>
|
||||||
|
kind is ChannelKind.GuildNewsThread or ChannelKind.GuildPublicThread or ChannelKind.GuildPrivateThread;
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue