Support listing and exporting voice channels

Closes #874
pull/882/head
Oleksii Holub 2 years ago
parent 7b72f473fd
commit 94ef4b6981

@ -31,13 +31,7 @@ public class ExportAllCommand : ExportCommandBase
continue; continue;
await foreach (var channel in Discord.GetGuildChannelsAsync(guild.Id, cancellationToken)) await foreach (var channel in Discord.GetGuildChannelsAsync(guild.Id, cancellationToken))
{
// Skip non-text channels
if (!channel.Kind.IsText())
continue;
channels.Add(channel); channels.Add(channel);
}
} }
await base.ExecuteAsync(console, channels); await base.ExecuteAsync(console, channels);

@ -1,5 +1,4 @@
using System.Linq; using System.Threading.Tasks;
using System.Threading.Tasks;
using CliFx.Attributes; using CliFx.Attributes;
using CliFx.Infrastructure; using CliFx.Infrastructure;
using DiscordChatExporter.Cli.Commands.Base; using DiscordChatExporter.Cli.Commands.Base;
@ -19,8 +18,7 @@ public class ExportDirectMessagesCommand : ExportCommandBase
await console.Output.WriteLineAsync("Fetching channels..."); await console.Output.WriteLineAsync("Fetching channels...");
var channels = await Discord.GetGuildChannelsAsync(Guild.DirectMessages.Id, cancellationToken); var channels = await Discord.GetGuildChannelsAsync(Guild.DirectMessages.Id, cancellationToken);
var textChannels = channels.Where(c => c.Kind.IsText()).ToArray();
await base.ExecuteAsync(console, textChannels); await base.ExecuteAsync(console, channels);
} }
} }

@ -1,10 +1,8 @@
using System.Linq; using System.Threading.Tasks;
using System.Threading.Tasks;
using CliFx.Attributes; using CliFx.Attributes;
using CliFx.Infrastructure; 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.Utils.Extensions; using DiscordChatExporter.Core.Utils.Extensions;
namespace DiscordChatExporter.Cli.Commands; namespace DiscordChatExporter.Cli.Commands;
@ -28,8 +26,7 @@ public class ExportGuildCommand : ExportCommandBase
await console.Output.WriteLineAsync("Fetching channels..."); await console.Output.WriteLineAsync("Fetching channels...");
var channels = await Discord.GetGuildChannelsAsync(GuildId, cancellationToken); var channels = await Discord.GetGuildChannelsAsync(GuildId, cancellationToken);
var textChannels = channels.Where(c => c.Kind.IsText()).ToArray();
await base.ExecuteAsync(console, textChannels); await base.ExecuteAsync(console, channels);
} }
} }

@ -5,7 +5,6 @@ using CliFx.Attributes;
using CliFx.Infrastructure; 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.Utils.Extensions; using DiscordChatExporter.Core.Utils.Extensions;
namespace DiscordChatExporter.Cli.Commands; namespace DiscordChatExporter.Cli.Commands;
@ -26,7 +25,6 @@ public class GetChannelsCommand : TokenCommandBase
var cancellationToken = console.RegisterCancellationHandler(); var cancellationToken = console.RegisterCancellationHandler();
var channels = (await Discord.GetGuildChannelsAsync(GuildId, cancellationToken)) var channels = (await Discord.GetGuildChannelsAsync(GuildId, cancellationToken))
.Where(c => c.Kind.IsText())
.OrderBy(c => c.Category.Position) .OrderBy(c => c.Category.Position)
.ThenBy(c => c.Name) .ThenBy(c => c.Name)
.ToArray(); .ToArray();

@ -17,7 +17,6 @@ public class GetDirectMessageChannelsCommand : TokenCommandBase
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))
.Where(c => c.Kind.IsText())
.OrderByDescending(c => c.LastMessageId) .OrderByDescending(c => c.LastMessageId)
.ThenBy(c => c.Name) .ThenBy(c => c.Name)
.ToArray(); .ToArray();

@ -15,8 +15,10 @@ public partial record Channel(
string Name, string Name,
int? Position, int? Position,
string? Topic, string? Topic,
Snowflake? LastMessageId Snowflake? LastMessageId) : IHasId
) : IHasId; {
public bool SupportsVoice => Kind is ChannelKind.GuildVoiceChat or ChannelKind.GuildStageVoice;
}
public partial record Channel public partial record Channel
{ {
@ -28,7 +30,6 @@ public partial record Channel
ChannelKind.DirectTextChat => "Private", ChannelKind.DirectTextChat => "Private",
ChannelKind.DirectGroupTextChat => "Group", ChannelKind.DirectGroupTextChat => "Group",
ChannelKind.GuildNews => "News", ChannelKind.GuildNews => "News",
ChannelKind.GuildStore => "Store",
_ => "Default" _ => "Default"
}, },
null null

