mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-04-21 05:28:39 +00:00
Use snowflakes in more places
This commit is contained in:
@@ -1,21 +1,22 @@
|
||||
using DiscordChatExporter.Core.Utils;
|
||||
using DiscordChatExporter.Core.Discord;
|
||||
using DiscordChatExporter.Core.Utils;
|
||||
|
||||
namespace DiscordChatExporter.Core.Markdown;
|
||||
|
||||
internal record EmojiNode(
|
||||
// Only present on custom emoji
|
||||
string? Id,
|
||||
Snowflake? Id,
|
||||
// Name of custom emoji (e.g. LUL) or actual representation of standard emoji (e.g. 🙂)
|
||||
string Name,
|
||||
bool IsAnimated) : MarkdownNode
|
||||
{
|
||||
public bool IsCustomEmoji => Id is not null;
|
||||
|
||||
// Name of custom emoji (e.g. LUL) or name of standard emoji (e.g. slight_smile)
|
||||
public string Code => !string.IsNullOrWhiteSpace(Id)
|
||||
public string Code => IsCustomEmoji
|
||||
? Name
|
||||
: EmojiIndex.TryGetCode(Name) ?? Name;
|
||||
|
||||
public bool IsCustomEmoji => !string.IsNullOrWhiteSpace(Id);
|
||||
|
||||
public EmojiNode(string name)
|
||||
: this(null, name, false)
|
||||
{
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
namespace DiscordChatExporter.Core.Markdown;
|
||||
using DiscordChatExporter.Core.Discord;
|
||||
|
||||
internal record MentionNode(string Id, MentionKind Kind) : MarkdownNode;
|
||||
namespace DiscordChatExporter.Core.Markdown;
|
||||
|
||||
internal record MentionNode(Snowflake Id, MentionKind Kind) : MarkdownNode;
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using DiscordChatExporter.Core.Discord;
|
||||
using DiscordChatExporter.Core.Utils;
|
||||
|
||||
namespace DiscordChatExporter.Core.Markdown.Parsing;
|
||||
@@ -123,31 +124,31 @@ internal static partial class MarkdownParser
|
||||
// Capture @everyone
|
||||
private static readonly IMatcher<MarkdownNode> EveryoneMentionNodeMatcher = new StringMatcher<MarkdownNode>(
|
||||
"@everyone",
|
||||
_ => new MentionNode("everyone", MentionKind.Meta)
|
||||
_ => new MentionNode(Snowflake.Zero, MentionKind.Meta)
|
||||
);
|
||||
|
||||
// Capture @here
|
||||
private static readonly IMatcher<MarkdownNode> HereMentionNodeMatcher = new StringMatcher<MarkdownNode>(
|
||||
"@here",
|
||||
_ => new MentionNode("here", MentionKind.Meta)
|
||||
_ => new MentionNode(Snowflake.Zero, MentionKind.Meta)
|
||||
);
|
||||
|
||||
// Capture <@123456> or <@!123456>
|
||||
private static readonly IMatcher<MarkdownNode> UserMentionNodeMatcher = new RegexMatcher<MarkdownNode>(
|
||||
new Regex("<@!?(\\d+)>", DefaultRegexOptions),
|
||||
(_, m) => new MentionNode(m.Groups[1].Value, MentionKind.User)
|
||||
(_, m) => new MentionNode(Snowflake.Parse(m.Groups[1].Value), MentionKind.User)
|
||||
);
|
||||
|
||||
// Capture <#123456>
|
||||
private static readonly IMatcher<MarkdownNode> ChannelMentionNodeMatcher = new RegexMatcher<MarkdownNode>(
|
||||
new Regex("<#!?(\\d+)>", DefaultRegexOptions),
|
||||
(_, m) => new MentionNode(m.Groups[1].Value, MentionKind.Channel)
|
||||
(_, m) => new MentionNode(Snowflake.Parse(m.Groups[1].Value), MentionKind.Channel)
|
||||
);
|
||||
|
||||
// Capture <@&123456>
|
||||
private static readonly IMatcher<MarkdownNode> RoleMentionNodeMatcher = new RegexMatcher<MarkdownNode>(
|
||||
new Regex("<@&(\\d+)>", DefaultRegexOptions),
|
||||
(_, m) => new MentionNode(m.Groups[1].Value, MentionKind.Role)
|
||||
(_, m) => new MentionNode(Snowflake.Parse(m.Groups[1].Value), MentionKind.Role)
|
||||
);
|
||||
|
||||
/* Emoji */
|
||||
@@ -177,7 +178,11 @@ internal static partial class MarkdownParser
|
||||
// Capture <:lul:123456> or <a:lul:123456>
|
||||
private static readonly IMatcher<MarkdownNode> CustomEmojiNodeMatcher = new RegexMatcher<MarkdownNode>(
|
||||
new Regex("<(a)?:(.+?):(\\d+?)>", DefaultRegexOptions),
|
||||
(_, m) => new EmojiNode(m.Groups[3].Value, m.Groups[2].Value, !string.IsNullOrWhiteSpace(m.Groups[1].Value))
|
||||
(_, m) => new EmojiNode(
|
||||
Snowflake.Parse(m.Groups[3].Value),
|
||||
m.Groups[2].Value,
|
||||
!string.IsNullOrWhiteSpace(m.Groups[1].Value)
|
||||
)
|
||||
);
|
||||
|
||||
/* Links */
|
||||
|
||||
Reference in New Issue
Block a user