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. |
models |
Database models for the bot module. |
utils |
Utilities and constants for the bot module. |
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,
)
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 |
Methods:
Name | Description |
---|---|
clean_up |
Clean up the action from the database. |
is_valid |
Check if the action is valid. |
save_to_db |
Save the action to the database. |
Source code in src/kamihi/bot/action.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
|
clean_up
classmethod
⚓︎
clean_up(keep: list[str]) -> None
Clean up the action from the database.
Source code in src/kamihi/bot/action.py
145 146 147 148 |
|
is_valid
⚓︎
is_valid() -> bool
Check if the action is valid.
Source code in src/kamihi/bot/action.py
134 135 136 |
|
save_to_db
⚓︎
save_to_db() -> RegisteredAction
Save the action to the database.
Source code in src/kamihi/bot/action.py
138 139 140 141 142 143 |
|
Bot
⚓︎
Bot(settings: KamihiSettings)
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.
Attributes:
Name | Type | Description |
---|---|---|
settings |
KamihiSettings
|
The settings for the bot. |
templates |
Templates
|
The templates loaded by the bot. |
Initialize the Bot class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
KamihiSettings
|
The settings for the bot. |
required |
Methods:
Name | Description |
---|---|
action |
Register an action with the bot. |
start |
Start the bot. |
user_class |
Set the user model for the bot. |
Source code in src/kamihi/bot/bot.py
65 66 67 68 69 70 71 72 73 74 75 76 |
|
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
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
|
start
⚓︎
start() -> None
Start the bot.
Source code in src/kamihi/bot/bot.py
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 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
|
user_class
⚓︎
user_class(cls: type[User]) -> None
Set the user model for the bot.
This method is used as a decorator to set the user model for the bot.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
type[User]
|
The user class to set. |
required |
Source code in src/kamihi/bot/bot.py
125 126 127 128 129 130 131 132 133 134 135 |
|