Exemple #1
0
def parse_command(content: str, context: Message=None, client: Client=None) -> Command:
    """Returns the given content string as a command, if it's formatted as one, else None.
    Optionally with the given message as context."""
    match = regex.search(r"^" + regex.escape(get_prefix(context)) + r"([A-Za-z]+) ?(.+)?", content)
    if match:
        name = match.group(1)
        args = match.group(2)

        if args:
            args_respecting_quotes = [unescape(arg) for arg, _ in split_unescaped(args, (" ",))]
            return Command(name, *args_respecting_quotes, context=context, client=client)
        return Command(name, context=context, client=client)
    return None
Exemple #2
0
def test_unescape_no_quotes():
    assert unescape("no quotes") == "no quotes"
Exemple #3
0
def test_unescape_different_quotes():
    assert unescape("”“different \"quotes”\"“") == "different \"quotes”"
Exemple #4
0
def test_unescape():
    assert unescape("\"normal \"quotes\"\"") == "normal \"quotes\""