예제 #1
0
    def _help(self, data, connection):
        """
        Command to provide in-game help with commands.

        If invoked with no arguments, lists all commands available to a player.
        When invoked with a trailing command, provides usage details for the
        command.

        :param data: The packet containing the command.
        :param connection: The connection which sent the command.
        :return: Null.
        """
        if not data:
            commands = []
            for c, f in self.commands.items():
                if connection.player.perm_check(f.perm):
                    commands.append(c)
            send_message(connection,
                         "Available commands: {}".format(" ".join(
                             [command for command in sorted(commands)])))
        else:
            try:
                docstring = self.commands[data[0]].__doc__
                send_message(connection,
                             "Help for {}: {}".format(data[0], docstring),
                             get_syntax(data[0],
                                        self.commands[data[0]],
                                        self.command_prefix))
            except KeyError:
                self.logger.error("Help failed on command {}.".format(data[0]))
                send_message(connection,
                             "Unknown command {}.".format(data[0]))
예제 #2
0
파일: help.py 프로젝트: thakyZ/StarryPy3k
    def _help(self, data, connection):
        """
        Command to provide in-game help with commands.

        If invoked with no arguments, lists all commands available to a player.
        When invoked with a trailing command, provides usage details for the
        command.

        :param data: The packet containing the command.
        :param connection: The connection which sent the command.
        :return: Null.
        """
        if not data:
            commands = []
            for c, f in self.commands.items():
                if connection.player.perm_check(f.perm):
                    commands.append(c)
            send_message(
                connection, "Available commands: {}".format(" ".join(
                    [command for command in sorted(commands)])))
        else:
            try:
                docstring = self.commands[data[0]].__doc__
                send_message(
                    connection, "Help for {}: {}".format(data[0], docstring),
                    get_syntax(data[0], self.commands[data[0]],
                               self.command_prefix))
            except KeyError:
                self.logger.error("Help failed on command {}.".format(data[0]))
                send_message(connection, "Unknown command {}.".format(data[0]))
예제 #3
0
    def _send_syntax_error(self, command, error, connection):
        """
        Sends a syntax error to the user regarding a command.

        :param command: The command name
        :param error: The error (a string or an exception)
        :param connection: The player connection.
        :return: None.
        """
        send_message(
            connection, "Syntax error: {}".format(error),
            get_syntax(command, self.commands[command],
                       self.plugin_config.command_prefix))
        return None
예제 #4
0
    def _send_syntax_error(self, command, error, connection):
        """
        Sends a syntax error to the user regarding a command.

        :param command: The command name
        :param error: The error (a string or an exception)
        :param connection: The player connection.
        :return: None.
        """
        send_message(connection,
                     "Syntax error: {}".format(error),
                     get_syntax(command,
                                self.commands[command],
                                self.plugin_config.command_prefix))
        return None