Add CLI option to include or exclude voice channels in `exportall` and `exportguild`

pull/1101/head
Tyrrrz 1 year ago
parent bd4cfcdaf6
commit d4f62387a5

@ -28,6 +28,12 @@ public class ExportAllCommand : ExportCommandBase
)] )]
public bool IncludeGuildChannels { get; init; } = true; public bool IncludeGuildChannels { get; init; } = true;
[CommandOption(
"include-vc",
Description = "Include voice channels."
)]
public bool IncludeVoiceChannels { get; init; } = true;
[CommandOption( [CommandOption(
"data-package", "data-package",
Description = Description =
@ -97,6 +103,8 @@ public class ExportAllCommand : ExportCommandBase
channels.RemoveAll(c => c.Kind.IsDirect()); channels.RemoveAll(c => c.Kind.IsDirect());
if (!IncludeGuildChannels) if (!IncludeGuildChannels)
channels.RemoveAll(c => c.Kind.IsGuild()); channels.RemoveAll(c => c.Kind.IsGuild());
if (!IncludeVoiceChannels)
channels.RemoveAll(c => c.Kind.IsVoice());
await base.ExecuteAsync(console, channels); await base.ExecuteAsync(console, channels);
} }

@ -19,6 +19,12 @@ public class ExportGuildCommand : ExportCommandBase
)] )]
public required Snowflake GuildId { get; init; } public required Snowflake GuildId { get; init; }
[CommandOption(
"include-vc",
Description = "Include voice channels."
)]
public bool IncludeVoiceChannels { get; init; } = true;
public override async ValueTask ExecuteAsync(IConsole console) public override async ValueTask ExecuteAsync(IConsole console)
{ {
await base.ExecuteAsync(console); await base.ExecuteAsync(console);
@ -29,6 +35,7 @@ public class ExportGuildCommand : ExportCommandBase
var channels = (await Discord.GetGuildChannelsAsync(GuildId, cancellationToken)) var channels = (await Discord.GetGuildChannelsAsync(GuildId, cancellationToken))
.Where(c => c.Kind != ChannelKind.GuildCategory) .Where(c => c.Kind != ChannelKind.GuildCategory)
.Where(c => IncludeVoiceChannels || !c.Kind.IsVoice())
.ToArray(); .ToArray();
await base.ExecuteAsync(console, channels); await base.ExecuteAsync(console, channels);

@ -18,7 +18,8 @@ public partial record Channel(
string? Topic, string? Topic,
Snowflake? LastMessageId) : IHasId Snowflake? LastMessageId) : IHasId
{ {
public bool IsVoice => Kind is ChannelKind.GuildVoiceChat or ChannelKind.GuildStageVoice; // Only needed for WPF data binding. Don't use anywhere else.
public bool IsVoice => Kind.IsVoice();
} }
public partial record Channel public partial record Channel

@ -24,4 +24,7 @@ public static class ChannelKindExtensions
public static bool IsGuild(this ChannelKind kind) => public static bool IsGuild(this ChannelKind kind) =>
!kind.IsDirect(); !kind.IsDirect();
public static bool IsVoice(this ChannelKind kind) =>
kind is ChannelKind.GuildVoiceChat or ChannelKind.GuildStageVoice;
} }

@ -261,7 +261,7 @@ internal partial class HtmlMarkdownVisitor : MarkdownVisitor
else if (mention.Kind == MentionKind.Channel) else if (mention.Kind == MentionKind.Channel)
{ {
var channel = mention.TargetId?.Pipe(_context.TryGetChannel); var channel = mention.TargetId?.Pipe(_context.TryGetChannel);
var symbol = channel?.IsVoice == true ? "🔊" : "#"; var symbol = channel?.Kind.IsVoice() == true ? "🔊" : "#";
var name = channel?.Name ?? "deleted-channel"; var name = channel?.Name ?? "deleted-channel";
_buffer.Append( _buffer.Append(

@ -1,6 +1,7 @@
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using DiscordChatExporter.Core.Discord.Data;
using DiscordChatExporter.Core.Markdown; using DiscordChatExporter.Core.Markdown;
using DiscordChatExporter.Core.Markdown.Parsing; using DiscordChatExporter.Core.Markdown.Parsing;
using DiscordChatExporter.Core.Utils.Extensions; using DiscordChatExporter.Core.Utils.Extensions;
@ -71,7 +72,7 @@ internal partial class PlainTextMarkdownVisitor : MarkdownVisitor
_buffer.Append($"#{name}"); _buffer.Append($"#{name}");
// Voice channel marker // Voice channel marker
if (channel?.IsVoice == true) if (channel?.Kind.IsVoice() == true)
_buffer.Append(" [voice]"); _buffer.Append(" [voice]");
} }
else if (mention.Kind == MentionKind.Role) else if (mention.Kind == MentionKind.Role)

Loading…
Cancel
Save