mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-03-20 22:01:29 +00:00
Refactor IsTextChannel and IsVoiceChannel to extensions
This commit is contained in:
@@ -14,17 +14,8 @@ public partial record Channel(
|
||||
ChannelCategory Category,
|
||||
string Name,
|
||||
int? Position,
|
||||
string? Topic) : IHasId
|
||||
{
|
||||
public bool IsTextChannel => Kind is
|
||||
ChannelKind.GuildTextChat or
|
||||
ChannelKind.DirectTextChat or
|
||||
ChannelKind.DirectGroupTextChat or
|
||||
ChannelKind.GuildNews or
|
||||
ChannelKind.GuildStore;
|
||||
|
||||
public bool IsVoiceChannel => !IsTextChannel;
|
||||
}
|
||||
string? Topic
|
||||
) : IHasId;
|
||||
|
||||
public partial record Channel
|
||||
{
|
||||
|
||||
@@ -11,4 +11,17 @@ public enum ChannelKind
|
||||
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;
|
||||
}
|
||||
@@ -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?.IsVoiceChannel == true ? "🔊" : "#";
|
||||
var symbol = channel?.Kind.IsVoice() == true ? "🔊" : "#";
|
||||
var name = channel?.Name ?? "deleted-channel";
|
||||
|
||||
_buffer
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Text;
|
||||
using DiscordChatExporter.Core.Discord.Data;
|
||||
using DiscordChatExporter.Core.Markdown;
|
||||
using DiscordChatExporter.Core.Markdown.Parsing;
|
||||
using DiscordChatExporter.Core.Utils.Extensions;
|
||||
@@ -58,7 +59,7 @@ internal partial class PlainTextMarkdownVisitor : MarkdownVisitor
|
||||
_buffer.Append($"#{name}");
|
||||
|
||||
// Voice channel marker
|
||||
if (channel?.IsVoiceChannel == true)
|
||||
if (channel?.Kind.IsVoice() == true)
|
||||
_buffer.Append(" [voice]");
|
||||
}
|
||||
else if (mention.Kind == MentionKind.Role)
|
||||
|
||||
Reference in New Issue
Block a user