usernein / pyromod

A monkeypatcher add-on for Pyrogram
https://pyromod.pauxis.dev/
GNU Lesser General Public License v3.0
223 stars 70 forks source link

`Message.wait_for_click` and `Client.listen` will never return the expected `CallbackQuery` #31

Open WhaleFell opened 12 months ago

WhaleFell commented 12 months ago

message.wait_for_click() Even though clicking the button triggers the callback, it never makes him return. Unless a timeout triggers an error.

The same occurs in message.chat.listen when listener_type=ListenerTypes.CALLBACK_QUERY expects to receive a callback from the user pressing a button.

I had a feeling this was an issue and wondered if it could be reproduced on your end.

thanks for the reply. 😃

image

usernein commented 10 months ago

Hello there! This issue in specific puzzled me!

At first was unable to reproduce the error with either pyromod v2 or v3. Message.wait_for_click always worked for me:



I had the feeling the the problem was client.listen being unable to process the callback query. Then i realized it depends on CallbackQueryHandler to be executed and it won't execute if you don't have any callback_query handler on your code.

It means that if you don't have any @Client.on_callback_query on your code, pyromod won't be able to intercept the CallbackQuery updates and consequently won't deliver them to Message.wait_for_click.

And i actually tested it: i tried removing all my callback_query handlers from the code and Bingo!: wait_for_click stopped working.

Solution

It will work again if you add at least one callback_query handler on your code. It does not even need to handle the CallbackQuery, it should just exist. For instance, you can add the following code into your plugins and it will make wait_for_click work as normal:

@Client.on_callback_query(filters.regex('wont ever match'))
async def on_callback():
    pass

I don't see this as a bug by the way, it's more like a pyromod inconvenient requirement which may be improved at the future. But this totally must be documented. Thanks for reporting that!

jusidama18 commented 10 months ago

@usernein i'm not using any Client.on_callback_query and it still works fine

covein commented 8 months ago

Hello there! This issue in specific puzzled me!

At first was unable to reproduce the error with either pyromod v2 or v3. Message.wait_for_click always worked for me:

I had the feeling the the problem was client.listen being unable to process the callback query. Then i realized it depends on CallbackQueryHandler to be executed and it won't execute if you don't have any callback_query handler on your code.

It means that if you don't have any @Client.on_callback_query on your code, pyromod won't be able to intercept the CallbackQuery updates and consequently won't deliver them to Message.wait_for_click.

And i actually tested it: i tried removing all my callback_query handlers from the code and Bingo!: wait_for_click stopped working.

Solution

It will work again if you add at least one callback_query handler on your code. It does not even need to handle the CallbackQuery, it should just exist. For instance, you can add the following code into your plugins and it will make wait_for_click work as normal:

@Client.on_callback_query(filters.regex('wont ever match'))
async def on_callback():
    pass

I don't see this as a bug by the way, it's more like a pyromod inconvenient requirement which may be improved at the future. But this totally must be documented. Thanks for reporting that!

Thanks! This solves my problem too!

BTW, does the new project Hydrogram still has the wait_for_click function? I want to transfer the hydrogram ~