pyrostep


Namepyrostep JSON
Version 2.11.22 PyPI version JSON
download
home_pagehttps://github.com/awolverp/pyrostep
SummaryA Python library to handle steps in pyrogram framework.
upload_time2024-03-23 09:13:33
maintainerNone
docs_urlNone
authoraWolver
requires_pythonNone
licenseMIT
keywords pyrostep pyrogram step handler pyrogram helper helper pyrogram plugin plugin pyrogram connection
VCS
bugtrack_url
requirements cachebox
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pyrostep
[![Downloads](https://static.pepy.tech/personalized-badge/pyrostep?period=total&units=abbreviation&left_color=red&right_color=grey&left_text=Downloads)](https://pepy.tech/project/pyrostep)

You can implement conversation in your project based on pyrogram very easy with **pyrostep**.

**Features**:
- Full type hint
- Support step handling
- Support asking
- Change core settings of pyrogram

**Installing**
```bash
pip3 install -U pyrostep
```

**Content**
- [tutorial](#tutorial)
    - [step handling](#step-handling)
    - [wait for method](#wait-for-method)
    - [plugins](#plugins)
- [shortcuts](#shortcuts)
- [connection package](#connection-package)

## Tutorial
Use `pyrostep.listen()` to start listening on your client:
```python
from pyrogram import Client
import pyrostep

# ...

client = Client("myaccount")
pyrostep.listen(client)
```

> [!NOTE]\
> Always use `pyrostep.listen()` before adding your handlers.

After that, we have two ways to make conversation: [wait_for method](#wait-for-method) or [step handling](#step-handling)

-----

### Wait for method
⏰ In this way we can use `pyrostep.wait_for` function, that waits for an update (e.g message) from your target.

```python
client = Client("myaccount")
pyrostep.listen(client)

# ...

@client.on_message()
async def get_name(_, message):
    await message.reply("Send your name?")
    
    answer = await pyrostep.wait_for(message.from_user.id)
    await message.reply(f"Your name is {answer.text}")
```

> [!TIP]\
> You can specify how long it will wait with `timeout` parameter. see this example:

```python
client = Client("myaccount")
pyrostep.listen(client)

# ...

@client.on_message()
async def get_name(_, message):
    await message.reply("Send your name?")

    try:
        answer = await pyrostep.wait_for(message.from_user.id, timeout=10)
    except TimeoutError:
        await message.reply("Timed out")
    else:
        await message.reply(f"Your name is {answer.text}")
```

🔗 **Related functions:**
- `clear()`: remove all registered steps (and cancels all wait_for's).

------

### Step handling
🎯 In this way we will use this functions:
- `pyrostep.register_next_step()`

We will specify a function that should process the next update from the target with `pyrostep.register_next_step()`.

> [!IMPORTANT]\
> In this way we cannot specify a timeout.

```python
client = Client("myaccount")
pyrostep.listen(client)

# ...

@client.on_message()
async def get_name(_, message):
    await message.reply("Send your name?")
    await pyrostep.register_next_step(
        message.from_user.id, get_age
    )

async def get_age(_, message):
    await message.reply("OK, Send your age?")
    await pyrostep.register_next_step(
        message.from_user.id,
        say_info,
        kwargs={"name": message.text}
    )

async def say_info(_, message, name: str = None):
    await message.reply(f"Name: {name} - Age: {message.text}")
```

🔗 **Related functions:**
- `unregister_steps(id)`: remove registered step for *id*.
- `clear()`: remove all registered steps (and cancels all wait_for's).

-------

### Plugins
📁 If you're using plugins in pyrogram, maybe you cannot use `pyrostep.listen()`, so you can use `pyrostep.listening_handler` function.

How? there's an example:
```python
# plugin file
from pyrogram import Client
import pyrostep

Client.on_message()
async def stephandler(client, message):
    await pyrostep.listening_handler(client, message)

# your other handlers
```

> [!WARNING]\
> We didn't test it completely.

## Shortcuts
✂️ **pyrostep** have some shortcuts and shorthands for you.

#### pyrostep.shortcuts.split_list()
split_list splites your list.

example:
```python
>>> from pyrostep import shortcuts
>>> split_list([1, 2, 3, 4, 5, 6], 2)
[[1, 2], [3, 4], [5, 6]]
>>> split_list([1, 2, 3], 2)
[[1, 2], [3]]
```


#### pyrostep.shortcuts.keyboard()
keyboard creates ReplyKeyboardMarkup from your list.

example:
```python
>>> from pyrostep import shortcuts
>>> buttons = [
...     [["Top Left"], ["Top Right"]],
...     [["Bottom | Request Contact", True, "request_contact"]]
... ]
>>> shortcuts.keyboard(buttons)
ReplyKeyboardMarkup(keyboard=[[KeyboardButton(text='Top Left'), KeyboardButton(text='Top Right')], [KeyboardButton(text='Bottom | Request Contact', request_contact=True)]])
```

#### pyrostep.shortcuts.inlinekeyboard()
inlinekeyboard creates InlineKeyboardMarkup from your list.

example:
```python
>>> from pyrostep import shortcuts
>>> buttons = [
...     [["Top Left", "data_1"], ["Top Right", "data_2"]],
...     [["Bottom", "Your URL", "url"]]
... ]
>>> shortcuts.inlinekeyboard(buttons)
InlineKeyboardMarkup(inline_keyboard=[[InlineKeyboardButton(text='Top Left', callback_data='data_1'), InlineKeyboardButton(text='Top Right', callback_data='data_2')], [InlineKeyboardButton(text='Bottom', url='Your URL')]])
```

#### pyrostep.shortcuts.validation_channels()
validation_channels checks user is already in channels or not.
returns `True` if user is already in channels, returns `False` otherwise.

example:
```python
>>> from pyrostep import shortcuts
>>> user_id = 56392019
>>> channels = [-10279279837, -10823827873, 'channel_username']
>>> await validation_channels(app, user_id, channels)
True
```

## connection package
This package helps you to change *pyrogram connection* settings.

> [!NOTE]\
> All of these functions should be used before importing pyrogram

#### pyrostep.connection.connection_max_retries()
How many times does it try to connect (to proxy or telegram)?

-----

#### pyrostep.connection.invoke_max_retries()
How many times does it try to invoke a method?

-----

#### pyrostep.connection.session_start_timeout()
How many seconds to wait for connection?

-----

#### pyrostep.connection.session_max_retries()
How many times does it try to authenticate?

-----

Example:
```python
from pyrostep import connection
connection.connection_max_retries(3)
connection.invoke_max_retries(3)
connection.session_start_timeout(20)
connection.session_max_retries(2)

from pyrogram import Client
# code ...
```



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/awolverp/pyrostep",
    "name": "pyrostep",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "pyrostep, pyrogram, step handler, pyrogram helper, helper, pyrogram plugin, plugin, pyrogram connection",
    "author": "aWolver",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/db/04/8d9f98e7629d8b69d66912a21f1c704cc90f99248b4361aceb6effe37262/pyrostep-2.11.22.tar.gz",
    "platform": null,
    "description": "# pyrostep\n[![Downloads](https://static.pepy.tech/personalized-badge/pyrostep?period=total&units=abbreviation&left_color=red&right_color=grey&left_text=Downloads)](https://pepy.tech/project/pyrostep)\n\nYou can implement conversation in your project based on pyrogram very easy with **pyrostep**.\n\n**Features**:\n- Full type hint\n- Support step handling\n- Support asking\n- Change core settings of pyrogram\n\n**Installing**\n```bash\npip3 install -U pyrostep\n```\n\n**Content**\n- [tutorial](#tutorial)\n    - [step handling](#step-handling)\n    - [wait for method](#wait-for-method)\n    - [plugins](#plugins)\n- [shortcuts](#shortcuts)\n- [connection package](#connection-package)\n\n## Tutorial\nUse `pyrostep.listen()` to start listening on your client:\n```python\nfrom pyrogram import Client\nimport pyrostep\n\n# ...\n\nclient = Client(\"myaccount\")\npyrostep.listen(client)\n```\n\n> [!NOTE]\\\n> Always use `pyrostep.listen()` before adding your handlers.\n\nAfter that, we have two ways to make conversation: [wait_for method](#wait-for-method) or [step handling](#step-handling)\n\n-----\n\n### Wait for method\n\u23f0 In this way we can use `pyrostep.wait_for` function, that waits for an update (e.g message) from your target.\n\n```python\nclient = Client(\"myaccount\")\npyrostep.listen(client)\n\n# ...\n\n@client.on_message()\nasync def get_name(_, message):\n    await message.reply(\"Send your name?\")\n    \n    answer = await pyrostep.wait_for(message.from_user.id)\n    await message.reply(f\"Your name is {answer.text}\")\n```\n\n> [!TIP]\\\n> You can specify how long it will wait with `timeout` parameter. see this example:\n\n```python\nclient = Client(\"myaccount\")\npyrostep.listen(client)\n\n# ...\n\n@client.on_message()\nasync def get_name(_, message):\n    await message.reply(\"Send your name?\")\n\n    try:\n        answer = await pyrostep.wait_for(message.from_user.id, timeout=10)\n    except TimeoutError:\n        await message.reply(\"Timed out\")\n    else:\n        await message.reply(f\"Your name is {answer.text}\")\n```\n\n\ud83d\udd17 **Related functions:**\n- `clear()`: remove all registered steps (and cancels all wait_for's).\n\n------\n\n### Step handling\n\ud83c\udfaf In this way we will use this functions:\n- `pyrostep.register_next_step()`\n\nWe will specify a function that should process the next update from the target with `pyrostep.register_next_step()`.\n\n> [!IMPORTANT]\\\n> In this way we cannot specify a timeout.\n\n```python\nclient = Client(\"myaccount\")\npyrostep.listen(client)\n\n# ...\n\n@client.on_message()\nasync def get_name(_, message):\n    await message.reply(\"Send your name?\")\n    await pyrostep.register_next_step(\n        message.from_user.id, get_age\n    )\n\nasync def get_age(_, message):\n    await message.reply(\"OK, Send your age?\")\n    await pyrostep.register_next_step(\n        message.from_user.id,\n        say_info,\n        kwargs={\"name\": message.text}\n    )\n\nasync def say_info(_, message, name: str = None):\n    await message.reply(f\"Name: {name} - Age: {message.text}\")\n```\n\n\ud83d\udd17 **Related functions:**\n- `unregister_steps(id)`: remove registered step for *id*.\n- `clear()`: remove all registered steps (and cancels all wait_for's).\n\n-------\n\n### Plugins\n\ud83d\udcc1 If you're using plugins in pyrogram, maybe you cannot use `pyrostep.listen()`, so you can use `pyrostep.listening_handler` function.\n\nHow? there's an example:\n```python\n# plugin file\nfrom pyrogram import Client\nimport pyrostep\n\nClient.on_message()\nasync def stephandler(client, message):\n    await pyrostep.listening_handler(client, message)\n\n# your other handlers\n```\n\n> [!WARNING]\\\n> We didn't test it completely.\n\n## Shortcuts\n\u2702\ufe0f **pyrostep** have some shortcuts and shorthands for you.\n\n#### pyrostep.shortcuts.split_list()\nsplit_list splites your list.\n\nexample:\n```python\n>>> from pyrostep import shortcuts\n>>> split_list([1, 2, 3, 4, 5, 6], 2)\n[[1, 2], [3, 4], [5, 6]]\n>>> split_list([1, 2, 3], 2)\n[[1, 2], [3]]\n```\n\n\n#### pyrostep.shortcuts.keyboard()\nkeyboard creates ReplyKeyboardMarkup from your list.\n\nexample:\n```python\n>>> from pyrostep import shortcuts\n>>> buttons = [\n...     [[\"Top Left\"], [\"Top Right\"]],\n...     [[\"Bottom | Request Contact\", True, \"request_contact\"]]\n... ]\n>>> shortcuts.keyboard(buttons)\nReplyKeyboardMarkup(keyboard=[[KeyboardButton(text='Top Left'), KeyboardButton(text='Top Right')], [KeyboardButton(text='Bottom | Request Contact', request_contact=True)]])\n```\n\n#### pyrostep.shortcuts.inlinekeyboard()\ninlinekeyboard creates InlineKeyboardMarkup from your list.\n\nexample:\n```python\n>>> from pyrostep import shortcuts\n>>> buttons = [\n...     [[\"Top Left\", \"data_1\"], [\"Top Right\", \"data_2\"]],\n...     [[\"Bottom\", \"Your URL\", \"url\"]]\n... ]\n>>> shortcuts.inlinekeyboard(buttons)\nInlineKeyboardMarkup(inline_keyboard=[[InlineKeyboardButton(text='Top Left', callback_data='data_1'), InlineKeyboardButton(text='Top Right', callback_data='data_2')], [InlineKeyboardButton(text='Bottom', url='Your URL')]])\n```\n\n#### pyrostep.shortcuts.validation_channels()\nvalidation_channels checks user is already in channels or not.\nreturns `True` if user is already in channels, returns `False` otherwise.\n\nexample:\n```python\n>>> from pyrostep import shortcuts\n>>> user_id = 56392019\n>>> channels = [-10279279837, -10823827873, 'channel_username']\n>>> await validation_channels(app, user_id, channels)\nTrue\n```\n\n## connection package\nThis package helps you to change *pyrogram connection* settings.\n\n> [!NOTE]\\\n> All of these functions should be used before importing pyrogram\n\n#### pyrostep.connection.connection_max_retries()\nHow many times does it try to connect (to proxy or telegram)?\n\n-----\n\n#### pyrostep.connection.invoke_max_retries()\nHow many times does it try to invoke a method?\n\n-----\n\n#### pyrostep.connection.session_start_timeout()\nHow many seconds to wait for connection?\n\n-----\n\n#### pyrostep.connection.session_max_retries()\nHow many times does it try to authenticate?\n\n-----\n\nExample:\n```python\nfrom pyrostep import connection\nconnection.connection_max_retries(3)\nconnection.invoke_max_retries(3)\nconnection.session_start_timeout(20)\nconnection.session_max_retries(2)\n\nfrom pyrogram import Client\n# code ...\n```\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Python library to handle steps in pyrogram framework.",
    "version": "2.11.22",
    "project_urls": {
        "Homepage": "https://github.com/awolverp/pyrostep"
    },
    "split_keywords": [
        "pyrostep",
        " pyrogram",
        " step handler",
        " pyrogram helper",
        " helper",
        " pyrogram plugin",
        " plugin",
        " pyrogram connection"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c562da33a687e52390cc959aaf48047b832c55e5c0c75125e7d996539b93cb89",
                "md5": "d253e90ad31c9d7a002ba19d6ff9a965",
                "sha256": "728ce31dc1613bc1c4eb17aab2a0ebe758eb7a50591fc903586ca61b635e297e"
            },
            "downloads": -1,
            "filename": "pyrostep-2.11.22-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d253e90ad31c9d7a002ba19d6ff9a965",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 9763,
            "upload_time": "2024-03-23T09:13:16",
            "upload_time_iso_8601": "2024-03-23T09:13:16.512293Z",
            "url": "https://files.pythonhosted.org/packages/c5/62/da33a687e52390cc959aaf48047b832c55e5c0c75125e7d996539b93cb89/pyrostep-2.11.22-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "db048d9f98e7629d8b69d66912a21f1c704cc90f99248b4361aceb6effe37262",
                "md5": "257e7c0be88d3279e6721517a32066a1",
                "sha256": "351548c9494305587558c3daa2d34af30acb05163b78852371437ce5bb268381"
            },
            "downloads": -1,
            "filename": "pyrostep-2.11.22.tar.gz",
            "has_sig": false,
            "md5_digest": "257e7c0be88d3279e6721517a32066a1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 9992,
            "upload_time": "2024-03-23T09:13:33",
            "upload_time_iso_8601": "2024-03-23T09:13:33.118069Z",
            "url": "https://files.pythonhosted.org/packages/db/04/8d9f98e7629d8b69d66912a21f1c704cc90f99248b4361aceb6effe37262/pyrostep-2.11.22.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-23 09:13:33",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "awolverp",
    "github_project": "pyrostep",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "cachebox",
            "specs": []
        }
    ],
    "lcname": "pyrostep"
}
        
Elapsed time: 3.74536s