korone.modules package

Subpackages

Submodules

korone.modules.core.MODULES = {}

A dictionary that stores information about the modules.

Examples

>>> MODULES = {
...     "dummy": {
...         "info": {
...             "name": "Dummy System",
...             "summary": "The Dummy System is a special system implemented into Dummy Plugs.",
...             "doc": "Entry Plugs are capsule-like tubes which acts as the cockpit for Evangelion pilots."
...         },
...         "handlers": [
...             "pm_menu.handlers.eva00"
...             "pm_menu.handlers.eva01",
...             "pm_menu.handlers.eva02",
...         ]
...     }
... }
korone.modules.core.COMMANDS = {}

Korone’s command structure.

Examples

>>> COMMANDS = {
...     "evangelion": {
...         "chat": {
...             -100123456789: True,
...             -100987654321: False,
...         },
...         "children": [
...             "eva01",
...             "eva02",
...         ],
...     },
...     "eva01": {
...         "parent": "evangelion",
...     },
...     "eva02": {
...         "parent": "evangelion",
...     },
... }
korone.modules.core.NOT_DISABLEABLE = []

A list of commands that cannot be disabled.

Type:

list[str]

korone.modules.core.add_module_info(module_name, module_info)[source]

Add module information to the MODULES dictionary.

This function adds information about a module to the MODULES dictionary.

Parameters:
  • module_name (str) – The name of the module.

  • module_info (Callable) – The module information. This should be a callable object that provides information about the module, such as its name, summary, and documentation.

Raises:

ValueError – If any of the required attributes are missing in the module information.

Notes

The module_info parameter should be a callable object that returns a dictionary with the following attributes:

  • ‘name’ (str): The name of the module.

  • ‘summary’ (str): A brief summary of the module’s functionality.

  • ‘doc’ (str): The documentation for the module.

korone.modules.core.add_handlers(module_name, handlers_path)[source]

Add handlers to the MODULES dictionary.

This function adds handlers to the MODULES dictionary. Each handler is represented as a string in the format “{module_name}.handlers.{handler_name}” and is appended to the list of handlers for the specified module in the MODULES dictionary.

Parameters:
  • module_name (str) – The name of the module.

  • handlers_path (Path) – The path to the handlers directory.

korone.modules.core.add_modules_to_dict()[source]

Add modules to the MODULES dictionary.

This function searches for modules in the korone.modules package and adds them to the MODULES dictionary. It looks for modules in the handlers subdirectory of each module’s directory. If a module has a ModuleInfo class defined, it adds the module information to the MODULES dictionary. It also adds the handlers found in the handlers subdirectory to the MODULES dictionary.

Notes

The MODULES dictionary is a global dictionary used to store information about the modules and their handlers.

korone.modules.core.get_method_callable(cls, key)[source]

Get a callable method from a class.

This function checks if the method is a static method or an asynchronous method. If it is a static method, it returns the method itself. If it is an asynchronous method, it returns an async function that calls the method. Otherwise, it returns a regular function that calls the method.

Parameters:

key (str) – The name of the method to retrieve.

Returns:

collections.abc.Callable[..., typing.Any] – The callable method.

Examples

>>> class MyClass:
...     def my_method(self):
...         return "Hello, world!"
>>> my_instance = MyClass()
>>> get_method_callable(MyClass, "my_method")(my_instance)
'Hello, world!'
async korone.modules.core.check_command_state(command)[source]

Check the state of a command.

This function checks the state of a command in the database and returns the command state.

Parameters:

command (str) – The command to check.

Returns:

Documents | None – The command state if it exists, None otherwise.

async korone.modules.core.process_handler_commands(filters)[source]

Handle the commands associated with a handler.

This function process the commands associated with a handler. It updates the command structure with the specified commands and their chat state.

Parameters:

filters (KoroneFilters) – The filters associated with the handler.

async korone.modules.core.update_commands(commands)[source]

Update the COMMANDS dictionary with the specified commands.

This function updates the COMMANDS dictionary with the specified commands and their chat state.

Parameters:

commands (list[str]) – The list of commands to update.

async korone.modules.core.register_handler(client, module)[source]

Register handlers for a module in the client.

This function searches for classes in the module that are subclasses of MessageHandler or CallbackQueryHandler, and that have methods that are instances of FunctionType. It adds these methods as handlers in the client.

If a handler has associated commands, the function checks and updates the state of these commands.

Parameters:
Returns:

bool – True if at least one handler was successfully registered, False otherwise.

async korone.modules.core.load_module(client, module)[source]

Load specified module.

This function loads a module into the Hydrogram’s Client.

Parameters:
  • client (hydrogram.Client) – The Hydrogram’s Client instance.

  • module (tuple) – The module to be loaded.

Returns:

bool – True if the module was loaded successfully, False otherwise.

Raises:
async korone.modules.core.load_all_modules(client)[source]

Load all modules.

This function loads all modules from the korone.modules package.

Parameters:

client (hydrogram.Client) – The client object.