mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-03-12 01:43:05 +00:00
Convert several types to records
This commit is contained in:
@@ -1,38 +1,24 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using DiscordChatExporter.Core.Utils;
|
||||
using DiscordChatExporter.Core.Utils;
|
||||
|
||||
namespace DiscordChatExporter.Core.Markdown
|
||||
{
|
||||
internal class EmojiNode : MarkdownNode
|
||||
{
|
||||
internal record EmojiNode(
|
||||
// Only present on custom emoji
|
||||
public string? Id { get; }
|
||||
|
||||
string? Id,
|
||||
// Name of custom emoji (e.g. LUL) or actual representation of standard emoji (e.g. 🙂)
|
||||
public string Name { get; }
|
||||
|
||||
string Name,
|
||||
bool IsAnimated) : MarkdownNode
|
||||
{
|
||||
// Name of custom emoji (e.g. LUL) or name of standard emoji (e.g. slight_smile)
|
||||
public string Code => !string.IsNullOrWhiteSpace(Id)
|
||||
? Name
|
||||
: EmojiIndex.TryGetCode(Name) ?? Name;
|
||||
|
||||
public bool IsAnimated { get; }
|
||||
|
||||
public bool IsCustomEmoji => !string.IsNullOrWhiteSpace(Id);
|
||||
|
||||
public EmojiNode(string? id, string name, bool isAnimated)
|
||||
{
|
||||
Id = id;
|
||||
Name = name;
|
||||
IsAnimated = isAnimated;
|
||||
}
|
||||
|
||||
public EmojiNode(string name)
|
||||
: this(null, name, false)
|
||||
{
|
||||
}
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public override string ToString() => $"<Emoji> {Name}";
|
||||
}
|
||||
}
|
||||
@@ -1,29 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
|
||||
namespace DiscordChatExporter.Core.Markdown
|
||||
{
|
||||
internal class FormattingNode : MarkdownNode
|
||||
{
|
||||
public FormattingKind Kind { get; }
|
||||
|
||||
public IReadOnlyList<MarkdownNode> Children { get; }
|
||||
|
||||
public FormattingNode(FormattingKind kind, IReadOnlyList<MarkdownNode> children)
|
||||
{
|
||||
Kind = kind;
|
||||
Children = children;
|
||||
}
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public override string ToString()
|
||||
{
|
||||
var childrenFormatted = Children.Count == 1
|
||||
? Children.Single().ToString()
|
||||
: "+" + Children.Count;
|
||||
|
||||
return $"<{Kind}> ({childrenFormatted})";
|
||||
}
|
||||
}
|
||||
internal record FormattingNode(FormattingKind Kind, IReadOnlyList<MarkdownNode> Children) : MarkdownNode;
|
||||
}
|
||||
@@ -1,17 +1,4 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace DiscordChatExporter.Core.Markdown
|
||||
namespace DiscordChatExporter.Core.Markdown
|
||||
{
|
||||
internal class InlineCodeBlockNode : MarkdownNode
|
||||
{
|
||||
public string Code { get; }
|
||||
|
||||
public InlineCodeBlockNode(string code)
|
||||
{
|
||||
Code = code;
|
||||
}
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public override string ToString() => $"<Code> {Code}";
|
||||
}
|
||||
internal record InlineCodeBlockNode(string Code) : MarkdownNode;
|
||||
}
|
||||
@@ -1,34 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
|
||||
namespace DiscordChatExporter.Core.Markdown
|
||||
{
|
||||
internal class LinkNode : MarkdownNode
|
||||
internal record LinkNode(
|
||||
string Url,
|
||||
IReadOnlyList<MarkdownNode> Children) : MarkdownNode
|
||||
{
|
||||
public string Url { get; }
|
||||
|
||||
public IReadOnlyList<MarkdownNode> Children { get; }
|
||||
|
||||
public LinkNode(string url, IReadOnlyList<MarkdownNode> children)
|
||||
{
|
||||
Url = url;
|
||||
Children = children;
|
||||
}
|
||||
|
||||
public LinkNode(string url)
|
||||
: this(url, new[] {new TextNode(url)})
|
||||
: this(url, new[] { new TextNode(url) })
|
||||
{
|
||||
}
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public override string ToString()
|
||||
{
|
||||
var childrenFormatted = Children.Count == 1
|
||||
? Children.Single().ToString()
|
||||
: "+" + Children.Count;
|
||||
|
||||
return $"<Link> ({childrenFormatted})";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,4 @@
|
||||
namespace DiscordChatExporter.Core.Markdown
|
||||
{
|
||||
internal abstract class MarkdownNode
|
||||
{
|
||||
}
|
||||
internal abstract record MarkdownNode;
|
||||
}
|
||||
@@ -1,20 +1,4 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace DiscordChatExporter.Core.Markdown
|
||||
namespace DiscordChatExporter.Core.Markdown
|
||||
{
|
||||
internal class MentionNode : MarkdownNode
|
||||
{
|
||||
public string Id { get; }
|
||||
|
||||
public MentionKind Kind { get; }
|
||||
|
||||
public MentionNode(string id, MentionKind kind)
|
||||
{
|
||||
Id = id;
|
||||
Kind = kind;
|
||||
}
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public override string ToString() => $"<{Kind} mention> {Id}";
|
||||
}
|
||||
internal record MentionNode(string Id, MentionKind Kind) : MarkdownNode;
|
||||
}
|
||||
@@ -1,20 +1,4 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace DiscordChatExporter.Core.Markdown
|
||||
namespace DiscordChatExporter.Core.Markdown
|
||||
{
|
||||
internal class MultiLineCodeBlockNode : MarkdownNode
|
||||
{
|
||||
public string Language { get; }
|
||||
|
||||
public string Code { get; }
|
||||
|
||||
public MultiLineCodeBlockNode(string language, string code)
|
||||
{
|
||||
Language = language;
|
||||
Code = code;
|
||||
}
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public override string ToString() => $"<{Language}> {Code}";
|
||||
}
|
||||
internal record MultiLineCodeBlockNode(string Language, string Code) : MarkdownNode;
|
||||
}
|
||||
@@ -2,23 +2,10 @@
|
||||
|
||||
namespace DiscordChatExporter.Core.Markdown.Parsing
|
||||
{
|
||||
internal readonly struct StringPart
|
||||
internal readonly record struct StringPart(string Target, int StartIndex, int Length)
|
||||
{
|
||||
public string Target { get; }
|
||||
|
||||
public int StartIndex { get; }
|
||||
|
||||
public int Length { get; }
|
||||
|
||||
public int EndIndex => StartIndex + Length;
|
||||
|
||||
public StringPart(string target, int startIndex, int length)
|
||||
{
|
||||
Target = target;
|
||||
StartIndex = startIndex;
|
||||
Length = length;
|
||||
}
|
||||
|
||||
public StringPart(string target)
|
||||
: this(target, 0, target.Length)
|
||||
{
|
||||
|
||||
@@ -1,17 +1,4 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace DiscordChatExporter.Core.Markdown
|
||||
namespace DiscordChatExporter.Core.Markdown
|
||||
{
|
||||
internal class TextNode : MarkdownNode
|
||||
{
|
||||
public string Text { get; }
|
||||
|
||||
public TextNode(string text)
|
||||
{
|
||||
Text = text;
|
||||
}
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public override string ToString() => Text;
|
||||
}
|
||||
internal record TextNode(string Text) : MarkdownNode;
|
||||
}
|
||||
@@ -1,15 +1,6 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace DiscordChatExporter.Core.Markdown
|
||||
{
|
||||
internal class UnixTimestampNode : MarkdownNode
|
||||
{
|
||||
public DateTimeOffset Value { get; }
|
||||
|
||||
public UnixTimestampNode(DateTimeOffset value) => Value = value;
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public override string ToString() => Value.ToString();
|
||||
}
|
||||
internal record UnixTimestampNode(DateTimeOffset Value) : MarkdownNode;
|
||||
}
|
||||
Reference in New Issue
Block a user