### Install Pyromod with Package Managers Source: https://github.com/usernein/pyromod/blob/master/docs/docs/getting-started/installation.md Provides commands to install the pyromod library using popular Python package managers like pip, poetry, and rye. It also notes dependencies on pyrogram and compatibility with Hydrogram. ```bash pip install pyromod ``` ```bash poetry add pyromod ``` ```bash rye add pyromod ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/usernein/pyromod/blob/master/docs/README.md Installs all necessary project dependencies using Yarn. This is the first step before running any other commands. ```shell $ yarn ``` -------------------------------- ### Start Local Development Server Source: https://github.com/usernein/pyromod/blob/master/docs/README.md Starts a local development server. It opens the website in a browser and reflects most changes live without requiring a server restart. ```shell $ yarn start ``` -------------------------------- ### Full Handler Example: Get User Info with Chat.ask Source: https://github.com/usernein/pyromod/blob/master/docs/docs/getting-started/examples.md Demonstrates a complete message handler that uses the bound `chat.ask` method to collect user's name and age interactively. It filters for messages with the '/form' command and replies with the collected information. ```python from pyromod import Client, Message from pyrogram import filters @Client.on_message(filters.command('form')) async def on_form(client: Client, message: Message): chat = message.chat name = await chat.ask('What is your name?', filters=filters.text) age = await chat.ask('What is your age?', filters=filters.text) await message.reply(f'Your name is {name.text} and you are {age.text} years old.') ``` -------------------------------- ### Easier Inline Keyboard Creation - Pyromod Helpers Source: https://github.com/usernein/pyromod/blob/master/docs/docs/getting-started/examples.md Provides a simplified way to create inline keyboards using the `ikb` helper function from `pyromod.helpers`. It allows defining buttons and their associated callbacks or URLs in a structured list format. ```python from pyromod.helpers import ikb keyboard = ikb([ [('Button 1', 'callback_data_1'), ('Button 2', 'callback_data_2')], [('Another button', 't.me/pyromodchat', 'url')] ]) ``` -------------------------------- ### Ask User a Question - Pyromod Client Source: https://github.com/usernein/pyromod/blob/master/docs/docs/getting-started/examples.md Asks the user a question and awaits their text response. The client sends the specified text message and returns the user's reply. Requires a chat ID. ```python response = await client.ask(chat_id=chat_id, text='What is your name?') ``` -------------------------------- ### Ask User a Question with Timeout - Pyromod Client Source: https://github.com/usernein/pyromod/blob/master/docs/docs/getting-started/examples.md Asks the user a question and awaits their response with a specified timeout. If the user does not respond within the timeout period, a ListenerTimeout exception is raised, allowing for fallback actions. ```python try: response = await client.ask(chat_id=chat_id, text='What is your name?', timeout=10) except ListenerTimeout: await message.reply('You took too long to answer.') ``` -------------------------------- ### Listen for Message from Chat - Pyromod Client Source: https://github.com/usernein/pyromod/blob/master/docs/docs/getting-started/examples.md Listens for a single incoming message from a specified chat using the Pyromod client. Requires a valid chat ID. Returns the message object upon reception. ```python response = await client.listen(chat_id=chat_id) ``` -------------------------------- ### Install pyromod (Bash) Source: https://github.com/usernein/pyromod/blob/master/README.md Installs the pyromod library using pip, poetry, or rye. This is the first step to integrate pyromod's features into your Pyrogram projects. ```bash pip install pyromod ``` ```bash poetry add pyromod ``` ```bash rye add pyromod ``` -------------------------------- ### Full Handler: Get Name and Age (Python) Source: https://github.com/usernein/pyromod/blob/master/README.md Provides a complete example of a Pyrogram message handler that uses pyromod's 'chat.ask' method to collect user input for name and age. It showcases a conversational form-like interaction. ```python from pyromod import Client, Message from pyrogram import filters @Client.on_message(filters.command('form')) async def on_form(client: Client, message: Message): chat = message.chat name = await chat.ask('What is your name?', filters=filters.text) age = await chat.ask('What is your age?', filters=filters.text) await message.reply(f'Your name is {name.text} and you are {age.text} years old.') ``` -------------------------------- ### Listen for Message from Specific User - Pyromod Client Source: https://github.com/usernein/pyromod/blob/master/docs/docs/getting-started/examples.md Listens for a single incoming message from a specific user within a particular chat. Requires both chat ID and user ID. Returns the message object when the condition is met. ```python response = await client.listen(chat_id=chat_id, user_id=user_id) ``` -------------------------------- ### Pyromod Client Initialization Source: https://github.com/usernein/pyromod/blob/master/docs/docs/release-notes/v3-0-0.md Demonstrates the new, simplified way to initialize pyromod's Client by importing it directly, replacing the older method that required importing pyromod before pyrogram. ```python from pyromod.api import Client # Initialize pyromod Client app = Client("my_account", api_id=1234567, api_hash="your_api_hash") # Now you can use pyromod features seamlessly # For example, interacting with messages or chats ``` -------------------------------- ### Initialize pyromod Client Source: https://github.com/usernein/pyromod/blob/master/docs/docs/getting-started/initialization.md Replace the standard Pyrogram Client import with `pyromod.Client` in your client creation file. This is the primary step to enable pyromod's enhanced features. Subsequent Client instances will be patched automatically. ```Python from pyromod import Client ``` -------------------------------- ### Build Static Website Source: https://github.com/usernein/pyromod/blob/master/docs/README.md Generates the static content for the website into the 'build' directory. This output can be served by any static hosting service. ```shell $ yarn build ``` -------------------------------- ### pyromod.nav.Pagination Class and Methods Source: https://github.com/usernein/pyromod/blob/master/docs/docs/reference/modules/nav/pagination.md Documentation for the pyromod.nav.Pagination class, detailing its constructor parameters and the `create` method. The class handles object pagination and allows customization of displayed data. ```APIDOC class pyromod.nav.Pagination __init__(objects: list, page_data: function = None, item_data: function = None, item_title: function = None) Initializes the Pagination utility. Parameters: objects (list): The list of items to paginate. page_data (function, optional): A function to customize data for pagination controls. Defaults to a function returning the page number as a string. item_data (function, optional): A function to customize data for each item. Defaults to a function prefixing items with the page number. item_title (function, optional): A function to customize the title for each item. Defaults to a function prefixing titles with the page number in square brackets. async create(page: int, lines: int = 5, columns: int = 1) Creates a paginated interface for the specified page. Parameters: page (int): The page number to display. lines (int, optional): The number of lines (rows) per page. Defaults to 5. columns (int, optional): The number of columns per page. Defaults to 1. Returns: A list of paginated items and pagination controls in the form of button data. ``` -------------------------------- ### Deploy Website Source: https://github.com/usernein/pyromod/blob/master/docs/README.md Deploys the website, typically to GitHub Pages. It builds the static content and pushes it to the 'gh-pages' branch. Supports both SSH and non-SSH deployment methods. ```shell $ USE_SSH=true yarn deploy ``` ```shell $ GIT_USER= yarn deploy ``` -------------------------------- ### pyromod.listen.Client Methods Source: https://github.com/usernein/pyromod/blob/master/docs/docs/reference/modules/listen/client.md Documentation for the pyromod.listen.Client class methods, including listening for messages and sending messages to await responses. These methods extend pyrogram.Client functionality. ```APIDOC pyromod.listen.Client: __init__(...) Bases: pyrogram.Client listen(filters: Filter | None = None, listener_type: ListenerTypes = ListenerTypes.MESSAGE, timeout: int | None = None, unallowed_click_alert: bool = True, chat_id: int | None = None, user_id: int | None = None, message_id: int | None = None, inline_message_id: str | None = None) Description: Listen for a message, callback query, etc. Parameters: filters: A filter to check the incoming message against. (Type: pyrogram.filters.Filter or None) listener_type: The type of listener to listen for. (Type: pyromod.types.ListenerTypes, Default: ListenerTypes.MESSAGE) timeout: The maximum amount of time to wait for a message. (Type: int or None) unallowed_click_alert: Whether to alert the user if they click a button that doesn’t match the filters. (Type: bool, Default: True) chat_id: The chat ID to listen for. (Type: int or None) user_id: The user ID to listen for. (Type: int or None) message_id: The message ID to listen for. (Type: int or None) inline_message_id: The inline message ID to listen for. (Type: str or None) Raises: pyromod.exceptions.ListenerStopped: If the listener was stopped. pyromod.exceptions.ListenerTimeout: If the listener timed out. Returns: The message that was listened for. If the listener type is ListenerTypes.MESSAGE, then a pyrogram.types.Message object is returned. If the listener type is ListenerTypes.CALLBACK_QUERY, then a pyrogram.types.CallbackQuery object is returned. ask(chat_id: int, text: str, filters: Filter | None = None, listener_type: ListenerTypes = ListenerTypes.MESSAGE, timeout: int | None = None, unallowed_click_alert: bool = True, user_id: int | None = None, message_id: int | None = None, inline_message_id: str | None = None, *args, **kwargs) Description: Send a message and calls Client.listen to wait for a response. Parameters: chat_id: The chat ID to send the message to. (Type: int) text: The text content of the message to send. (Type: str) filters: A filter to check the incoming response message against. (Type: pyrogram.filters.Filter or None) listener_type: The type of listener to listen for the response. (Type: pyromod.types.ListenerTypes, Default: ListenerTypes.MESSAGE) timeout: The maximum amount of time to wait for a response. (Type: int or None) unallowed_click_alert: Whether to alert the user if they click a button that doesn’t match the filters. (Type: bool, Default: True) user_id: The user ID to listen for the response from. (Type: int or None) message_id: The message ID to listen for the response to. (Type: int or None) inline_message_id: The inline message ID to listen for the response. (Type: str or None) *args, **kwargs: Additional arguments to pass to the underlying send_message and listen methods. ``` -------------------------------- ### pyromod.ikb: Create InlineKeyboardMarkup Source: https://github.com/usernein/pyromod/blob/master/docs/docs/reference/modules/helpers/index.md Constructs a Telegram Bot API InlineKeyboardMarkup from a list of lists of buttons. This is used to attach custom keyboards to messages. ```python def ikb(rows: list[list[InlineKeyboardButton]] = None): """ Create an InlineKeyboardMarkup from a list of lists of buttons. Parameters: rows (list[list[InlineKeyboardButton]]): A list of lists of buttons. Returns: InlineKeyboardMarkup: An InlineKeyboardMarkup. """ pass ``` -------------------------------- ### Create Inline Keyboards with Strings Source: https://github.com/usernein/pyromod/blob/master/docs/docs/release-notes/v2-0-0.md Demonstrates how to create simple inline keyboards by passing strings directly. Each string will be used as both the button's text and its callback data. ```python from pyromod.utils import ikb keyboard = ikb([ ["Earth", "Mars", "Venus"], ["Saturn", "Jupyter"] ]) ``` -------------------------------- ### Pyromod Listen and Ask Method Updates Source: https://github.com/usernein/pyromod/blob/master/docs/docs/release-notes/v3-0-0.md Illustrates the updated `listen` and `ask` methods in pyromod, showing the removal of tuple identifiers in favor of keyword arguments and the change in argument order for `Client.ask`. ```python # Old way (using tuples - removed) # await client.listen(chat_id, timeout=60) # New way (using keyword arguments) await client.listen(chat_id=123456789, timeout=60) # Client.ask argument order change # Old: await client.ask(text, chat_id, ...) # New: await client.ask(chat_id, text, ...) # Example with inline_message_id support await client.ask(chat_id=123456789, text="Hello!", inline_message_id="123456789:123") # The 'request' attribute is now 'sent_message' response = await client.ask(chat_id=123456789, text="How are you?") # print(response.sent_message) # Previously response.request ``` -------------------------------- ### pyromod.kb: Create ReplyKeyboardMarkup Source: https://github.com/usernein/pyromod/blob/master/docs/docs/reference/modules/helpers/index.md Creates a Telegram Bot API ReplyKeyboardMarkup from a list of lists of buttons. This function also allows passing additional keyword arguments for customization. ```python def kb(rows: list[list[KeyboardButton]] = None, **kwargs): """ Create a ReplyKeyboardMarkup from a list of lists of buttons. Parameters: rows (list[list[KeyboardButton]]): A list of lists of buttons. **kwargs (dict): Keyword arguments to pass to ReplyKeyboardMarkup. Returns: ReplyKeyboardMarkup: A ReplyKeyboardMarkup. """ pass ``` -------------------------------- ### Configure Pyromod Settings with `pyromod.config` Source: https://github.com/usernein/pyromod/blob/master/docs/docs/reference/modules/config/index.md Demonstrates how to set custom configuration values for the Pyromod bot using the `config` object. This includes setting listener handlers and controlling exception behavior. ```python from pyromod.config import config # Set a custom timeout handler function config.timeout_handler = my_custom_timeout_handler # Disable raising exceptions for listener events config.throw_exceptions = False ``` -------------------------------- ### Import pyromod config object Source: https://github.com/usernein/pyromod/blob/master/docs/docs/getting-started/configuration.md Imports the `config` object from `pyromod.config` to enable customization of pyromod's behavior. This is the first step before setting any configuration options. ```python from pyromod.config import config ``` -------------------------------- ### Create Inline Keyboard (Python) Source: https://github.com/usernein/pyromod/blob/master/README.md Demonstrates the use of the 'ikb' helper function from 'pyromod.helpers' to easily construct inline keyboards. It supports creating buttons with text, callback data, and URL links. ```python from pyromod.helpers import ikb keyboard = ikb([ [('Button 1', 'callback_data_1'), ('Button 2', 'callback_data_2')], [('Another button', 't.me/pyromodchat', 'url')] ]) # This 'keyboard' object can then be passed to client.send_message or similar methods. ``` -------------------------------- ### Initialize pyromod Client (Python) Source: https://github.com/usernein/pyromod/blob/master/README.md Demonstrates how to initialize the pyromod Client by importing it from 'pyromod' instead of 'pyrogram'. This ensures that all pyromod features are monkeypatched into the Client class for subsequent use. ```python from pyromod import Client # Your Pyrogram client initialization here # client = Client("my_account", api_id=..., api_hash=...) ``` -------------------------------- ### pyromod.listen.Chat Methods Source: https://github.com/usernein/pyromod/blob/master/docs/docs/reference/modules/listen/chat.md Documentation for the bound methods of the pyromod.listen.Chat class, which extend Pyrogram's Chat object for enhanced message listening and interaction. ```APIDOC Class: pyromod.listen.Chat Description: An extension of pyrogram.types.user_and_chats.chat.Chat providing additional methods for working with chats. It is monkeypatched into the pyrogram.types.user_and_chats.chat.Chat class. Methods: - listen(*args, **kwargs) Description: Listen for a message or a callback query on the chat. This method calls the Client.listen method, passing Chat.id as chat_id. Parameters: *args: Any - The arguments to pass to the Client.listen method. **kwargs: Any - The keyword arguments to pass to the Client.listen method. Returns: The message that was listened for. - ask(text: str, *args, **kwargs) Description: Sends a message with the specified text and waits for a response from the same chat. This method calls the Client.ask method, passing Chat.id as chat_id. Parameters: text: str - The text of the message to send. *args: Any - The arguments to pass to the Client.ask method. **kwargs: Any - The keyword arguments to pass to the Client.ask method. Returns: The message that was listened for. The sent_message attribute contains the Message object of the message that was sent. - stop_listening() Description: Stop listening for messages and/or callback queries. This method calls the Client.stop_listening method, passing Chat.id as chat_id. Returns: None ``` -------------------------------- ### pyromod.listen.User Listening Methods Source: https://github.com/usernein/pyromod/blob/master/docs/docs/reference/modules/listen/user.md Provides methods for interacting with users via listening and messaging. These methods delegate to the underlying Client class, passing the User's ID for context. ```APIDOC pyromod.listen.User: # Extends pyrogram.types.user_and_chats.user.User listen(*args, **kwargs): # Listen for a message or a callback query from the user. # This method delegates to the Client.listen method, passing User.id as user_id. # Parameters: # *args: Any positional arguments to pass to Client.listen. # **kwargs: Any keyword arguments to pass to Client.listen. # Returns: The listened message or callback query. ask(text: str, *args, **kwargs): # Sends a message with the specified text to the User.id and waits for a response. # This method delegates to the Client.ask method, passing User.id as both chat_id and user_id. # Parameters: # text (str): The text of the message to send. # *args: Any positional arguments to pass to Client.ask. # **kwargs: Any keyword arguments to pass to Client.ask. # Returns: The message that was listened for. The sent_message attribute contains the Message object of the sent message. stop_listening(): # Stop listening for messages and/or callback queries. # This method delegates to the Client.stop_listening method, passing User.id as user_id. # Returns: None ``` -------------------------------- ### Pyromod Project Structure Refactoring Source: https://github.com/usernein/pyromod/blob/master/docs/docs/release-notes/v3-0-0.md Illustrates the new, more organized project structure of pyromod, with classes and functionalities moved into dedicated subpackages like `config`, `exceptions`, `listen`, and `types`. ```yaml pyromod/ ├── __init__.py ├── config │ └── __init__.py (contains the config object, formerly PyrogramConfig) ├── exceptions │ ├── __init__.py │ ├── listener_stopped.py │ └── listener_timeout.py ├── helpers │ ├── __init__.py │ └── helpers.py ├── listen │ ├── __init__.py │ ├── callback_query_handler.py │ ├── chat.py │ ├── client.py │ ├── message_handler.py │ ├── message.py │ └── user.py ├── nav │ ├── __init__.py │ └── pagination.py └── types ├── __init__.py └── listener_types.py (contains ListenerTypes enum) ``` -------------------------------- ### pyromod.kbtn: Alias for KeyboardButton Source: https://github.com/usernein/pyromod/blob/master/docs/docs/reference/modules/helpers/index.md This is an alias for the KeyboardButton class, providing a shorthand for creating standard reply keyboard buttons. ```python kbtn = KeyboardButton ``` -------------------------------- ### pyromod.bki: Deserialize InlineKeyboardMarkup Source: https://github.com/usernein/pyromod/blob/master/docs/docs/reference/modules/helpers/index.md Deserializes a Telegram Bot API InlineKeyboardMarkup object into a more manageable list of lists of buttons. This aids in programmatic manipulation of keyboard structures. ```python def bki(keyboard: InlineKeyboardMarkup): """ Deserialize an InlineKeyboardMarkup to a list of lists of buttons. Parameters: keyboard (InlineKeyboardMarkup): An InlineKeyboardMarkup. Returns: list[list[Button]]: A list of lists of buttons. """ pass ``` -------------------------------- ### Ask User Question (Python) Source: https://github.com/usernein/pyromod/blob/master/README.md Demonstrates the 'ask' method to prompt the user with a question and await their response. This is a core feature for building interactive dialogues. ```python response = await client.ask(chat_id=chat_id, text='What is your name?') # The 'response' object will contain the user's message. ``` -------------------------------- ### Docsify JavaScript Configuration Source: https://github.com/usernein/pyromod/blob/master/old-docs/index.html JavaScript configuration object for Docsify, a documentation site generator. It enables features like sidebar loading, theme color, cover page, theme transitions, and code copying. ```JavaScript window.$docsify = { loadSidebar: true, themeColor: '#dd9809', coverpage: 'cover.md', themeable: { readyTransition: true }, copyCode: { buttonText: 'Copy', errorText: 'Error', successText: 'Copied' } }; ``` -------------------------------- ### pyromod Utility Decorators Source: https://github.com/usernein/pyromod/blob/master/docs/docs/reference/index.md Provides decorators for patching and conditional patching of classes and functions within the pyromod library. These utilities help in extending or modifying behavior of existing code. ```APIDOC pyromod.utils.patch_into(target_class) - Description: Decorator to patch a method or attribute into a target class. - Parameters: - target_class: The class to which the decorated method/attribute will be added. - Usage: ```python @patch_into(SomeClass) def new_method(self, arg1): pass ``` pyromod.utils.should_patch(func) - Description: Decorator that conditionally applies patching based on a function's return value or other logic. - Parameters: - func: The function to be patched. - Usage: ```python @should_patch def some_function(): # Logic to determine if patching should occur return True # or False ``` ``` -------------------------------- ### pyromod.btn: Create InlineKeyboardButton Source: https://github.com/usernein/pyromod/blob/master/docs/docs/reference/modules/helpers/index.md Creates a Telegram Bot API InlineKeyboardButton. It allows specifying the button's text, its associated value (like callback_data or URL), and the type of interaction. ```python def btn(text: str, value: str, type: str = 'callback_data'): """ Create an InlineKeyboardButton. Parameters: text (str): The text of the button. value (str): The value of the button. type (str): The type of the button. Returns: InlineKeyboardButton: An InlineKeyboardButton. """ pass ``` -------------------------------- ### Message Sending and Listening Source: https://github.com/usernein/pyromod/blob/master/docs/docs/reference/modules/listen/client.md Details parameters for sending messages and listening for responses within a chat. It specifies input types, descriptions, and potential return values based on listener types. ```APIDOC send_message_and_listen: Parameters: chat_id (int): The chat ID to send the message to and listen for a response. text (str): The text content of the message to send. filters (pyrogram.filters.Filter or None): A filter to apply to incoming messages. listener_type (pyromod.types.ListenerTypes): Specifies the type of listener (e.g., MESSAGE, CALLBACK_QUERY). timeout (int or None): Maximum time in seconds to wait for a response. unallowed_click_alert (bool): If True, alerts user on disallowed button clicks. user_id (int or None): Specific user ID to listen for. message_id (int or None): Specific message ID to listen for. inline_message_id (str or None): Specific inline message ID to listen for. *args: Additional positional arguments. **kwargs: Additional keyword arguments. Returns: pyrogram.types.Message or pyrogram.types.CallbackQuery: The listened message or callback query. The 'request' attribute contains the sent message. ``` -------------------------------- ### Ask User Question with Timeout (Python) Source: https://github.com/usernein/pyromod/blob/master/README.md Shows how to use the 'ask' method with a timeout parameter. If the user does not respond within the specified time, a ListenerTimeout exception is raised, allowing for graceful handling of inactivity. ```python from pyromod.exceptions import ListenerTimeout try: response = await client.ask(chat_id=chat_id, text='What is your name?', timeout=10) except ListenerTimeout: await message.reply('You took too long to answer.') ``` -------------------------------- ### Listen for Single Message (Python) Source: https://github.com/usernein/pyromod/blob/master/README.md Shows how to use the 'listen' method to await a single message from a specific chat. This method is part of pyromod's enhanced client capabilities for conversational bots. ```python response = await client.listen(chat_id=chat_id) ``` -------------------------------- ### Listen for Specific User Message (Python) Source: https://github.com/usernein/pyromod/blob/master/README.md Illustrates using the 'listen' method to wait for a message from a particular user within a specified chat. This allows for more targeted conversational flows. ```python response = await client.listen(chat_id=chat_id, user_id=user_id) ``` -------------------------------- ### Listener Management Source: https://github.com/usernein/pyromod/blob/master/docs/docs/reference/modules/listen/client.md Provides API methods for managing listeners, including retrieving listeners that match specific patterns and removing existing listeners. ```APIDOC get_matching_listener: Signature: get_matching_listener(pattern: Identifier, listener_type: ListenerTypes) Description: Retrieves a single listener that matches the provided pattern and listener type. Parameters: pattern (pyromod.types.Identifier): The pattern to match listeners against. listener_type (pyromod.types.ListenerTypes): The type of listener to search for. Returns: The matching listener object, or None if no match is found. get_many_matching_listeners: Signature: get_many_matching_listeners(pattern: Identifier, listener_type: ListenerTypes) Description: Retrieves all listeners that match the provided pattern and listener type. Parameters: pattern (pyromod.types.Identifier): The pattern to match listeners against. listener_type (pyromod.types.ListenerTypes): The type of listener to search for. Returns: A list of all matching listener objects. remove_listener: Signature: remove_listener(listener: Listener) Description: Removes a specific listener from the active listeners. Parameters: listener (Listener): The listener object to remove. ```