mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-17 03:00:13 +00:00
Escape username markdown directly.
This commit is contained in:
parent
6d76fb799b
commit
f1e84db1a6
2 changed files with 4 additions and 11 deletions
|
|
@ -43,7 +43,7 @@ public class EmbedService
|
||||||
{
|
{
|
||||||
// Fetch/render info for all accounts simultaneously
|
// Fetch/render info for all accounts simultaneously
|
||||||
var accounts = await _repo.GetSystemAccounts(system.Id);
|
var accounts = await _repo.GetSystemAccounts(system.Id);
|
||||||
var users = (await GetUsers(accounts)).Select(x => x.User?.NameAndMention().EscapeMarkdownExcludingMentions() ?? $"(deleted account {x.Id})");
|
var users = (await GetUsers(accounts)).Select(x => x.User?.NameAndMention() ?? $"(deleted account {x.Id})");
|
||||||
|
|
||||||
var countctx = LookupContext.ByNonOwner;
|
var countctx = LookupContext.ByNonOwner;
|
||||||
if (cctx.MatchFlag("a", "all"))
|
if (cctx.MatchFlag("a", "all"))
|
||||||
|
|
@ -407,8 +407,8 @@ public class EmbedService
|
||||||
// Calculate string displayed under "Sent by"
|
// Calculate string displayed under "Sent by"
|
||||||
string userStr;
|
string userStr;
|
||||||
if (showContent && memberInfo != null && memberInfo.Nick != null)
|
if (showContent && memberInfo != null && memberInfo.Nick != null)
|
||||||
userStr = $"**Username:** {userInfo.NameAndMention().EscapeMarkdownExcludingMentions()}\n**Nickname:** {memberInfo.Nick}";
|
userStr = $"**Username:** {userInfo.NameAndMention()}\n**Nickname:** {memberInfo.Nick}";
|
||||||
else if (userInfo != null) userStr = userInfo.NameAndMention().EscapeMarkdownExcludingMentions();
|
else if (userInfo != null) userStr = userInfo.NameAndMention();
|
||||||
else userStr = $"*(deleted user {msg.Message.Sender})*";
|
else userStr = $"*(deleted user {msg.Message.Sender})*";
|
||||||
|
|
||||||
var content = serverMsg?.Content?.NormalizeLineEndSpacing();
|
var content = serverMsg?.Content?.NormalizeLineEndSpacing();
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ public static class DiscordUtils
|
||||||
private static readonly Regex UNBROKEN_LINK_REGEX = new("<?(https?:\\/\\/[^\\s<]+[^<.,:;\"')\\]\\s])>?");
|
private static readonly Regex UNBROKEN_LINK_REGEX = new("<?(https?:\\/\\/[^\\s<]+[^<.,:;\"')\\]\\s])>?");
|
||||||
|
|
||||||
public static string NameAndMention(this User user) =>
|
public static string NameAndMention(this User user) =>
|
||||||
$"{user.Username}{(user.Discriminator == "0" ? "" : $"#{user.Discriminator}")} ({user.Mention()})";
|
$"{user.Username.EscapeMarkdown()}{(user.Discriminator == "0" ? "" : $"#{user.Discriminator}")} ({user.Mention()})";
|
||||||
|
|
||||||
public static Instant SnowflakeToInstant(ulong snowflake) =>
|
public static Instant SnowflakeToInstant(ulong snowflake) =>
|
||||||
Instant.FromUtc(2015, 1, 1, 0, 0, 0) + Duration.FromMilliseconds(snowflake >> 22);
|
Instant.FromUtc(2015, 1, 1, 0, 0, 0) + Duration.FromMilliseconds(snowflake >> 22);
|
||||||
|
|
@ -156,13 +156,6 @@ public static class DiscordUtils
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string EscapeMarkdownExcludingMentions(this string input)
|
|
||||||
{
|
|
||||||
var pattern = new Regex(@"[*_~`(||)\\]", RegexOptions.Multiline);
|
|
||||||
if (input != null) return pattern.Replace(input, @"\$&");
|
|
||||||
return input;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string EscapeBacktickPair(this string input)
|
public static string EscapeBacktickPair(this string input)
|
||||||
{
|
{
|
||||||
if (input == null)
|
if (input == null)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue