Context

class anjani.command.Context

Represent a context of a command invoked on.

Attributes:

  • args (Optional[List[str]]) - The list of transformed arguments that were passed into the command.
  • author (~pyrogram.types.User) - Author associated with the context’s command. Shortcut of message.from_user.
  • bot (~anjani.core.Anjani) - Anjani instance.
  • chat (~pyrogram.types.Chat) - Chat associated with the context’s command. Shortcut of message.chat.
  • cmd_len (int) - The lenght of the command text.
  • invoker (str) - The string that makes the context invoked.
  • input (str) - A text that contain an input string without the command.
  • input_raw (str) - Raw input parsed in Markdown.
  • message (~pyrogram.types.Message) - The message that triggered the command. Alias msg.
  • response (Optional[~pyrogram.types.Message]) - A response message by the bot.
  • segments (List[str]) - The list of splited text that were passed into the command.

Methods:

await respond(text=None, *, animation=None, audio=None, document=None, photo=None, video=None, delete_after=None, mode="edit", readact=True, reference=None, **kwargs)

Respond to the invoker of the context. This method handle edit and reply. If the bot hasn't send any message it force to use reply method else it will try to edit the last response.

Parameters:

  • text (str) - Text of the message to be sent.
  • annimation (Optional[Union[str, BinaryIO]]) - Annimation to send. Pass a file_id as string to send an animation(GIF) file that exists on the Telegram servers, pass an HTTP URL as a string for Telegram to get an animation file from the Internet, pass a file path as string to upload a new animation file that exists on your local machine, or pass a binary file-like object with its attribute “.name” set for in-memory uploads.
  • audio (Optional[Union[str, BinaryIO]]) - Audio file to send. Pass a file_id as string to send an audio file that exists on the Telegram servers, pass an HTTP URL as a string for Telegram to get an audio file from the Internet, pass a file path as string to upload a new audio file that exists on your local machine, or pass a binary file-like object with its attribute “.name” set for in-memory uploads.
  • document (Optional[Union[str, BinaryIO]]) - File to send. Pass a file_id as string to send a file that exists on the Telegram servers, pass an HTTP URL as a string for Telegram to get a file from the Internet, pass a file path as string to upload a new file that exists on your local machine, or pass a binary file-like object with its attribute “.name” set for in-memory uploads.
  • photo (Optional[Union[str, BinaryIO]]) - Photo to send. Pass a file_id as string to send a photo that exists on the Telegram servers, pass an HTTP URL as a string for Telegram to get a photo from the Internet, pass a file path as string to upload a new photo that exists on your local machine, or pass a binary file-like object with its attribute “.name” set for in-memory uploads.
  • photo (Optional[Union[str, BinaryIO]]) - Video to send. Pass a file_id as string to send a video that exists on the Telegram servers, pass an HTTP URL as a string for Telegram to get a video from the Internet, pass a file path as string to upload a new video that exists on your local machine, or pass a binary file-like object with its attribute “.name” set for in-memory uploads.
  • delete_after (Optional[Union[int, float]]) - If provided, the number of seconds to wait in the background before deleting the message we just sent. If the deletion fails, then it is silently ignored.
  • mode (str) - The mode that the client will respond. "edit" and "reply". Defaults to "edit".
  • redact (bool) - Tells wether the text will be redacted from sensitive environment key. Defaults to True.
  • reference (Optional[~pyrogram.types.Message]) - Tells client which message to respond (message to edit or to reply based on mode).

await trigger_action(action="typing")

Tell the other party that something is happening on your side.

Parameters:

  • action (str) - Type of action to broadcast. Choose one, depending on what the user is about to receive: “typing” for text messages, “upload_photo” for photos, “record_video” or “upload_video” for videos, “record_audio” or “upload_audio” for audio files, “upload_document” for general files, “find_location” for location data, “record_video_note” or “upload_video_note” for video notes, “choose_contact” for contacts, “playing” for games, “speaking” for speaking in group calls or “cancel” to cancel any chat action currently displayed.

async with action(action="typing")

Returns a context manager that allows you to send a chat action for an indefinite period of time.

Parameters:

  • action (str) - Type of action to broadcast. Choose one, depending on what the user is about to receive: “typing” for text messages, “upload_photo” for photos, “record_video” or “upload_video” for videos, “record_audio” or “upload_audio” for audio files, “upload_document” for general files, “find_location” for location data, “record_video_note” or “upload_video_note” for video notes, “choose_contact” for contacts, “playing” for games, “speaking” for speaking in group calls or “cancel” to cancel any chat action currently displayed.

This is both a regular context manager and an async context manager. This means that both with and async with work with this.

example usage

async with ctx.action():
    # Do expensive stuff here
    await ctx.respond("Done!")

await get_text("plugin-translation-text", *args, noformat=False, **kwargs)

Bound method of ~Plugin.get_text that chat_id already set. Parse the string with the user language setting. Return English string in case other language doesn't have the string requested.

Parameters:

  • name (str) - String name(key) to parse.
  • *args (any, Optional) - One or more values that should be formatted and inserted in the string. The value should be in order based on the language string placeholder.
  • noformat (bool, Optional) - If exist and True, the text returned will not be formatted (if you don't want to insert any value to the placeholders). Default to False.
  • **kwargs (any, Optional) - One or more keyword values that should be formatted and inserted in the string. Based on the keyword placeholder on the language strings.

example usage

await ctx.get_text("plugin-translation-text")