πModule structure
A module is a Python module (directory with __init__.py
file) of a special structure.
core
βββ extensions
βΒ Β βββ logs.py
βΒ Β βββ mod_manage.py
βΒ Β βββ permissions.py
βββ info.yaml
βββ __init__.py
βββ main.py
βββ strings
βββ en.yaml
βββ ru.yaml
Structure example
The heart of the module is the BaseModule
super-class, which provides the necessary API for the module's operation, as well as performs its initialization. The module class must inherit from BaseModule
from base.module import BaseModule
class CoreModule(BaseModule):
In __init__.py
there must be an import of a new module class, otherwise the loader just won't see it
from .main import CoreModule
All information about the module is described in the YAML file info.yaml
. It includes: title, author, version, description, and permissions (more about them later). An example of such a file:
info:
name: BestModule
author: Developers
version: 0.0.1
description: Just best module, lol
src_url: https://bestgit.org/BestModule
# Use raw loader object. Very dangerous permission!
permissions:
- use_loader
Module commands are created as class methods, with the same arguments as a normal handler in pyrogram, except that special decorators must be used (more details in the next section).
ModuleExtension
classes allow you to break module code into files without losing important class attributes. In the example above, the files with extensions are located in the extensions
folder, although they can be located however you want, it's up to you.
The module has a built-in translation system. When loading, the module checks the strings folder, and loads the translation files as dictionaries into the rawS
attribute, then selects the currently active language (specified in the bot's config) and loads it into the S
attribute. Example usage:
text = self.S["help"]["header"]
Last updated