Module
The module object is passed to the main function of the module.
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__.pyfrom utils import *
async def main(app: Client, mod: Module):
cmd = mod.cmd
@cmd(['cmd', 'my_command'])
async def _cmd(_, msg: M):
pass
Methods
-
get_groupReturns a new group of the module for handlers
Arguments: None
Returns: str - A new group of the module
-
add_taskAdds 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_buttonsPrepares buttons. See Buttons
Arguments:
buttons(Buttons) - Buttons to be prepared
Returns: Buttons - Prepared buttons
-
async
send_buttonsSends buttons to a specific chat. See Buttons
Arguments:
chat_id(str|int) - Chat ID or username of the chat to send buttons totext(str) - Message textbuttons(Buttons) - Buttons**kwargs- Parameters forClient.send_inline_bot_result
Returns: Message - Sent message
Decorators
-
on_readyA decorator that is called when the bot is launched
See @mod.on_ready
Example:
Module/__init__.pyfrom utils import *
async def main(app: Client, mod: Module):
@mod.on_ready
async def _onr(app: Client):
mod.logger.info("RimTUB has started!") -
callbackCallback handler. See Buttons
Arguments:
callback_data(Optional, str) - Exact match of callback datastartswith(Optional, str) - Beginning of callback data.group(Optional, int) - Handler groupis_private(Optional, bool) = True - Private button.allowed_ids(Optional, List[int]) - Ifis_private==True: user_ids of those who can press the buttonmessage(Optional, str) ='This is not your button!'- Ifis_private==True: Message displayed if access to the button is deniedshow_alert(Optional, bool) = True - Ifis_private==True: Whether to display the error message as a popup or not (parametershow_alertinClient.answer_callback_query)
infoIf neither
callback_datanorstartswithare specified, all callbacks will be accepted.