Skip to main content

A step handler library for pyrogram framework

Project description

Pyrostep

Downloads Python Pyrogram

Pyrostep helps you to use pyrogram:

  • step handling
  • new filters may you need
  • change connection timeout, retries, e.g.
  • and other helper methods

I tried to provide the best speed ...

  1. Install
  2. Usage
    1. Step handling
    2. New filters
    3. Connection
    4. Other
  3. TODO

Install

pip3 install -U pyrostep

Usage

before learn, You should know that this library only works as async.

Step handling

import pyrostep.steps first:

from pyrostep import steps

Now see simple example:

@app.on_message(filters.command("start"))
async def step1(c, msg):
    await app.send_message(msg.chat.id, "what is your name?")
    steps.register_next_step(msg.from_user.id, step2)

async def step2(c, msg):
    await app.send_message(msg.chat.id, "your name is: %s" % msg.text)
    steps.unregister_steps(msg.from_user.id)

steps.listen(app)

First we create a function named step1, we want user name. ask user to send name with send_message and set next step for user with register_next_step. after all, we use unregister_steps to remove steps for user.

end of code, you can see steps.listen function. this function listen updates which sends to your client.

you must use listen after all decorators.

Now see ask method, this is make code easy for you. see example:

@app.on_message(filters.command("start"))
async def step1(c, msg):
    await steps.ask(
        c, step2, msg.chat.id, "what is your name?",
        user_id=msg.from_user.id
    )

async def step2(c, msg):
    await app.send_message(msg.chat.id, "your name is: %s" % msg.text)
    steps.unregister_steps(msg.from_user.id)

steps.listen(app)

If you don't like this step handling, can use ask_wait function. see example:

@app.on_message(filters.command("start"))
async def step1(c, msg):
    result = await steps.ask_wait(
        c, step2, msg.chat.id, "what is your name?",
        user_id=msg.from_user.id
    )
    await app.send_message(msg.chat.id, "your name is: %s" % result.text)

steps.listen(app)

Let's not forget the listen_on_the_side function. Use this instead listen method if you have a decorator without any filter.

Example:

@app.on_message() # or @app.on_message(filters.all)
@steps.listen_on_the_side
async def step1(c, msg):
    result = await steps.ask_wait(
        c, step2, msg.chat.id, "what is your name?",
        user_id=msg.from_user.id
    )
    await app.send_message(msg.chat.id, "your name is: %s" % result.text)

New filters

from pyrostep import filters
  • ttl_message: Filter ttl messages ( ttl photo message or ttl video message ).

  • video_sticker: Filter video sticker messages.

  • entities: Filter messages include entities.

  • photo_size: Filter photo messages with width and height.

  • member_of_chats: Filter users who are members of chats.

Connection

Function connection_max_retries:

Change connection max retries. (default 3)

retries message: Unable to connect due to network issues: ...

Return: returns MAX_RETRIES if max_retries is None

Function invoke_max_retries:

Change invoke max retries. (default 5)

retries message: [...] Waiting for ... seconds before continuing (required by "...")

Return: returns MAX_RETRIES if max_retries is None

Function session_start_timeout:

Change start timeout. (default 1)

Return: returns START_TIMEOUT if timeout is None.

Function session_max_retries:

Change session max retries.

retries message: Connection failed! Trying again...

What is mode? TCP Connection mode.

  • TCP Modes:
    • TCPFull
    • TCPAbridged
    • TCPIntermediate
    • TCPAbridgedO
    • TCPIntermediateO

Other

import shortcuts:

from pyrostep import shortcuts

Now see methods:

split_list splites lst list:

>>> shortcuts.split_list([1, 2, 3, 4, 5, 6], 2)
# [[1, 2], [3, 4], [5, 6]]
>>> shortcuts.split_list([1, 2, 3], 2)
# [[1, 2], [3]]

keyboard creates ReplyKeyboardMarkup from your list:

buttons = [
    [
        ["Top Left"], ["Top Right"]
    ],
    [
        ["Bottom | Request Contact", True, "request_contact"]
    ]
]
kb = shortcuts.keyboard(buttons)

inlinekeyboard creates InlineKeyboardMarkup from your list:

buttons = [
    [
        ["Top Left", "data_1"], ["Top Right", "data_2"]
    ],
    [
        ["Bottom", "Your URL", "url"]
    ]
]
ikb = inlinekeyboard(buttons)

validation_channels checks user already in channels or not:

user_id = 56392019
channels = [-102792837, -10823823, 'channel_username']

is_joined = await validation_channels(
    app, user_id, channels
)
# ...
async def invite(app, id, channels) -> None:
    print(
        f"User {id} is not member of channels ({channels})"
    )

is_joined = await validation_channels(
    app, user_id, channels,
    invite_func=invite
)

TODO

  • Add examples
  • Do other tests

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyrostep-2.0.0.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyrostep-2.0.0-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file pyrostep-2.0.0.tar.gz.

File metadata

  • Download URL: pyrostep-2.0.0.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.2

File hashes

Hashes for pyrostep-2.0.0.tar.gz
Algorithm Hash digest
SHA256 561cfbab0d90a47ab337a2533728da524e693443deb4754e15821fcfdba0dc3e
MD5 ff6ab9b155368aa9e6a204771669e64f
BLAKE2b-256 fa3a7b66c0de2e2b1b94d5972f2e31bc9ab93a7270ec7a8902a5040fdeaa5396

See more details on using hashes here.

File details

Details for the file pyrostep-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: pyrostep-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 17.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.2

File hashes

Hashes for pyrostep-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cdfef4c889e1fbd59e548e9fd880f106c3fe0f2f14a063b074d501e77a3f5a59
MD5 7ab92b6e1d1092771ea474e9a9d02c30
BLAKE2b-256 c61720640307073599a74ee87bc29cef050fd17a372725e8ae106c4a064b39ac

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page