Fix: Escape Backticks (#192)

This commit is contained in:
BeeFox-sys 2020-07-05 20:55:21 +10:00 committed by GitHub
parent 0d2777c1d1
commit 55ea314b42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 17 additions and 10 deletions

View File

@ -68,7 +68,7 @@ namespace PluralKit.Bot
await ctx.Reply("This member does not have any proxy tags."); await ctx.Reply("This member does not have any proxy tags.");
else else
{ {
var tags = string.Join("\n", target.ProxyTags.Select(t => $"`{t.ProxyString}`")); var tags = string.Join("\n", target.ProxyTags.Select(t => $"``{t.ProxyString.EscapeBacktickPair()}``"));
await ctx.Reply($"This member's proxy tags are:\n{tags}"); await ctx.Reply($"This member's proxy tags are:\n{tags}");
} }
} }
@ -90,7 +90,7 @@ namespace PluralKit.Bot
var patch = new MemberPatch {ProxyTags = Partial<ProxyTag[]>.Present(newTags.ToArray())}; var patch = new MemberPatch {ProxyTags = Partial<ProxyTag[]>.Present(newTags.ToArray())};
await _db.Execute(conn => conn.UpdateMember(target.Id, patch)); await _db.Execute(conn => conn.UpdateMember(target.Id, patch));
await ctx.Reply($"{Emojis.Success} Added proxy tags `{tagToAdd.ProxyString}`."); await ctx.Reply($"{Emojis.Success} Added proxy tags ``{tagToAdd.ProxyString.EscapeBacktickPair()}``.");
} }
// Subcommand: "remove" // Subcommand: "remove"
else if (ctx.Match("remove", "delete")) else if (ctx.Match("remove", "delete"))
@ -107,7 +107,7 @@ namespace PluralKit.Bot
var patch = new MemberPatch {ProxyTags = Partial<ProxyTag[]>.Present(newTags.ToArray())}; var patch = new MemberPatch {ProxyTags = Partial<ProxyTag[]>.Present(newTags.ToArray())};
await _db.Execute(conn => conn.UpdateMember(target.Id, patch)); await _db.Execute(conn => conn.UpdateMember(target.Id, patch));
await ctx.Reply($"{Emojis.Success} Removed proxy tags `{tagToRemove.ProxyString}`."); await ctx.Reply($"{Emojis.Success} Removed proxy tags ``{tagToRemove.ProxyString.EscapeBacktickPair()}``.");
} }
// Subcommand: bare proxy tag given // Subcommand: bare proxy tag given
else else
@ -131,7 +131,7 @@ namespace PluralKit.Bot
var patch = new MemberPatch {ProxyTags = Partial<ProxyTag[]>.Present(newTags)}; var patch = new MemberPatch {ProxyTags = Partial<ProxyTag[]>.Present(newTags)};
await _db.Execute(conn => conn.UpdateMember(target.Id, patch)); await _db.Execute(conn => conn.UpdateMember(target.Id, patch));
await ctx.Reply($"{Emojis.Success} Member proxy tags set to `{requestedTag.ProxyString}`."); await ctx.Reply($"{Emojis.Success} Member proxy tags set to ``{requestedTag.ProxyString.EscapeBacktickPair()}``.");
} }
} }
} }

View File

