commandkit package
Submodules
commandkit.EventManager module
This module contains a class responsible for managing event listeners and dispatching events.
- class commandkit.EventManager.EventManager(events: dict[str, list[Callable]] | None = None)[source]
Bases:
objectresponsible for managing event listeners and dispatching events.
- Parameters:
events (dict[str, list[Callable]])
- add_listen(func: Callable, name: str | None = None)[source]
adds a new event listener
- Parameters:
func (Callable) – the listener
name (str (default: None)) – the name of the listener. (uses the listeners name if None).
- async dispatch(event_name: str, /, *args, **kwargs)[source]
dispatch an event
- Parameters:
event_name (str) – the name of the event
*args – the arguments of the event
**kwargs – the keyword arguments of the event
- event(func: Callable)[source]
a decorator to add an event listener
- Parameters:
func (Callable) – the listener function
commandkit.commander module
module contains classes to manage and dispatch commands
- class commandkit.commander.CommandManager(prefix: str = '')[source]
Bases:
objectA class to manage and dispatch commands.
- add_command(command: Command)[source]
add a new command
- Parameters:
command (Command) – the command object to add
- command(name: str | None = None, description: str | None = None, **kwargs)[source]
a decorator to register a command
- Parameters:
name (str (default: None)) – the name of the command
description (str (default: None)) – a short description of the command
- get_command(name: str) Command | None[source]
get command by name or alias
- Parameters:
name (str) – the name or alias of the command
- Returns:
the command object if found
- Return type:
Optional[Command]
- async invoke(command: Command, view: StringView) Any[source]
invokes a command by parsing arguments from a StringView
- Parameters:
command (Command) – the command to invoke
view (StringView) – the view containing raw arguments
commandkit.core module
module containing Classes and functions to manage commands
- exception commandkit.core.BadArgument(message, parameters, command)[source]
Bases:
CommandErrorwhen a parsing command arguments fails
- class commandkit.core.Command(callback: Callable, name: str | None = None, description: str | None = None, **kwargs)[source]
Bases:
objectRepresents a command.
- exception commandkit.core.CommandNotFoundError(message, name)[source]
Bases:
CommandErrorwhen command doesn’t exist
commandkit.parsers module
Type conversion system for commandkit.
Converts string arguments to typed values based on annotations. Handles Union, Optional, custom converters, and callable fallback.
- class commandkit.parsers.converter.Converter[source]
Bases:
objectBase class for custom converters.
Example
class HexColor(Converter): def convert(self, argument: str) -> int: return int(argument.lstrip('#'), 16)
- class commandkit.parsers.converter.Greedy(converter: Any)[source]
Bases:
objectMarker class for greedy argument parsing.
Example: Greedy[int] consumes all successful int conversions.
- commandkit.parsers.converter.register_converter(type_: type, converter: Any) None[source]
Register a custom converter (callable or Converter instance).
- commandkit.parsers.converter.run_converters(converter: Any, argument: str) Any[source]
Convert argument using annotation. Unwraps Union/Optional first.
- Parameters:
converter (Any) – Type annotation or Converter instance.
argument (str) – Raw string to convert.
- Raises:
ConversionError – If all conversion attempts fail.
- commandkit.parsers.converter.unregister_converter(type_: type) None[source]
Remove a registered converter.
The MIT License (MIT)
Copyright (c) 2015-present Rapptz
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Module contents
commandkit is a package to make managing and implementing events managers, commands easier
- exception commandkit.BadArgument(message, parameters, command)[source]
Bases:
CommandErrorwhen a parsing command arguments fails
- class commandkit.Command(callback: Callable, name: str | None = None, description: str | None = None, **kwargs)[source]
Bases:
objectRepresents a command.
- class commandkit.CommandManager(prefix: str = '')[source]
Bases:
objectA class to manage and dispatch commands.
- add_command(command: Command)[source]
add a new command
- Parameters:
command (Command) – the command object to add
- command(name: str | None = None, description: str | None = None, **kwargs)[source]
a decorator to register a command
- Parameters:
name (str (default: None)) – the name of the command
description (str (default: None)) – a short description of the command
- get_command(name: str) Command | None[source]
get command by name or alias
- Parameters:
name (str) – the name or alias of the command
- Returns:
the command object if found
- Return type:
Optional[Command]
- async invoke(command: Command, view: StringView) Any[source]
invokes a command by parsing arguments from a StringView
- Parameters:
command (Command) – the command to invoke
view (StringView) – the view containing raw arguments
- exception commandkit.CommandNotFoundError(message, name)[source]
Bases:
CommandErrorwhen command doesn’t exist
- class commandkit.EventManager(events: dict[str, list[Callable]] | None = None)[source]
Bases:
objectresponsible for managing event listeners and dispatching events.
- Parameters:
events (dict[str, list[Callable]])
- add_listen(func: Callable, name: str | None = None)[source]
adds a new event listener
- Parameters:
func (Callable) – the listener
name (str (default: None)) – the name of the listener. (uses the listeners name if None).
- async dispatch(event_name: str, /, *args, **kwargs)[source]
dispatch an event
- Parameters:
event_name (str) – the name of the event
*args – the arguments of the event
**kwargs – the keyword arguments of the event
- event(func: Callable)[source]
a decorator to add an event listener
- Parameters:
func (Callable) – the listener function