pyplanet.contrib.command¶
The commands contributed package contains command management and callback logic.
-
class
pyplanet.contrib.command.
CommandManager
(instance)[source]¶ The Command Manager contributed extension is a manager that controls all chat-commands in the game. Your app needs to use this manager to register any custom commands you want to provide.
You should access this class within your app like this:
self.instance.command_manager
You can register your commands like this:
await self.instance.command_manager.register( Command(command='reboot', target=self.reboot_pool, perms='admin:reboot', admin=True), )
More information of the command and the options of it, see the
pyplanet.contrib.command.Command
class.Warning
Don’t initiate this class yourself. Access this class from the
self.instance.command_manager
instance.-
async
execute
(player, command, *args)[source]¶ Execute a command for the given player with the given args.
- Parameters
player (pyplanet.apps.core.maniaplanet.models.player.Player) – Player instance.
command (pyplanet.contrib.command.command.Command) – Command instance.
args – Args for the command, will be concat into a string with spaces.
- Returns
-
async
-
class
pyplanet.contrib.command.
Command
(command, target, aliases=None, admin=False, namespace=None, parser=None, perms=None, description=None)[source]¶ The command instance describes the command itself, the target to fire and all other related information, like admin command or aliases.
Some examples of some commands:
# Admin command with permission on it. Command(command='reboot', target=self.reboot_pool, perms='admin:reboot', admin=True) # Normal user command with optional argument. Command(command='list', target=self.show_map_list) .add_param(name='search', required=False)
-
add_param
(name: str, nargs=1, type=<class 'str'>, default=None, required: bool = True, help: str = None, dest: str = None)[source]¶ Add positional parameter.
- Parameters
name – Name of parameter, will be used to store result into!
nargs – Number of arguments, use integer or ‘*’ for multiple or infinite.
type – Type of value, keep str to match all types. Use any other to try to parse to the type.
default – Default value when no value is given.
required – Set the parameter required state, defaults to true.
help – Help text to display when parameter is invalid or not given and required.
dest – Destination to save into namespace result (defaults to name).
- Returns
parser instance
- Return type
pyplanet.contrib.command.command.Command
-
get_params
(input)[source]¶ Get params in array from input in array.
- Parameters
input (list) – Array of raw input.
- Returns
Array of parameters, stripped of the command name and namespace, if defined.
- Return type
list
-
async
handle
(instance, player, argv)[source]¶ Handle command parsing and execution.
- Parameters
player (pyplanet.apps.core.maniaplanet.models.player.Player) – Player object.
argv – Arguments in array
-
match
(raw)[source]¶ Try to match the command with the given input in array style (splitted by spaces).
- Parameters
raw (list) – Raw input, split by spaces.
- Returns
Boolean if command matches.
-
property
usage_text
¶ The usage text line for the command.
-
-
class
pyplanet.contrib.command.
ParameterParser
(prog=None)[source]¶ Parameter Parser.
Todo
Write introduction + examples.
-
add_param
(name: str, nargs=1, type=<class 'str'>, default=None, required: bool = True, help: str = None, dest: str = None)[source]¶ Add positional parameter.
- Parameters
name – Name of parameter, will be used to store result into!
nargs – Number of arguments, use integer or ‘*’ for multiple or infinite.
type – Type of value, keep str to match all types. Use any other to try to parse to the type.
default – Default value when no value is given.
required – Set the parameter required state, defaults to true.
help – Help text to display when parameter is invalid or not given and required.
dest – Destination to save into namespace result (defaults to name).
- Returns
parser instance
- Return type
-
property
errors
¶ Get errors.
- Returns
array of strings.
- Return type
list
-
-
exception
pyplanet.contrib.command.exceptions.
InvalidParamException
[source]¶ Invalid parameter arguments given!