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;
await foreach (var channel in Discord.GetGuildChannelsAsync(guild.Id, cancellationToken))
{
// Skip non-text channels
if (!channel.Kind.IsText())
continue;
channels.Add(channel);
}
}
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.Infrastructure;
using DiscordChatExporter.Cli.Commands.Base;
@ -19,8 +18,7 @@ public class ExportDirectMessagesCommand : ExportCommandBase
await console.Output.WriteLineAsync("Fetching channels...");
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.Infrastructure;
using DiscordChatExporter.Cli.Commands.Base;
using DiscordChatExporter.Core.Discord;
using DiscordChatExporter.Core.Discord.Data;
using DiscordChatExporter.Core.Utils.Extensions;
namespace DiscordChatExporter.Cli.Commands;
@ -28,8 +26,7 @@ public class ExportGuildCommand : ExportCommandBase
await console.Output.WriteLineAsync("Fetching channels...");
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 DiscordChatExporter.Cli.Commands.Base;
using DiscordChatExporter.Core.Discord;
using DiscordChatExporter.Core.Discord.Data;
using DiscordChatExporter.Core.Utils.Extensions;
namespace DiscordChatExporter.Cli.Commands;
@ -26,7 +25,6 @@ public class GetChannelsCommand : TokenCommandBase
var cancellationToken = console.RegisterCancellationHandler();
var channels = (await Discord.GetGuildChannelsAsync(GuildId, cancellationToken))
.Where(c => c.Kind.IsText())
.OrderBy(c => c.Category.Position)
.ThenBy(c => c.Name)
.ToArray();

@ -17,7 +17,6 @@ public class GetDirectMessageChannelsCommand : TokenCommandBase
var cancellationToken = console.RegisterCancellationHandler();
var channels = (await Discord.GetGuildChannelsAsync(Guild.DirectMessages.Id, cancellationToken))
.Where(c => c.Kind.IsText())
.OrderByDescending(c => c.LastMessageId)
.ThenBy(c => c.Name)
.ToArray();

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

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

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

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

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

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

@ -348,8 +348,20 @@
<materialDesign:PackIcon
Grid.Column="0"
Margin="16,7,0,6"
VerticalAlignment="Center"
Kind="Pound" />
VerticalAlignment="Center">
<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 -->
<TextBlock

Loading…
Cancel
Save