Example #1
0
    def __init__(self,
                 name,
                 description=None,
                 parent=None,
                 command_string=None,
                 function=None):
        """
        name            : str                                   - The name of the command
        description     : str | None                            - A description for the command
        parent          : discord_cli.command.Command | None    - The parent command of the command
        command_string  : str | None                            - The full command identifier including ancestor commands' names
        function        : function | None                       - The executable function associated with this command

        Raises discord_cli.exceptions.Discord_CLI_Error if inputs are not valid
        """

        try:
            validation.validate_command_name(name)
        except exceptions.Discord_CLI_Error as e:
            raise type(e)('Command name {}'.format(str(e)))

        try:
            if description is not None:
                validation.validate_string(description)
        except exceptions.Discord_CLI_Error as e:
            raise type(e)('Command description {}'.format(str(e)))

        if function is not None and not iscoroutinefunction(function):
            raise exceptions.Not_Async_Function_Error(
                'Command function must be an async function')

        self._name = name
        self._description = description

        self._parent = parent
        self._function = function

        self._command_string = command_string

        self._argument_builder = Argument_Builder(self)
        self._option_builder = Option_Builder(self)
        self._tag_builder = Tag_Builder(self)
        self._permission_builder = Permission_Builder(self)

        self._sub_commands = {}
        self._sub_command_count = 0
Example #2
0
    def __init__(self, name, description, letter, word, parser):
        """
        If letter is None, the first letter of the name
        is used instead.

        name            : str                               - The name of the option
        description     : str | None                        - A description of the option
        letter          : str | None                        - The letter identifier for the option (If None, set to the first letter of the name)
        word            : str | None                        - The word identifier of the option
        parser          : discord_cli.parsers.Base_Parser   - The parser used to parse this option

        Raises discord_cli.exceptions.Discord_CLI_Error if inputs are not valid
        """

        try:
            validation.validate_word(name)
        except exceptions.Discord_CLI_Error as e:
            raise type(e)('Option name {}'.format(str(e)))

        try:
            if description is not None:
                validation.validate_string(description)
        except exceptions.Discord_CLI_Error as e:
            raise type(e)('Option description {}'.format(str(e)))

        if letter is None:
            letter = name[0]

        try:
            validation.validate_letter(letter)
        except exceptions.Discord_CLI_Error as e:
            raise type(e)('Option letter {}'.format(str(e)))

        try:
            if word is not None:
                validation.validate_word(word)
        except exceptions.Discord_CLI_Error as e:
            raise type(e)('Option word {}'.format(str(e)))

        self._name = name
        self._description = description
        self._letter = letter
        self._word = word

        self._parser = parser
Example #3
0
    def __init__(self, name, description, letter, word):
        """
        name        : str           - The name of the tag
        description : str | None    - A description of the tag
        letter      : str | None    - The letter identifier of the tag (If None, the first letter of name is used)
        word        : str | None    - The word identifier of the tag

        Raises discord_cli.exceptions.Discord_CLI_Error if inputs are not valid
        """

        try:
            validation.validate_word(name)
        except exceptions.Discord_CLI_Error as e:
            raise type(e)('Tag name {}, \'{}\' given'.format(str(e), name))

        try:
            if description is not None:
                validation.validate_string(description)
        except exceptions.Discord_CLI_Error as e:
            raise type(e)('Tag description {}, \'{}\' given'.format(
                str(e), description))

        if letter is None:
            letter = name[0]

        try:
            validation.validate_letter(letter)
        except exceptions.Discord_CLI_Error as e:
            raise type(e)('Tag letter {}, \'{}\' given'.format(str(e), letter))

        try:
            if word is not None:
                validation.validate_word(word)
        except exceptions.Discord_CLI_Error as e:
            raise type(e)('Tag word {}, \'{}\' given'.format(str(e), word))

        self._name = name
        self._description = description
        self._letter = letter
        self._word = word
Example #4
0
    def __init__(self, name, description, parser):
        """
        name        : str                               - The name of the argument
        description : str | None                        - A description of the argument
        parser      : discord_cli.parsers.Base_Parser   - The parser used to parse this argument

        Raises discord_cli.exceptions.Discord_CLI_Error if inputs are not valid
        """

        try:
            validation.validate_word(name)
        except exceptions.Discord_CLI_Error as e:
            raise type(e)('Argument name {}'.format(str(e)))

        try:
            if description is not None:
                validation.validate_string(description)
        except exceptions.Discord_CLI_Error as e:
            raise type(e)('Argument description {}'.format(str(e)))

        self._name = name
        self._description = description

        self._parser = parser