Skip to content
This repository has been archived by the owner on Jun 2, 2019. It is now read-only.

include_callback_query_chat_id doesn't seem to care about what seeder evaluates #433

Open
jaroojim opened this issue Nov 26, 2018 · 3 comments

Comments

@jaroojim
Copy link

i have this two classes. What i would like to know is why do both Handlers get activated to handle a callback query even though the seeder function of the second delegation pattern returns None. Is this normal behavior or am missing something?

class HandlerA(telepot.helper.ChatHandler):
    def on_callback_query(self, msg):
        ...
        if query_data:
           print('class A handler') 

class HandlerB(telepot.helper.ChatHandler):
    def on_callback_query(self, msg):
        ...
        if query_data:
           print('class B handler')

bot = telepot.DelegatorBot(token, [
    include_callback_query_chat_id(pave_event_space())(per_chat_id_in(myset, types='private'), 
     create_open, HandlerA, timeout=20),
   
   include_callback_query_chat_id(pave_event_space())(per_chat_id_in(myset, types='private'), 
     create_open, HandlerB, timeout=20)
])

sample output of one inline button press

Class A handler
class B handler

That happens even though i would expect only ""Class A handler" to be printed out.

@nickoala
Copy link
Owner

... the seeder function of the second delegation pattern returns None.

I don't understand what this means. Nothing in delegation pattern returns None, as far as I can see.

Regardless, one message triggering more than one pattern is what my design allows. All patterns work independently. Your reported behavior is what is intended.

I am happy to see per_chat_id_in() being used. All those canned seeder functions did not go to waste. Thank you 😄

@jaroojim
Copy link
Author

jaroojim commented Nov 27, 2018

sorry for how i phrased the question it's just that am still learning english. i thought seeder functions like per_chat_id_in return either the chat_id or None. Let me elaborate a bit more.

def handle(self, msg):
        self._mic.send(msg)

        for calculate_seed, make_delegate, dict in self._delegate_records:
            id = calculate_seed(msg)

            if id is None:
                continue
            elif isinstance(id, collections.Hashable):
                if id not in dict or not dict[id].is_alive():
                    d = make_delegate((self, msg, id))
                    d = self._ensure_startable(d)

                    dict[id] = d
                    dict[id].start()
            else:
                d = make_delegate((self, msg, id))
                d = self._ensure_startable(d)
                d.start()

from the handle method of DelegatorBot, calculate_seed is called to calculate the id and if the id is None nothing happens. If am not wrong, the seeder functions are the ones that get called to produce functions that in turn produce the effect. In my issue above, include_callback_query_chat_id(pave_event_space())(per_chat_id_in(myset, types='private'), create_open, HandlerB, timeout=20) i expect the calculate_seed to return None because the chat_id is not in myset hence the accompanying delegator function shouldn't be called but somehow it gets called so my issue was, why does it call the accompanying delegator function even though it returns None?. I know am not so clear but please try to understand my question.

@Dulb26
Copy link

Dulb26 commented Jan 16, 2019

I have the same problem... i think the OP misunderstood delegator for seeder

My DelegatorBot have two include_callback_query_chat_id with per_chat_id_in with different ids in it and after a callback both respond creating one more thread beyond the first.

Using Lover example:

bot = telepot.DelegatorBot(TOKEN, [
    include_callback_query_chat_id(
        pave_event_space())(
            per_chat_id_in([group1],types=['private','group']), create_open, Lover, timeout=10),

    include_callback_query_chat_id(
        pave_event_space())(
            per_chat_id_in([group2],types=['private','group']), create_open, Lover, timeout=10),

])

The bot respond twice to the same group after a callback

Could you help?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants