Справочник API
Bot
The main Bot class that orchestrates API communication and message handling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
str
|
Your unique API key for authentication. |
required |
base_url
|
str
|
The base URL for the bot API endpoint. Defaults to the official DeadRat API. |
DEFAULT_API_URL
|
Source code in src\deadrat\__init__.py
169 170 171 172 173 174 175 176 177 178 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 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 | |
command
Decorator: Registers a function to handle a specific command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trigger
|
str
|
The command string (e.g., "/start" or "!help"). |
required |
Source code in src\deadrat\__init__.py
delete_message
Deletes a message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
SentMessage | str
|
The SentMessage object or the message ID string to delete. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True on success, False on failure. |
Source code in src\deadrat\__init__.py
edit_message
Edits an existing message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
SentMessage | str
|
The SentMessage object or the message ID string to edit. |
required |
new_text
|
str
|
The new text content. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True on success, False on failure. |
Source code in src\deadrat\__init__.py
event
Decorator: Registers a handler for lifecycle events.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_name
|
str
|
The event type. Options: |
required |
Source code in src\deadrat\__init__.py
on_message
Decorator: Registers a handler for all non-command messages.
Source code in src\deadrat\__init__.py
run
Starts the bot's main loop using long polling.
This method blocks execution until the bot is stopped (Ctrl+C). It handles connection errors and automatic reconnections.
Source code in src\deadrat\__init__.py
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 | |
send_message
Sends a message to the chat.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text content of the message. |
None
|
image_url
|
str
|
A URL to an image to be included in the message. |
None
|
reply_to_id
|
str
|
The ID of the message to reply to. |
None
|
Returns:
| Type | Description |
|---|---|
Optional[SentMessage]
|
SentMessage | None: A SentMessage object on success, or None on failure. |
Source code in src\deadrat\__init__.py
upload_file
Uploads a file to the server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
The local path to the file. |
required |
Returns:
| Type | Description |
|---|---|
Optional[str]
|
str | None: The URL of the uploaded file on success, otherwise None. |
Source code in src\deadrat\__init__.py
Декораторы
Используйте эти методы для регистрации функций-обработчиков.
command
Decorator: Registers a function to handle a specific command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trigger
|
str
|
The command string (e.g., "/start" or "!help"). |
required |
Source code in src\deadrat\__init__.py
on_message
Decorator: Registers a handler for all non-command messages.
Source code in src\deadrat\__init__.py
event
Decorator: Registers a handler for lifecycle events.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_name
|
str
|
The event type. Options: |
required |
Source code in src\deadrat\__init__.py
Message
Represents a message received by the bot. Contains methods to reply directly to this message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict
|
The raw JSON payload for the message. |
required |
bot
|
Bot
|
The Bot instance that received this message. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
text |
str
|
The full text content of the message. |
author |
Author
|
The author of the message. |
reply_to_message |
Message | None
|
The message object this message is replying to (if any). |
command |
str | None
|
The command trigger (e.g., "/start") if present. |
args |
list[str]
|
List of arguments following the command. |
Source code in src\deadrat\__init__.py
reply
Replies directly to this message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text content for the reply. |
None
|
image_url
|
str
|
A URL to an image to include in the reply. |
None
|
Returns:
| Type | Description |
|---|---|
Optional[SentMessage]
|
SentMessage | None: A SentMessage object on success, or None on failure. |
Source code in src\deadrat\__init__.py
reply_with_file
Uploads a local file and replies with it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
The local path to the file to upload. |
required |
text
|
str
|
Optional text to accompany the file. |
None
|
Returns:
| Type | Description |
|---|---|
Optional[SentMessage]
|
SentMessage | None: A SentMessage object on success, or None on failure. |
Source code in src\deadrat\__init__.py
SentMessage
Represents a message that the bot has successfully sent. Allows editing or deleting the message later.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict
|
The raw JSON payload returned by the API after sending. |
required |
bot
|
Bot
|
The Bot instance that sent this message. |
required |
initial_text
|
str
|
The original text content of the message. |
None
|
Source code in src\deadrat\__init__.py
delete
Deletes this message from the chat.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the deletion was successful, False otherwise. |
edit
Edits this message with new text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
new_text
|
str
|
The new text content for the message. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the edit was successful, False otherwise. |
Source code in src\deadrat\__init__.py
Author
Represents the author of a message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict
|
The raw JSON payload containing author information. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
The unique ID of the user. |
username |
str
|
The display name of the user. |