@ -5,23 +5,15 @@
public enum ChannelKind public enum ChannelKind
{ {
GuildTextChat = 0, GuildTextChat = 0,
DirectTextChat, DirectTextChat = 1,
GuildVoiceChat, GuildVoiceChat = 2,
DirectGroupTextChat, DirectGroupTextChat = 3,
GuildCategory, GuildCategory = 4,
GuildNews, GuildNews = 5,
GuildStore GuildNewsThread = 10,
} GuildPublicThread = 11,
GuildPrivateThread = 12,
public static class ChannelKindExtensions GuildStageVoice = 13,
{ GuildDirectory = 14,
public static bool IsText(this ChannelKind kind) => kind is GuildForum = 15
ChannelKind.GuildTextChat or
ChannelKind.DirectTextChat or
ChannelKind.DirectGroupTextChat or
ChannelKind.GuildNews or
ChannelKind.GuildStore;
public static bool IsVoice(this ChannelKind kind) => kind is
ChannelKind.GuildVoiceChat;
} }

@ -158,7 +158,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?.Kind.IsVoice() == true ? "🔊" : "#"; var symbol = channel?.SupportsVoice == true ? "🔊" : "#";
var name = channel?.Name ?? "deleted-channel"; var name = channel?.Name ?? "deleted-channel";
_buffer _buffer

@ -1,5 +1,4 @@
using System.Text; using System.Text;
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;
@ -53,13 +52,13 @@ internal partial class PlainTextMarkdownVisitor : 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 name = channel?.Name ?? "deleted-channel"; var name = channel?.Name ?? "deleted-channel";
_buffer.Append($"#{name}"); _buffer.Append($"#{name}");
// Voice channel marker // Voice channel marker
if (channel?.Kind.IsVoice() == true) if (channel?.SupportsVoice == true)
_buffer.Append(" [voice]"); _buffer.Append(" [voice]");
} }
else if (mention.Kind == MentionKind.Role) else if (mention.Kind == MentionKind.Role)

@ -45,7 +45,8 @@ public partial class SettingsService
try try
{ {
return Registry.CurrentUser.OpenSubKey( return Registry.CurrentUser.OpenSubKey(
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", false "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize",
false
)?.GetValue("AppsUseLightTheme") is 0; )?.GetValue("AppsUseLightTheme") is 0;
} }
catch catch

@ -105,10 +105,7 @@ public class DashboardViewModel : PropertyChangedBase
var guildChannelMap = new Dictionary<Guild, IReadOnlyList<Channel>>(); var guildChannelMap = new Dictionary<Guild, IReadOnlyList<Channel>>();
await foreach (var guild in discord.GetUserGuildsAsync()) await foreach (var guild in discord.GetUserGuildsAsync())
{ guildChannelMap[guild] = await discord.GetGuildChannelsAsync(guild.Id);
var channels = await discord.GetGuildChannelsAsync(guild.Id);
guildChannelMap[guild] = channels.Where(c => c.Kind.IsText()).ToArray();
}
_discord = discord; _discord = discord;
GuildChannelMap = guildChannelMap; GuildChannelMap = guildChannelMap;

@ -348,8 +348,20 @@
<materialDesign:PackIcon <materialDesign:PackIcon
Grid.Column="0" Grid.Column="0"
Margin="16,7,0,6" Margin="16,7,0,6"
VerticalAlignment="Center" VerticalAlignment="Center">
Kind="Pound" /> <materialDesign:PackIcon.Style>
<Style TargetType="{x:Type materialDesign:PackIcon}">
<Style.Triggers>
<DataTrigger Binding="{Binding SupportsVoice}" Value="True">
<Setter Property="Kind" Value="VolumeHigh" />
</DataTrigger>
<DataTrigger Binding="{Binding SupportsVoice}" Value="False">
<Setter Property="Kind" Value="Pound" />
</DataTrigger>
</Style.Triggers>
</Style>
</materialDesign:PackIcon.Style>
</materialDesign:PackIcon>
<!-- Channel name --> <!-- Channel name -->
<TextBlock <TextBlock

Loading…
Cancel
Save