From 8b19f25ed295fe39fa40b751ae7d2b54532a37aa Mon Sep 17 00:00:00 2001 From: Ske Date: Thu, 30 May 2019 20:24:17 +0200 Subject: [PATCH] Split command segments on any whitespace, not just spaces --- src/pluralkit/bot/commands/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/pluralkit/bot/commands/__init__.py b/src/pluralkit/bot/commands/__init__.py index e5aa319e..53e6d9e8 100644 --- a/src/pluralkit/bot/commands/__init__.py +++ b/src/pluralkit/bot/commands/__init__.py @@ -11,6 +11,11 @@ from pluralkit.errors import PluralKitError from pluralkit.member import Member from pluralkit.system import System +def find_with_predicate(s: str, pred) -> int: + for i, v in enumerate(s): + if pred(v): + return i + return -1 def next_arg(arg_string: str) -> Tuple[str, Optional[str]]: # A basic quoted-arg parser @@ -25,7 +30,7 @@ def next_arg(arg_string: str) -> Tuple[str, Optional[str]]: else: return arg_string[1:], None - next_space = arg_string.find(" ") + next_space = find_with_predicate(arg_string, lambda ch: ch.isspace()) if next_space >= 0: return arg_string[:next_space].strip(), arg_string[next_space:].strip() else: