From ea4d93208eb1af72431f3b79e2fb19e499e35b3d Mon Sep 17 00:00:00 2001 From: spiral Date: Thu, 26 Nov 2020 00:01:19 -0500 Subject: [PATCH 1/2] Allow single character proxy name by adding invisible character --- PluralKit.Bot/Proxy/ProxyService.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/PluralKit.Bot/Proxy/ProxyService.cs b/PluralKit.Bot/Proxy/ProxyService.cs index 8342eb1d..7b78d17f 100644 --- a/PluralKit.Bot/Proxy/ProxyService.cs +++ b/PluralKit.Bot/Proxy/ProxyService.cs @@ -96,7 +96,7 @@ namespace PluralKit.Bot // Send the webhook var content = match.ProxyContent; if (!allowEmbeds) content = content.BreakLinkEmbeds(); - var proxyMessage = await _webhookExecutor.ExecuteWebhook(trigger.Channel, match.Member.ProxyName(ctx), + var proxyMessage = await _webhookExecutor.ExecuteWebhook(trigger.Channel, FixSingleCharacterName(match.Member.ProxyName(ctx)), match.Member.ProxyAvatar(ctx), content, trigger.Attachments, allowEveryone); @@ -185,9 +185,15 @@ namespace PluralKit.Bot return true; } + private string FixSingleCharacterName(string proxyName) + { + if (proxyName.Length == 1) return proxyName += "\u17b5"; + else return proxyName; + } + private bool CheckProxyNameBoundsOrError(string proxyName) { - if (proxyName.Length < 2) throw Errors.ProxyNameTooShort(proxyName); + // if (proxyName.Length < 2) throw Errors.ProxyNameTooShort(proxyName); if (proxyName.Length > Limits.MaxProxyNameLength) throw Errors.ProxyNameTooLong(proxyName); // TODO: this never returns false as it throws instead, should this happen? From 277b00105052f59eda97ad411843d653fd0b6e40 Mon Sep 17 00:00:00 2001 From: spiral Date: Thu, 26 Nov 2020 00:04:40 -0500 Subject: [PATCH 2/2] Clean up name length check method --- PluralKit.Bot/Proxy/ProxyService.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/PluralKit.Bot/Proxy/ProxyService.cs b/PluralKit.Bot/Proxy/ProxyService.cs index 7b78d17f..372a8c58 100644 --- a/PluralKit.Bot/Proxy/ProxyService.cs +++ b/PluralKit.Bot/Proxy/ProxyService.cs @@ -55,7 +55,9 @@ namespace PluralKit.Bot // Permission check after proxy match so we don't get spammed when not actually proxying if (!await CheckBotPermissionsOrError(message.Channel)) return false; - if (!CheckProxyNameBoundsOrError(match.Member.ProxyName(ctx))) return false; + + // this method throws, so no need to wrap it in an if statement + CheckProxyNameBoundsOrError(match.Member.ProxyName(ctx)); // Check if the sender account can mention everyone/here + embed links // we need to "mirror" these permissions when proxying to prevent exploits @@ -191,13 +193,9 @@ namespace PluralKit.Bot else return proxyName; } - private bool CheckProxyNameBoundsOrError(string proxyName) + private void CheckProxyNameBoundsOrError(string proxyName) { - // if (proxyName.Length < 2) throw Errors.ProxyNameTooShort(proxyName); if (proxyName.Length > Limits.MaxProxyNameLength) throw Errors.ProxyNameTooLong(proxyName); - - // TODO: this never returns false as it throws instead, should this happen? - return true; } } } \ No newline at end of file