tomer8007 / kik-bot-api-unofficial

Python API for writing unoffical Kik bots that act like humans
MIT License
128 stars 77 forks source link

on_group_search_response` callback doesn't invoke #208

Closed khigor777 closed 9 months ago

khigor777 commented 3 years ago

When I make search_group request , def on_group_search_response callback doesn't invoke. Any help?

 client = KikClient(callback=EchoBot(),
                       kik_username=username, kik_password=password)
    client.search_group(search_str)
class EchoBot(KikClientCallback):

    def on_group_search_response(self, response: GroupSearchResponse):
        print(response.groups)
StethoSaysHello commented 3 years ago

If you are using the EchoBot example as a template, did you remember to edit it to import GroupSearchResponse? If not, use:

from kik_unofficial.datatypes.xmpp.roster import GroupSearchResponse

I've posted working example source code for you to reference here. I hope this helps!

khigor777 commented 3 years ago

sure I adedd this import from kik_unofficial.datatypes.xmpp.roster import FetchRosterResponse, PeersInfoResponse, GroupSearchResponse

StethoSaysHello commented 3 years ago

Great! Did this fix your problem?

khigor777 commented 3 years ago

No, here is the full example: https://pastebin.com/4aPF5Tud

khigor777 commented 3 years ago

I set up breakpoint in def on_group_search_response method, but it doesn't invoke.

StethoSaysHello commented 3 years ago

You can't search for groups until your bot is authenticated, the code you provided attempts to search for groups immediately, prior to your bot being authenticated. I've made two edited copies of your code to demonstrate solutions to this.

Easy solution: Move search_group to under on_authenticated (Edited code here)

Another solution: Use a while loop to wait until bot is authenticated before triggering search_group (Edited code here)

khigor777 commented 3 years ago

Thanks a lot, works correctly, but after when I find groups I need token to join them, in documentation wrote that I can fetch it from GroupSearchResponse in def on_group_search_response(self, response: GroupSearchResponse) method, but what property should I use from GroupSearchResponse?

StethoSaysHello commented 3 years ago

Use self.group_join_token

If you peek over at line 181 of roster.py, you'll notice that GroupSearchResponse doesn't return tokens by default, but I just made a fork and edited that line to return the tokens too. (Example here.) In order to join groups you also need to make some more edits to bypass the safetynet check or it will raise the 400/bad-request error, this is discussed in more detail in my response to #207.

Edit: I don't intend on elaborating further on how to bypass the safetynet check here, due to the thot bot issue BlueMods mentioned in that previous issue. Honestly though its not worth the trouble with how often it times out anyways.