Escape Discord usernames in system embed.

This commit is contained in:
threeoh6000 2024-08-15 18:08:54 +01:00
parent d305faf401
commit 54adf8cf12
No known key found for this signature in database
GPG key ID: 801FE4AD456E922C
2 changed files with 8 additions and 1 deletions

View file

@ -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() ?? $"(deleted account {x.Id})"); var users = (await GetUsers(accounts)).Select(x => x.User?.NameAndMention().EscapeMarkdownExcludingMentions() ?? $"(deleted account {x.Id})");
var countctx = LookupContext.ByNonOwner; var countctx = LookupContext.ByNonOwner;
if (cctx.MatchFlag("a", "all")) if (cctx.MatchFlag("a", "all"))

View file

@ -156,6 +156,13 @@ 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)