Bot
rebootpy.Client and as a result anything that you can do with a rebootpy.Client you can do with this bot.
This class also subclasses GroupMixin to provide the functionality to manage commands.
Parameters
The command prefix is what the message content must contain initially to have a command invoked. This prefix could either be a string to indicate what the prefix should be, or a callable that takes in the bot as its first parameter and
rebootpy.FriendMessage or rebootpy.PartyMessage as its second parameter and returns the prefix. This is to facilitate “dynamic” command prefixes. This callable can be either a regular function or a coroutine.An empty string as the prefix always matches, enabling prefix-less command invocation.The command prefix could also be an iterable of strings indicating that multiple checks for the prefix should be used and the first one to match will be the invocation prefix.The authentication instance to use for the bot.
The help command implementation to use. This can be dynamically set at runtime. To remove the help command pass
None.The content prefixed into the default help message.
Whether the commands should be case insensitive. This attribute does not carry over to groups. You must set it to every group if you require group commands to be case insensitive as well.
The user ID that owns the bot. This is used by
is_owner() and checks that call this method. You cannot set both owner_id and owner_ids.The user IDs that owns the bot. This is similar to
owner_id. For performance reasons it is recommended to use a set for the collection. You cannot set both owner_id and owner_ids.Attributes
The command prefix for the bot.
The content prefixed into the default help message.
The help command implementation being used.
The user ID that owns the bot.
The user IDs that own the bot.
A read-only mapping of cog name to cog.
A read-only mapping of extension name to extension.
Methods
check
Context, and can only raise exceptions inherited from CommandError.
Parameters:
func: The function that will be used as a global check. Can be either a regular function or a coroutine.
add_check
check() and check_once().
Parameters:
func: The function that was used as a global check.call_once(bool): If the function should only be called once perCommand.invoke()call.
remove_check
func: The function to remove from the global checks.call_once(bool): If the function was added withcall_once=Truein theadd_check()call or usingcheck_once().
check_once
Command.invoke() call.
Example:
is_owner
user_id(str): The user id to check for.
bool - Whether the user is the owner.
before_invoke
Context.
Note: The before_invoke() and after_invoke() hooks are only called if all checks and argument parsing procedures pass without error.
Raises: TypeError - The coroutine passed is not actually a coroutine.
after_invoke
Context.
Note: This is not called unless checks and argument parsing procedures succeed. This hook is, however, always called regardless of the internal command callback raising an error.
Raises: TypeError - The coroutine passed is not actually a coroutine.
add_cog
cog(Cog): The cog to register to the bot.
TypeError: The cog does not inherit fromCog.CommandError: An error happened during loading.
remove_cog
name(str): The name of the cog to remove.
get_cog
None is returned instead.
Parameters:
name(str): The name of the cog you are requesting. This is equivalent to the name passed via keyword argument in class creation or the class name if unspecified.
Optional[Cog] - The cog instance, or None if not found.
load_extension
extension_setup defined as the entry point on what to do when the extension is loaded. This entry point must have a single argument, the bot.
Parameters:
name(str): The extension name to load. It must be dot separated like regular Python imports if accessing a sub-module. e.g.foo.testif you want to importfoo/test.py.
ExtensionNotFound: The extension could not be imported.ExtensionAlreadyLoaded: The extension is already loaded.ExtensionMissingEntryPoint: The extension does not have a extension_setup function.ExtensionFailed: The extension or its setup function had an execution error.
unload_extension
cog_teardown, to do miscellaneous clean-up if necessary. This function takes a single parameter, the bot, similar to extension_setup from load_extension().
Parameters:
name(str): The extension name to unload. It must be dot separated like regular Python imports if accessing a sub-module. e.g.foo.testif you want to importfoo/test.py.
ExtensionNotLoaded: The extension was not loaded.
reload_extension
unload_extension() followed by a load_extension() except done in an atomic way. That is, if an operation fails mid-reload then the bot will roll-back to the prior working state.
Parameters:
name(str): The extension name to reload. It must be dot separated like regular Python imports if accessing a sub-module. e.g.foo.testif you want to importfoo/test.py.
ExtensionNotLoaded: The extension was not loaded.ExtensionNotFound: The extension could not be imported.ExtensionMissingEntryPoint: The extension does not have a extension_setup function.ExtensionFailed: The extension setup function had an execution error.
get_prefix
message(Union[FriendMessage, PartyMessage]): The message context to get the prefix of.
Union[List[str], str] - A list of prefixes or a single prefix that the bot is listening for.
get_context
process_commands() to allow users more fine grained control over the processing.
The returned context is not guaranteed to be a valid invocation context, Context.valid must be checked to make sure it is.
Parameters:
message(Union[FriendMessage, PartyMessage]): The message to get the invocation context from.cls: The factory class that will be used to create the context. By default, this isContext. Should a custom class be provided, it must be similar enough toContext’s interface.
Context - The invocation context. The type of this can change via the cls parameter.
invoke
ctx(Context): The invocation context to invoke.
process_commands
get_context() followed by a call to invoke().
Parameters:
message(Union[FriendMessage, PartyMessage]): The message to process commands for.