From 493f7b12e55698739ca865886e194360c9defe55 Mon Sep 17 00:00:00 2001 From: Ske Date: Thu, 20 Feb 2020 23:53:05 +0100 Subject: [PATCH] Skip flag parsing when handling proxy tags --- PluralKit.Bot/CommandSystem/Context.cs | 5 ++--- PluralKit.Bot/CommandSystem/Parameters.cs | 15 +++++++++------ PluralKit.Bot/Commands/MemberProxy.cs | 6 +++--- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/PluralKit.Bot/CommandSystem/Context.cs b/PluralKit.Bot/CommandSystem/Context.cs index da445ae7..9ae543a6 100644 --- a/PluralKit.Bot/CommandSystem/Context.cs +++ b/PluralKit.Bot/CommandSystem/Context.cs @@ -48,9 +48,8 @@ namespace PluralKit.Bot public PKSystem System => _senderSystem; public string PopArgument() => _parameters.Pop(); - public string PeekArgument() => _parameters.Peek(); - public string Remainder() => _parameters.Remainder(); - public string RemainderOrNull() => Remainder().Trim().Length == 0 ? null : Remainder(); + public string PeekArgument() => _parameters.Peek(); + public string RemainderOrNull(bool skipFlags = true) => _parameters.Remainder(skipFlags).Length == 0 ? null : _parameters.Remainder(skipFlags); public bool HasNext() => RemainderOrNull() != null; public string FullCommand => _parameters.FullCommand; diff --git a/PluralKit.Bot/CommandSystem/Parameters.cs b/PluralKit.Bot/CommandSystem/Parameters.cs index 987d5b40..72fd1f41 100644 --- a/PluralKit.Bot/CommandSystem/Parameters.cs +++ b/PluralKit.Bot/CommandSystem/Parameters.cs @@ -101,15 +101,18 @@ namespace PluralKit.Bot return _flags; } - public string Remainder() + public string Remainder(bool skipFlags = true) { - // Skip all *leading* flags when taking the remainder - while (NextWordPosition(_ptr) is {} wp) + if (skipFlags) { - if (_cmd[wp.startPos] != '-' || wp.wasQuoted) break; - _ptr = wp.endPos + wp.advanceAfterWord; + // Skip all *leading* flags when taking the remainder + while (NextWordPosition(_ptr) is {} wp) + { + if (_cmd[wp.startPos] != '-' || wp.wasQuoted) break; + _ptr = wp.endPos + wp.advanceAfterWord; + } } - + // *Then* get the remainder return _cmd.Substring(Math.Min(_ptr, _cmd.Length)).Trim(); } diff --git a/PluralKit.Bot/Commands/MemberProxy.cs b/PluralKit.Bot/Commands/MemberProxy.cs index ccebd4bf..0d3855e9 100644 --- a/PluralKit.Bot/Commands/MemberProxy.cs +++ b/PluralKit.Bot/Commands/MemberProxy.cs @@ -65,7 +65,7 @@ namespace PluralKit.Bot { if (!ctx.HasNext()) throw new PKSyntaxError("You must pass an example proxy to add (eg. `[text]` or `J:text`)."); - var tagToAdd = ParseProxyTags(ctx.RemainderOrNull()); + var tagToAdd = ParseProxyTags(ctx.RemainderOrNull(skipFlags: false)); if (tagToAdd.IsEmpty) throw Errors.EmptyProxyTags(target); if (target.ProxyTags.Contains(tagToAdd)) throw Errors.ProxyTagAlreadyExists(tagToAdd, target); @@ -85,7 +85,7 @@ namespace PluralKit.Bot { if (!ctx.HasNext()) throw new PKSyntaxError("You must pass a proxy tag to remove (eg. `[text]` or `J:text`)."); - var tagToRemove = ParseProxyTags(ctx.RemainderOrNull()); + var tagToRemove = ParseProxyTags(ctx.RemainderOrNull(skipFlags: false)); if (tagToRemove.IsEmpty) throw Errors.EmptyProxyTags(target); if (!target.ProxyTags.Contains(tagToRemove)) throw Errors.ProxyTagDoesNotExist(tagToRemove, target); @@ -102,7 +102,7 @@ namespace PluralKit.Bot { if (!ctx.HasNext()) throw new PKSyntaxError("You must pass an example proxy to set (eg. `[text]` or `J:text`)."); - var requestedTag = ParseProxyTags(ctx.RemainderOrNull()); + var requestedTag = ParseProxyTags(ctx.RemainderOrNull(skipFlags: false)); if (requestedTag.IsEmpty) throw Errors.EmptyProxyTags(target); // This is mostly a legacy command, so it's gonna warn if there's