mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2025-05-29 05:55:21 -04:00
Add --include-threads
and --include-archived-threads
to exportguild
Related to #1119
This commit is contained in:
parent
d1d560fb55
commit
eac974cfb1
4 changed files with 50 additions and 6 deletions
|
@ -1,6 +1,8 @@
|
|||
using System.Linq;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Exceptions;
|
||||
using CliFx.Infrastructure;
|
||||
using DiscordChatExporter.Cli.Commands.Base;
|
||||
using DiscordChatExporter.Core.Discord;
|
||||
|
@ -25,10 +27,30 @@ public class ExportGuildCommand : ExportCommandBase
|
|||
)]
|
||||
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;
|
||||
|
||||
public override async ValueTask ExecuteAsync(IConsole 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();
|
||||
|
||||
await console.Output.WriteLineAsync("Fetching channels...");
|
||||
|
@ -38,6 +60,13 @@ public class ExportGuildCommand : ExportCommandBase
|
|||
.Where(c => IncludeVoiceChannels || !c.Kind.IsVoice())
|
||||
.ToArray();
|
||||
|
||||
await ExportAsync(console, channels);
|
||||
var threads = IncludeThreads
|
||||
? await Discord.GetGuildThreadsAsync(GuildId, IncludeArchivedThreads, cancellationToken)
|
||||
: Array.Empty<Channel>();
|
||||
|
||||
await ExportAsync(
|
||||
console,
|
||||
channels.Concat(threads).ToArray()
|
||||
);
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Exceptions;
|
||||
using CliFx.Infrastructure;
|
||||
using DiscordChatExporter.Cli.Commands.Base;
|
||||
using DiscordChatExporter.Core.Discord;
|
||||
|
@ -28,18 +29,28 @@ public class GetChannelsCommand : DiscordCommandBase
|
|||
|
||||
[CommandOption(
|
||||
"include-threads",
|
||||
Description = "Include threads in the output."
|
||||
Description = "Include threads."
|
||||
)]
|
||||
public bool IncludeThreads { get; init; }
|
||||
public bool IncludeThreads { get; init; } = false;
|
||||
|
||||
[CommandOption(
|
||||
"include-archived-threads",
|
||||
Description = "Include archived threads in the output."
|
||||
Description = "Include archived threads."
|
||||
)]
|
||||
public bool IncludeArchivedThreads { get; init; }
|
||||
public bool IncludeArchivedThreads { get; init; } = false;
|
||||
|
||||
public override async ValueTask ExecuteAsync(IConsole 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 channels = (await Discord.GetGuildChannelsAsync(GuildId, cancellationToken))
|
||||
|
|
|
@ -14,6 +14,8 @@ public class GetDirectChannelsCommand : DiscordCommandBase
|
|||
{
|
||||
public override async ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
await base.ExecuteAsync(console);
|
||||
|
||||
var cancellationToken = console.RegisterCancellationHandler();
|
||||
|
||||
var channels = (await Discord.GetGuildChannelsAsync(Guild.DirectMessages.Id, cancellationToken))
|
||||
|
|
|
@ -14,6 +14,8 @@ public class GetGuildsCommand : DiscordCommandBase
|
|||
{
|
||||
public override async ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
await base.ExecuteAsync(console);
|
||||
|
||||
var cancellationToken = console.RegisterCancellationHandler();
|
||||
|
||||
var guilds = (await Discord.GetUserGuildsAsync(cancellationToken))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue