Support listing and exporting voice channels

Closes #874
This commit is contained in:
Oleksii Holub
2022-06-28 18:27:01 +03:00
parent 7b72f473fd
commit 94ef4b6981
12 changed files with 39 additions and 51 deletions

View File

@@ -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

View File

@@ -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
}

View File

@@ -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

View File

@@ -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)