mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2024-09-19 20:28:46 -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 System.Threading.Tasks;
|
||||||
using CliFx.Attributes;
|
using CliFx.Attributes;
|
||||||
|
using CliFx.Exceptions;
|
||||||
using CliFx.Infrastructure;
|
using CliFx.Infrastructure;
|
||||||
using DiscordChatExporter.Cli.Commands.Base;
|
using DiscordChatExporter.Cli.Commands.Base;
|
||||||
using DiscordChatExporter.Core.Discord;
|
using DiscordChatExporter.Core.Discord;
|
||||||
|
@ -25,10 +27,30 @@ public class ExportGuildCommand : 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;
|
||||||
|
|
||||||
public override async ValueTask ExecuteAsync(IConsole console)
|
public override async ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
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();
|
||||||
|
|
||||||
await console.Output.WriteLineAsync("Fetching channels...");
|
await console.Output.WriteLineAsync("Fetching channels...");
|
||||||
|
@ -38,6 +60,13 @@ public class ExportGuildCommand : ExportCommandBase
|
||||||
.Where(c => IncludeVoiceChannels || !c.Kind.IsVoice())
|
.Where(c => IncludeVoiceChannels || !c.Kind.IsVoice())
|
||||||
.ToArray();
|
.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.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using CliFx.Attributes;
|
using CliFx.Attributes;
|
||||||
|
using CliFx.Exceptions;
|
||||||
using CliFx.Infrastructure;
|
using CliFx.Infrastructure;
|
||||||
using DiscordChatExporter.Cli.Commands.Base;
|
using DiscordChatExporter.Cli.Commands.Base;
|
||||||
using DiscordChatExporter.Core.Discord;
|
using DiscordChatExporter.Core.Discord;
|
||||||
|
@ -28,18 +29,28 @@ public class GetChannelsCommand : DiscordCommandBase
|
||||||
|
|
||||||
[CommandOption(
|
[CommandOption(
|
||||||
"include-threads",
|
"include-threads",
|
||||||
Description = "Include threads in the output."
|
Description = "Include threads."
|
||||||
)]
|
)]
|
||||||
public bool IncludeThreads { get; init; }
|
public bool IncludeThreads { get; init; } = false;
|
||||||
|
|
||||||
[CommandOption(
|
[CommandOption(
|
||||||
"include-archived-threads",
|
"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)
|
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 cancellationToken = console.RegisterCancellationHandler();
|
||||||
|
|
||||||
var channels = (await Discord.GetGuildChannelsAsync(GuildId, cancellationToken))
|
var channels = (await Discord.GetGuildChannelsAsync(GuildId, cancellationToken))
|
||||||
|
|
|
@ -14,6 +14,8 @@ public class GetDirectChannelsCommand : DiscordCommandBase
|
||||||
{
|
{
|
||||||
public override async ValueTask ExecuteAsync(IConsole console)
|
public override async ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
|
await base.ExecuteAsync(console);
|
||||||
|
|
||||||
var cancellationToken = console.RegisterCancellationHandler();
|
var cancellationToken = console.RegisterCancellationHandler();
|
||||||
|
|
||||||
var channels = (await Discord.GetGuildChannelsAsync(Guild.DirectMessages.Id, cancellationToken))
|
var channels = (await Discord.GetGuildChannelsAsync(Guild.DirectMessages.Id, cancellationToken))
|
||||||
|
|
|
@ -14,6 +14,8 @@ public class GetGuildsCommand : DiscordCommandBase
|
||||||
{
|
{
|
||||||
public override async ValueTask ExecuteAsync(IConsole console)
|
public override async ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
|
await base.ExecuteAsync(console);
|
||||||
|
|
||||||
var cancellationToken = console.RegisterCancellationHandler();
|
var cancellationToken = console.RegisterCancellationHandler();
|
||||||
|
|
||||||
var guilds = (await Discord.GetUserGuildsAsync(cancellationToken))
|
var guilds = (await Discord.GetUserGuildsAsync(cancellationToken))
|
||||||
|
|
Loading…
Reference in a new issue