instance module

Note

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

Here is defined a bot instance. This class managing all framework elements in one. If you not an advanced developer, you may use an ezbotf-cli. To get help about it, you must type in your terminal: # ezbotf -h

BotInstance

The BotInstance is main class of all. Instance of it class manages all required things, as: PluginManager, Context, etc. Also, handles a messages from the Telegram (method: BotInstance.handle_message())

Quick usage of this class:

import ezbotf
from pathlib import Path

instance = ezbotf.BotInstance()
instance.import_config(Path('<PATH TO THE CONFIG OF INSTANCE>'))  # Set ups config
instance.quick_run()  # Calls all required methods to start an instance

Note

You must create a file with the configuration of instance. See Instance Configuration about this.

class ezbotf.instance.BotInstance(config: dict[str, Any] | None = None)

Instance of the bot

Variables:
  • config – TOML config of instance

  • logger – Logger of instance

  • main_group – Main logger group of instance. All loggers will be use it as parent

__init__(config: dict[str, Any] | None = None)
Parameters:

config – Preloaded TOML dict config to use. If it not set, you must use import_config() method

import_config(path: Path)

Imports a TOML config from path to instance

Parameters:

path – Path to the config

Raises:

IncorrectInstanceConfigError – When config is not have required parameters

setup_context()

Setups a context attribute that shared between ezbot framework elements and plugins

initialize(parent_logger_group: LoggerGroup | str | None = None)

Initializes all values in instance, such as PluginLoader, working context, Logger and other

Parameters:

parent_logger_group – Parent logger of this instance

load()

Loads all required items (such as PluginLoader and TelegramClient)

run()

Runs an instance

quick_run()

Calls all required methods to start the instance (before using it, you must use import_config() method). Shorthand for the initialize(), load(), run() methods

async handle_message(event: EventBuilder)

Handles a message (Parses and search for the commands)

Parameters:

event – Event of the message from Telethon