pluginloader module

Note

This module is imports as from .. import *. This means that there is no need to import it separately or use ezbotf.pluginloader.PluginManageFunction. You can simply use ezbotf.PluginLoader as example.

Contains all to load plugins. The most useful thing is PluginLoader.

PluginManageFunction

A type-hint for the functions, that required for PluginLoader.apply_on_plugins()

PluginLoader

PluginLoader is used for manage plugins and load it (as can guess from it name). You mustn’t to manually use it, use BotInstance.

class ezbotf.pluginloader.PluginLoader(plugins_dir: Path, translator_lang: str)

Loads and manage all plugins in the given directory

Variables:
  • plugins_dir – Directory with the plugins

  • translator_lang – Language for the plugin translators

  • plugins – List with the initialized plugins

  • logger – Logger of the PluginLoader

  • plugins_group – Group of logger for the plugins

  • context – Working context

  • commands – Dict with the commands

__init__(plugins_dir: Path, translator_lang: str)
Parameters:
  • plugins_dir – Directory with the plugins

  • translator_lang – Language for the plugin translators

initialize(main_group: LoggerGroup, context: Context)

Initializes all elements to work (loggers and context link)

Parameters:
  • main_group – Main logger group for the all loggers (Plugins logger group, PluginsLoader logger)

  • context – Working context (must be InstanceContext)

import_plugin(plugin_dir: Path, config_path: Path) Plugin | None

Imports a plugin. Every plugin must have “plugin.toml” configuration file and main executable file. Also, there must be two folders: “lang” and “config”

Parameters:
  • plugin_dir – Directory with the plugin

  • config_path – Path to the plugin configuration file

Returns:

Plugin if it successfully loaded and initialized, otherwise None will be returned

initialize_plugins()

Initializes all plugins in “plugins_dir” directory to plugins list

load_plugin(plugin: Plugin)

Loads a Plugin, if it is not failed. Loads the runtime config and translator, after calls method Plugin._load() Also, adds all plugin commands to PluginLoader commands dictionary

Parameters:

pluginPlugin to load

unload_plugin(plugin: Plugin)

Unloads a Plugin, if it is not failed. Unloads the runtime config and sets translator to None, after calls method Plugin._unload() Also, deletes all plugin commands from PluginLoader commands dictionary

Parameters:

pluginPlugin to unload

start_plugin(plugin: Plugin)

Starts a Plugin, if it is not failed

Parameters:

pluginPlugin to start

reload_plugin(plugin: Plugin)

Unloads Plugin by unload_plugin() method, reloads plugin python executable (re-import) and loads back by load_plugin() method. It is usable for plugin development

Parameters:

pluginPlugin to reload

apply_on_plugins(action: str, function: Callable[[Plugin], None])

Sorts all initialized plugins by Core,Library,Standalone types and priority. After, activates it with function

Parameters:
  • action – Action that be used there

  • function – Function to call on each plugin

load_plugins()

Load all plugins, Shorthand for the apply_on_plugins()

unload_plugins()

Unloads all plugins, Shorthand for the apply_on_plugins()

start_plugins()

Starts all plugins, Shorthand for the apply_on_plugins()

get_command(command: str) Coroutine[EventBuilder, Context, None] | None

Tries to get a command from commands dictionary

Parameters:

command – Command name

Returns:

PluginCommand function, if command is exists and parent plugin of command is enabled and not failed. Otherwise, returns None