|
|
@ -1,6 +1,5 @@
|
|
|
|
using System;
|
|
|
|
using System;
|
|
|
|
using System.IO;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
using System.Net;
|
|
|
|
using System.Net;
|
|
|
|
using System.Text;
|
|
|
|
using System.Text;
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
@ -224,20 +223,12 @@ namespace DiscordChatExporter.Services
|
|
|
|
content = content.Replace("\n", Environment.NewLine);
|
|
|
|
content = content.Replace("\n", Environment.NewLine);
|
|
|
|
|
|
|
|
|
|
|
|
// User mentions (<@id>)
|
|
|
|
// User mentions (<@id>)
|
|
|
|
content = Regex.Replace(content, "<@(\\d*)>",
|
|
|
|
foreach (var mentionedUser in message.MentionedUsers)
|
|
|
|
m =>
|
|
|
|
content = content.Replace($"<@{mentionedUser.Id}>", $"@{mentionedUser}");
|
|
|
|
{
|
|
|
|
|
|
|
|
var mentionedUser = message.MentionedUsers.First(u => u.Id == m.Groups[1].Value);
|
|
|
|
|
|
|
|
return $"@{mentionedUser}";
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Role mentions (<@&id>)
|
|
|
|
// Role mentions (<@&id>)
|
|
|
|
content = Regex.Replace(content, "<@&(\\d*)>",
|
|
|
|
foreach (var mentionedRole in message.MentionedRoles)
|
|
|
|
m =>
|
|
|
|
content = content.Replace($"<@&{mentionedRole.Id}>", $"@{mentionedRole.Name}");
|
|
|
|
{
|
|
|
|
|
|
|
|
var mentionedRole = message.MentionedRoles.First(r => r.Id == m.Groups[1].Value);
|
|
|
|
|
|
|
|
return $"@{mentionedRole.Name}";
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Custom emojis (<:name:id>)
|
|
|
|
// Custom emojis (<:name:id>)
|
|
|
|
content = Regex.Replace(content, "<(:.*?:)\\d*>", "$1");
|
|
|
|
content = Regex.Replace(content, "<(:.*?:)\\d*>", "$1");
|
|
|
@ -259,8 +250,7 @@ namespace DiscordChatExporter.Services
|
|
|
|
content = Regex.Replace(content, "`([^`]+)`", "<span class=\"pre\">$1</span>");
|
|
|
|
content = Regex.Replace(content, "`([^`]+)`", "<span class=\"pre\">$1</span>");
|
|
|
|
|
|
|
|
|
|
|
|
// URL links
|
|
|
|
// URL links
|
|
|
|
content = Regex.Replace(content, "((https?|ftp)://[^\\s/$.?#].[^\\s]*)",
|
|
|
|
content = Regex.Replace(content, "((https?|ftp)://[^\\s/$.?#].[^\\s]*)", "<a href=\"$1\">$1</a>");
|
|
|
|
"<a href=\"$1\">$1</a>");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Bold (**text**)
|
|
|
|
// Bold (**text**)
|
|
|
|
content = Regex.Replace(content, "\\*\\*([^\\*]*?)\\*\\*", "<b>$1</b>");
|
|
|
|
content = Regex.Replace(content, "\\*\\*([^\\*]*?)\\*\\*", "<b>$1</b>");
|
|
|
@ -287,24 +277,22 @@ namespace DiscordChatExporter.Services
|
|
|
|
content = content.Replace("@here", "<span class=\"mention\">@here</span>");
|
|
|
|
content = content.Replace("@here", "<span class=\"mention\">@here</span>");
|
|
|
|
|
|
|
|
|
|
|
|
// User mentions (<@id>)
|
|
|
|
// User mentions (<@id>)
|
|
|
|
content = Regex.Replace(content, "<@(\\d*)>",
|
|
|
|
foreach (var mentionedUser in message.MentionedUsers)
|
|
|
|
m =>
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var mentionedUser = message.MentionedUsers.First(u => u.Id == m.Groups[1].Value);
|
|
|
|
content = content.Replace($"<@{mentionedUser.Id}>",
|
|
|
|
return $"<span class=\"mention\" title=\"{HtmlEncode(mentionedUser)}\">" +
|
|
|
|
$"<span class=\"mention\" title=\"{HtmlEncode(mentionedUser)}\">" +
|
|
|
|
$"@{HtmlEncode(mentionedUser.Name)}" +
|
|
|
|
$"@{HtmlEncode(mentionedUser.Name)}" +
|
|
|
|
"</span>";
|
|
|
|
"</span>");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Role mentions (<@&id>)
|
|
|
|
// Role mentions (<@&id>)
|
|
|
|
content = Regex.Replace(content, "<@&(\\d*)>",
|
|
|
|
foreach (var mentionedRole in message.MentionedRoles)
|
|
|
|
m =>
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var mentionedRole = message.MentionedRoles.First(r => r.Id == m.Groups[1].Value);
|
|
|
|
content = content.Replace($"<@&{mentionedRole.Id}>",
|
|
|
|
return "<span class=\"mention\">" +
|
|
|
|
"<span class=\"mention\">" +
|
|
|
|
$"@{HtmlEncode(mentionedRole.Name)}" +
|
|
|
|
$"@{HtmlEncode(mentionedRole.Name)}" +
|
|
|
|
"</span>";
|
|
|
|
"</span>");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Custom emojis (<:name:id>)
|
|
|
|
// Custom emojis (<:name:id>)
|
|
|
|
content = Regex.Replace(content, "<(:.*?:)(\\d*)>",
|
|
|
|
content = Regex.Replace(content, "<(:.*?:)(\\d*)>",
|
|
|
|