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 hashes)

Uploaded Source

Built Distribution

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

Uploaded Python 3

Supported by

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