@ -105,9 +105,9 @@ namespace PluralKit.Bot {
public static PKError ProxyNameTooShort(string name) => new PKError($"The webhook's name, `{name}`, is shorter than two characters, and thus cannot be proxied. Please change the member name or use a longer system tag."); public static PKError ProxyNameTooShort(string name) => new PKError($"The webhook's name, `{name}`, is shorter than two characters, and thus cannot be proxied. Please change the member name or use a longer system tag.");
public static PKError ProxyNameTooLong(string name) => new PKError($"The webhook's name, {name}, is too long ({name.Length} > {Limits.MaxProxyNameLength} characters), and thus cannot be proxied. Please change the member name, display name or server display name, or use a shorter system tag."); public static PKError ProxyNameTooLong(string name) => new PKError($"The webhook's name, {name}, is too long ({name.Length} > {Limits.MaxProxyNameLength} characters), and thus cannot be proxied. Please change the member name, display name or server display name, or use a shorter system tag.");
public static PKError ProxyTagAlreadyExists(ProxyTag tagToAdd, PKMember member) => new PKError($"That member already has the proxy tag `{tagToAdd.ProxyString}`. The member currently has these tags: {member.ProxyTagsString()}"); public static PKError ProxyTagAlreadyExists(ProxyTag tagToAdd, PKMember member) => new PKError($"That member already has the proxy tag ``{tagToAdd.ProxyString.EscapeBacktickPair()}``. The member currently has these tags: {member.ProxyTagsString()}");
public static PKError ProxyTagDoesNotExist(ProxyTag tagToRemove, PKMember member) => new PKError($"That member does not have the proxy tag `{tagToRemove.ProxyString}`. The member currently has these tags: {member.ProxyTagsString()}"); public static PKError ProxyTagDoesNotExist(ProxyTag tagToRemove, PKMember member) => new PKError($"That member does not have the proxy tag ``{tagToRemove.ProxyString.EscapeBacktickPair()}``. The member currently has these tags: {member.ProxyTagsString()}");
public static PKError LegacyAlreadyHasProxyTag(ProxyTag requested, PKMember member) => new PKError($"This member already has more than one proxy tag set: {member.ProxyTagsString()}\nConsider using the `pk;member {member.Hid} proxy add {requested.ProxyString}` command instead."); public static PKError LegacyAlreadyHasProxyTag(ProxyTag requested, PKMember member) => new PKError($"This member already has more than one proxy tag set: {member.ProxyTagsString()}\nConsider using the ``pk;member {member.Hid} proxy add {requested.ProxyString.EscapeBacktickPair()}`` command instead.");
public static PKError EmptyProxyTags(PKMember member) => new PKError($"The example proxy `text` is equivalent to having no proxy tags at all, since there are no symbols or brackets on either end. If you'd like to clear your proxy tags, use `pk;member {member.Hid} proxy clear`."); public static PKError EmptyProxyTags(PKMember member) => new PKError($"The example proxy `text` is equivalent to having no proxy tags at all, since there are no symbols or brackets on either end. If you'd like to clear your proxy tags, use `pk;member {member.Hid} proxy clear`.");
public static PKError GenericCancelled() => new PKError("Operation cancelled."); public static PKError GenericCancelled() => new PKError("Operation cancelled.");

View File

@ -22,7 +22,7 @@ namespace PluralKit.Bot
var proxyTagsString = m.ProxyTagsString(); var proxyTagsString = m.ProxyTagsString();
if (proxyTagsString.Length > 100) // arbitrary threshold for now, tweak? if (proxyTagsString.Length > 100) // arbitrary threshold for now, tweak?
proxyTagsString = "tags too long, see member card"; proxyTagsString = "tags too long, see member card";
return $"[`{m.Hid}`] **{m.NameFor(ctx)}** *({proxyTagsString})*"; return $"[`{m.Hid}`] **{m.NameFor(ctx)}** *(*{proxyTagsString}*)*";
} }
return $"[`{m.Hid}`] **{m.NameFor(ctx)}**"; return $"[`{m.Hid}`] **{m.NameFor(ctx)}**";

View File

@ -107,7 +107,7 @@ namespace PluralKit.Bot {
var guildDisplayName = guildSettings?.DisplayName; var guildDisplayName = guildSettings?.DisplayName;
var avatar = guildSettings?.AvatarUrl ?? member.AvatarFor(ctx); var avatar = guildSettings?.AvatarUrl ?? member.AvatarFor(ctx);
var proxyTagsStr = string.Join('\n', member.ProxyTags.Select(t => $"`{t.ProxyString}`")); var proxyTagsStr = string.Join('\n', member.ProxyTags.Select(t => $"``{t.ProxyString}``"));
var eb = new DiscordEmbedBuilder() var eb = new DiscordEmbedBuilder()
// TODO: add URL of website when that's up // TODO: add URL of website when that's up

View File

@ -192,6 +192,13 @@ namespace PluralKit.Bot
else return input; else return input;
} }
public static string EscapeBacktickPair(this string input){
Regex doubleBacktick = new Regex(@"``", RegexOptions.Multiline);
//Run twice to catch any pairs that are created from the first pass, pairs shouldn't be created in the second as they are created from odd numbers of backticks, even numbers are all caught on the first pass
if(input != null) return doubleBacktick.Replace(doubleBacktick.Replace(input, @"``"),@"``");
else return input;
}
public static Task<DiscordUser> GetUser(this DiscordRestClient client, ulong id) => public static Task<DiscordUser> GetUser(this DiscordRestClient client, ulong id) =>
WrapDiscordCall(client.GetUserAsync(id)); WrapDiscordCall(client.GetUserAsync(id));

View File

@ -14,7 +14,7 @@ using PluralKit.Core;
namespace PluralKit.Bot namespace PluralKit.Bot
{ {
public static class MiscUtils { public static class MiscUtils {
public static string ProxyTagsString(this PKMember member) => string.Join(", ", member.ProxyTags.Select(t => $"`{t.ProxyString.EscapeMarkdown()}`")); public static string ProxyTagsString(this PKMember member) => string.Join(", ", member.ProxyTags.Select(t => $"``{t.ProxyString.EscapeBacktickPair()}``"));
public static bool IsOurProblem(this Exception e) public static bool IsOurProblem(this Exception e)
{ {