Skip to main content
Version: 2.2.2-1

Module

The module object is passed to the main function of the module.

Module/__init__.py
from utils import *

async def main(app: Client, mod: Module):
pass

This object is used for all main actions with the module: registering commands, sending buttons, obtaining groups, etc.


Parameters

  • name (str) - The name of the module

  • path (pathlib.Path) - Path to the module folder for working with files

  • db_path (pathlib.Path) - Path to the module's SQL database. See SQL DataBase (db)

  • db (ModuleDB) - SQL Database. See SQL DataBase (db)

  • st (DictStorage) - Temporary storage based on a dictionary. See Temporary Storage (st)

  • logger (logging.Logger) - Module logger. All logs should be output through it.

  • manifest (dict) - Loaded data from manifest.yaml

  • group (int) - The main group of the module. Used in handlers

  • cmd (NCmd) - Object for registering command handlers.

    See Command Handlers

    Example

    Module/__init__.py
    from utils import *

    async def main(app: Client, mod: Module):

    cmd = mod.cmd

    @cmd(['cmd', 'my_command'])
    async def _cmd(_, msg: M):
    pass

Methods

  • get_group

    Returns a new group of the module for handlers

    Arguments: None

    Returns: str - A new group of the module

  • add_task

    Adds a task to the execution queue (ev.create_task)

    Example:

    async def worker(arg):
    pass

    mod.add_task(worker(arg))

    Arguments:

    • coro (Coroutine) - Coroutine to be executed.

    Returns: asyncio.Task - Task object

  • async prepare_buttons

    Prepares buttons. See Buttons

    Arguments:

    • buttons (Buttons) - Buttons to be prepared

    Returns: Buttons - Prepared buttons

  • async send_buttons

    Sends buttons to a specific chat. See Buttons

    Arguments:

    • chat_id (str|int) - Chat ID or username of the chat to send buttons to
    • text (str) - Message text
    • buttons (Buttons) - Buttons
    • **kwargs - Parameters for Client.send_inline_bot_result

    Returns: Message - Sent message


Decorators

  • on_ready

    A decorator that is called when the bot is launched

    See @mod.on_ready

    Example:

    Module/__init__.py
    from utils import *

    async def main(app: Client, mod: Module):

    @mod.on_ready
    async def _onr(app: Client):
    mod.logger.info("RimTUB has started!")
  • callback

    Callback handler. See Buttons

    Arguments:

    • callback_data (Optional, str) - Exact match of callback data
    • startswith (Optional, str) - Beginning of callback data.
    • group (Optional, int) - Handler group
    • is_private (Optional, bool) = True - Private button.
    • allowed_ids (Optional, List[int]) - If is_private==True: user_ids of those who can press the button
    • message (Optional, str) = 'This is not your button!' - If is_private==True: Message displayed if access to the button is denied
    • show_alert (Optional, bool) = True - If is_private==True: Whether to display the error message as a popup or not (parameter show_alert in Client.answer_callback_query)  
    info

    If neither callback_data nor startswith are specified, all callbacks will be accepted.