Skip to main content

A step handler library for pyrogram framework

Project description

Pyrostep

Downloads Python Pyrogram

A step handler library for pyrogram framework.
Helps you to step handling ...

I tried to provide the best speed ...

  1. Installing
  2. Usage
  3. Examples
  4. TODO
  5. Copyright & License

Installing

Can use pip:

pip3 install -U pyrostep

Or, Can use git (not recommended):

git clone https://github.com/aWolver/pyrostep && cd pyrostep && python3 setup.py install

Usage

Usage is very easy ... Follow me

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

First import pyrostep:

import pyrostep

pyrostep has a decorator named first_step, use this for handler which is first step, example:

app = Client(...)
# ...

@app.on_message()
@pyrostep.first_step()
async def step1(cli: Client, msg: Message):
    await msg.reply_text("please send your name:")
    await pyrostep.register_next_step(msg.from_user.id, step2)

# create handler to get name:
async def step2(cli: Client, msg: Message):
    await msg.reply_text("Hello %s!" % msg.text)

    # unregister step2 in end step (don't forget it)
    await pyrostep.unregister_steps(msg.from_user.id)

# ...

you can use ask method instead of register_next_step:

...
async def step1(cli: Client, msg: Message):
    pyrostep.ask(msg, step2, "please send your name:")
...

End of this code, you see unregister_steps method, you can use end_step decorator instead of it:

...
@end_step()
async def step2(cli: Client, msg: Message):
    await msg.reply_text("Hello %s!" % msg.text)
...

set_step_listener method

first_step decorator may broken your code, so i recommended use set_step_listener instead of first_step.

Example:

app = Client(...)
# ...

@app.on_message(filters=filters.command("sayhello"))
async def step1(cli: Client, msg: Message):
    await msg.reply_text("please send your name:")
    await pyrostep.register_next_step(msg.from_user.id, step2)

# create handler to get name:
async def step2(cli: Client, msg: Message):
    await msg.reply_text("Hello %s!" % msg.text)

    # unregister step2 in end step (don't forget it)
    await pyrostep.unregister_steps(msg.from_user.id)

# after all decorators
pyrostep.set_step_listener(app)

# ...

Note: Better you use set_step_listener after all of decorators.

Use set_step_listener or first_step?

to answer this, you should know how does set_step_listener and first_step works.

first_step decorator sets middleware on your handler/decorator. checks if this user in listening users or not, if true, call step functions, and if false, call default handler.

set_step_listener too. it sets a step listener handler without default decorator.

Why use set_step_listener after all decorators?

to check the pyrogram as the last method.

If you want clear all steps for all users, use clear method.

StepHandler class

You can use it to have a different steps handler:

from pyrostep import StepHandler

h = StepHandler()

It has all of methods you want.

Keyboards

import keyboards:

from pyrostep import keyboards

Now see methods:

split_list splites lst list:

>>> keyboards.split_list([1, 2, 3, 4, 5, 6], 2)
# [[1, 2], [3, 4], [5, 6]]
>>> keyboards.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 = keyboards.keyboard(buttons)

inlinekeyboard creates InlineKeyboardMarkup from your list:

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

Filters

import filters:

from pyrostep import filters

Now see 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.

Examples

See Examples here

TODO

  • Add examples
  • Add helper methods
  • Do Other Tests

License

Licensed under the terms of the GNU Lesser General Public License v2

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-1.4.7.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

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

pyrostep-1.4.7-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pyrostep-1.4.7.tar.gz
Algorithm Hash digest
SHA256 1c126eb4d1dbe580d68a242eca1c1bc952121d8852f0d1cdb896a9eeb4765f9b
MD5 db6f2727b6544acb2299ff4f64c85bf6
BLAKE2b-256 73260affd421a5a3415148af2320a7c95e49cd8e84387461faac2c21b8f5ad93

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyrostep-1.4.7-py3-none-any.whl
  • Upload date:
  • Size: 14.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-1.4.7-py3-none-any.whl
Algorithm Hash digest
SHA256 8bcd7145b5d8d95f6ff26d603cd870e2a42ce796efd2510bd78c2dab4410b700
MD5 0958cb87dbfac8a3a7f161a97843ce56
BLAKE2b-256 f989b5fcc7c6dc537cf77e4e9baca6251e30815f9cf627438824d0d03782b7d4

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