kamihi.bot
⚓︎
Bot module for Kamihi.
This module provides the primary interface for the Kamihi framework, allowing for the creation and management of Telegram bots.
License
MIT
Modules:
| Name | Description |
|---|---|
action |
Action helper class. |
bot |
Bot module for Kamihi. |
Classes:
| Name | Description |
|---|---|
Action |
Action class for Kamihi bot. |
Bot |
Bot class for Kamihi. |
Action
⚓︎
Action(
name: str,
commands: list[str],
description: str,
func: Callable,
datasources: dict[str, DataSource] = None,
)
Action class for Kamihi bot.
This class provides helpers for defining actions, their commands and their handlers.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the action. |
commands |
list[str]
|
List of commands associated. |
description |
str
|
Description of the action. |
Initialize the Action class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
The name of the action. |
required |
|
list[str]
|
List of commands associated. |
required |
|
str
|
Description of the action. |
required |
|
Callable
|
The function to be executed when the action is called. |
required |
|
dict[str, DataSource]
|
Dictionary of data sources available for the action. |
None
|
Methods:
| Name | Description |
|---|---|
clean_up |
Clean up the action from the database. |
run_scheduled |
Execute the action in a job context. |
Source code in src/kamihi/bot/action.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
handler
property
⚓︎
handler: AuthHandler | ConversationHandler
Construct a CommandHandler for the action.
jobs
property
⚓︎
jobs: list[
tuple[
Job,
Callable[
[CallbackContext], Coroutine[Any, Any, None]
],
]
]
Return a list of jobs associated with the action.
users
property
⚓︎
users: Sequence[BaseUser]
Return a list of telegram IDs of users authorized to use the action.
clean_up
classmethod
⚓︎
clean_up(keep: list[str]) -> None
Clean up the action from the database.
Source code in src/kamihi/bot/action.py
504 505 506 507 508 509 510 511 512 | |
run_scheduled
async
⚓︎
run_scheduled(context: CallbackContext) -> None
Execute the action in a job context.
Source code in src/kamihi/bot/action.py
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 | |
Bot
⚓︎
Bot()
Bot class for Kamihi.
The framework already provides a bot instance, which can be accessed using the
bot variable. This instance is already configured with default settings and
can be used to start the bot. The managed instance is preferable to using the
Bot class directly, as it ensures that the bot is properly configured and
managed by the framework.
Initialize the Bot class.
Methods:
| Name | Description |
|---|---|
action |
Register an action with the bot. |
start |
Start the bot. |
Source code in src/kamihi/bot/bot.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
action
⚓︎
action(
*commands: str, description: str = None
) -> partial[Action]
Register an action with the bot.
This method overloads the bot.action method so the decorator can be used
with or without parentheses.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
A list of command names. If not provided, the function name will be used. |
()
|
|
str
|
A description of the action. This will be used in the help message. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Callable |
partial[Action]
|
The wrapped function. |
Source code in src/kamihi/bot/bot.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | |
start
⚓︎
start() -> None
Start the bot.
Source code in src/kamihi/bot/bot.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |