Exemplo n.º 1
0
    def _on_message(self):
        args = parse(self._payload["message"])
        sender = self._payload["message"]["sender"]

        logging.info("Args parsed: %s", args)

        if len(args) == 0:
            args = ["help"]

        return self._invoke_commands(args, sender=sender)
Exemplo n.º 2
0
def test_more_mentions_payload():
    args = parse({
        "text":
        "@Tech Gallery hello @Jean Pimentel",
        "annotations": [
            {
                "type": "USER_MENTION",
                "startIndex": 0,
                "length": 13,
                "userMention": {
                    "user": {
                        "name": "users/123456",
                        "displayName": "Tech Gallery",
                        "avatarUrl":
                        "https://lh3.googleusercontent.com/NjgynwOVAgrdI1",
                        "type": "BOT",
                    },
                    "type": "MENTION",
                },
            },
            {
                "type": "USER_MENTION",
                "startIndex": 20,
                "length": 14,
                "userMention": {
                    "user": {
                        "name": "users/123789",
                        "displayName": "Jean Pimentel",
                        "avatarUrl":
                        "https://lh3.googleusercontent.com/a-/AAstDdyXmUsl2w",
                        "email": "*****@*****.**",
                        "type": "HUMAN",
                    },
                    "type": "MENTION",
                },
            },
        ],
    })

    assert args == ["hello", "*****@*****.**"]
Exemplo n.º 3
0
def test_bot_mention_payload():
    args = parse({
        "text":
        "@Tech Gallery hello world",
        "annotations": [{
            "type": "USER_MENTION",
            "startIndex": 0,
            "length": 13,
            "userMention": {
                "user": {
                    "name": "users/123456",
                    "displayName": "Tech Gallery",
                    "avatarUrl":
                    "https://lh3.googleusercontent.com/NjgynwOVAgrdI1",
                    "type": "BOT",
                },
                "type": "MENTION",
            },
        }],
    })

    assert args == ["hello", "world"]
Exemplo n.º 4
0
def test_invalid_payload():
    with pytest.raises(ValueError):
        parse({})
Exemplo n.º 5
0
def test_mention_without_annotations_payload():
    args = parse({"text": "@Tech Gallery hello world"})

    assert args == ["@Tech", "Gallery", "hello", "world"]
Exemplo n.º 6
0
def test_quoted_payload():
    args = parse({"text": 'Hi! "Hello World"'})

    assert args == ["Hi!", "Hello World"]
Exemplo n.º 7
0
def test_simple_quoted_payload():
    args = parse({"text": '"Hello World"'})

    assert args == ["Hello World"]
Exemplo n.º 8
0
def test_spaced_payload():
    args = parse({"text": "Hello World"})

    assert args == ["Hello", "World"]
Exemplo n.º 9
0
def test_simple_payload():
    args = parse({"text": "Hello"})

    assert args == ["Hello"]
Exemplo n.º 10
0
def test_invalid_key_payload():
    with pytest.raises(ValueError):
        parse({"txt": None})