Exemplo n.º 1
0
def test_create_text_response_with_update_message():
    assert create_text_response("hello", update_message=True) == {
        "actionResponse": {
            "type": "UPDATE_MESSAGE"
        },
        "text": "hello",
    }
Exemplo n.º 2
0
    def handle(self, arguments, **kwargs):
        text = [
            "Commands available:",
            "",
        ]

        for key, command in kwargs.pop("commands", OrderedDict()).items():
            if command.hidden:
                continue

            if key != command.command:
                # must be an alias
                continue

            if command.arguments:
                text.append(
                    f"*`{command.command}`*`{command.arguments}`\n{command.description}\n"
                )
            else:
                text.append(f"*`{command.command}`*\n{command.description}\n")

        text.append(
            'HINT: If you need to specify multiple words for a parameter, use quotes (").'
        )

        return create_text_response("\n".join(text))
Exemplo n.º 3
0
    def _invalid_command(command):
        text = [
            f"Invalid command: *{command}*",
            "",
            "Please, type *help* for more information about the commands available.",
        ]

        return create_text_response("\n".join(text))
Exemplo n.º 4
0
    def _invoke_commands(self, args, **kwargs):
        command = args.pop(0).lower()

        if command not in self._commands:
            return self._invalid_command(command)

        try:
            self._kwargs.update(kwargs)
            self._kwargs.update({"commands": self._commands})

            klass = self._commands.get(command)
            return klass().handle(args, **self._kwargs)
        except Exception as exc:
            logging.exception(exc)
            return create_text_response("Oops, something went wrong!")
Exemplo n.º 5
0
    def _on_added_to_space(self):
        space = self._payload["space"]
        user = self._payload["user"]

        logging.info("Bot added to space: %s", space)

        text = ""

        if space["type"] == "ROOM":
            text = f'Hello people! Thanks for adding me to *{space["displayName"]}*!'

        elif space["type"] == "DM":
            text = f'Hello <{user["name"]}>! How are you?'

        text += (
            "\n\nPlease, type *help* for more information about the commands available."
        )

        return create_text_response(text)
Exemplo n.º 6
0
 def handle(self, arguments, **kwargs):
     return create_text_response("Ciao!")
Exemplo n.º 7
0
 def handle(self, arguments, **kwargs):
     return create_text_response(f"Hello, {arguments[0]}!")
Exemplo n.º 8
0
 def handle(self, arguments, **kwargs):
     return create_text_response(f"Repository = {kwargs['repository']}")
Exemplo n.º 9
0
def test_create_text_response_with_invalid_arguments():
    with pytest.raises(ValueError):
        create_text_response(None)
Exemplo n.º 10
0
def test_create_text_response():
    assert create_text_response("hello") == {"text": "hello"}