Thanks to visit codestin.com
Credit goes to github.com

Skip to content

#2764; Implemented "prefallbacks" feature #2960

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

#2764; Implemented "prefallbacks" feature #2960

wants to merge 1 commit into from

Conversation

david-shiko
Copy link
Contributor

Imagine you have such CH:

ch = tg_ext.ConversationHandler(
    entry_points=[
        tg_ext.CommandHandler("start", callback=lambda *args, **kwargs: 0)],

    states={
        0: [
            tg_ext.MessageHandler(filters=tg_ext.Filters.text & ~Filters.regex("cancel"), 
                                  callback=lambda *args, **kwargs: 1)],

        1: [
            tg_ext.MessageHandler(filters=tg_ext.Filters.text & ~Filters.regex("cancel"), 
                                  callback=lambda *args, **kwargs: 2)],

        2: [
            tg_ext.MessageHandler(filters=tg_ext.Filters.text & ~Filters.regex("cancel"), 
                                  callback=lambda *args, **kwargs: -1)],
    },
    fallbacks=[
        tg_ext.CommandHandler("cancel", callback=lambda *args, **kwargs: -1),
    ])

Here you should apply & ~Filter for every handler in states to prevent catching a cancel command.
But it can be easily avoided by adding a list of handlers that should trigger before any other update.

@Bibo-Joshi
Copy link
Member

Hi. The situation hasn't changed much since you opened #2764: We're still working on asyncio and gathering todos for CH in #2770. Note that it's not clear when we'll have the capacity to tackle #2770.

Please either

@david-shiko
Copy link
Contributor Author

Hi. I closed my previous PR. can you please give me a review is my code and PR is okay and I can take another PR?
I want to implement conversation_data or create a PR with context-extractor

@Bibo-Joshi
Copy link
Member

Hi. I closed my previous PR.

Thanks

can you please give me a review is my code and PR is okay and I can take another PR?

Not at this point, no. As explained above, we're currently busy with getting the asyncio release ready and overhauling CH not one of the very next todo items.

I want to implement conversation_data

I highly recomment to first outline your idea & thoughts on implementation in either a new feature request issue or on #2770 for conversation_data. It's highly unlikely that we'll be adding new functionality to CH before putting a lot of thought in how to overhaul it.

or create a PR with context-extractor

TBH I don't see this getting added to the main lib. If you are interested, you cann add a contribution to ptbcontrib instead.

@david-shiko
Copy link
Contributor Author

david-shiko commented Apr 19, 2022

I highly recomment to first outline your idea & thoughts on implementation in either a new feature request issue or on #2770
for conversation_data. It's highly unlikely that we'll be adding new functionality to CH before putting a lot of thought in how to overhaul it.

Okay. I will very wait until you will release a new CH implementation because most likely my implementation will depend on new CH version :)

TBH I don't see this getting added to the main lib. If you are interested, you cann add a contribution to ptbcontrib instead.

I think we should do a poll. I see this as an extremely helpful tool. The case below is pretty easy but still makes a code cleaner. It helps to convert

This:

def target_checkboxes_handler(update: Update, context: CallbackContext):
    if context.user_data['target_user'].set_matches():  # If user has matches
        context.user_data['target_user'].set_new_matches()
        update.message.reply_text(
            text=f"Найдено {context.user_data['target_user'].all_matches_count} совпадений.",
            reply_markup=keyboards.keyboard_for_show_matches(
                len_all_matches=context.user_data['target_user'].all_matches_count,
                len_new_matches=context.user_data['target_user'].new_matches_count))
    else:
        update.message.reply_text(text='No matches', reply_markup=keyboards.remove_keyboard())
        return end_conversation(context=context)
    context.user_data['last_function'] = None  # To prevent "go back" at this state
    return 5

To this:

def target_checkboxes_handler(update: Update, context: CallbackContext, target_user: TargetUser):
    if target_user.set_matches():  # If user has matches
        target_user.set_new_matches()
        update.message.reply_text(text=f"Найдено {target_user.all_matches_count} совпадений.",
                                  reply_markup=keyboards.keyboard_for_show_matches(
                                      len_all_matches=target_user.all_matches_count,
                                      len_new_matches=target_user.new_matches_count))
    else:
        update.message.reply_text(text='No matches', reply_markup=keyboards.remove_keyboard())
        return end_conversation(context=context)
    context.user_data['last_function'] = None  # To prevent "go back" at this state
    return 5

@harshil21
Copy link
Member

can we close due to inactivity / adding it to the TODO for ConvHandler at a later stage?

@Bibo-Joshi
Copy link
Member

Yes, I'll go ahead and close. both #2764 this PR are mentioned in #2770 so that we can get back to this once we actually tackle CH. I fear that a refactor of CH will be a diff big enough to make this PR unmergable anyways 😬

@Bibo-Joshi Bibo-Joshi closed this Jul 9, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants