Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

#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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
david-shiko wants to merge1 commit intopython-telegram-bot:masterfromdavid-shiko:prefallbacks
Closed

#2764; Implemented "prefallbacks" feature#2960

david-shiko wants to merge1 commit intopython-telegram-bot:masterfromdavid-shiko:prefallbacks

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
ContributorAuthor

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 implementconversation_data or create a PR withcontext-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 implementconversation_data

I highly recomment to first outline your idea & thoughts on implementation in either a new feature request issue or on#2770 forconversation_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 withcontext-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
ContributorAuthor

david-shiko commentedApr 19, 2022
edited
Loading

I highly recomment to first outline your idea & thoughts on implementation in either a new feature request issue or on#2770
forconversation_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 😬

@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsJul 16, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@david-shiko@Bibo-Joshi@harshil21

[8]ページ先頭

©2009-2025 Movatter.jp