tomer8007 / kik-bot-api-unofficial

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

"remove" tag error in roster #161

Closed automator87 closed 3 years ago

automator87 commented 4 years ago

Hello, whenever i run interactive_client.py in examples i get the following error:

Exception in thread Thread-30: Traceback (most recent call last): File "/data/data/com.termux/files/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner self.run() File "/data/data/com.termux/files/usr/lib/python3.8/threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "/storage/emulated/0/myPythons/kik-bot-api-unofficial/kik_unofficial/client.py", line 509, in _on_new_data_received self._handle_received_iq_element(xml_element) File "/storage/emulated/0/myPythons/kik-bot-api-unofficial/kik_unofficial/client.py", line 551, in _handle_received_iq_element self._handle_response(xml_namespace, iq_element) File "/storage/emulated/0/myPythons/kik-bot-api-unofficial/kik_unofficial/client.py", line 566, in _handle_response xmlns_handlers.RosterResponseHandler(self.callback, self).handle(iq_element) File "/storage/emulated/0/myPythons/kik-bot-api-unofficial/kik_unofficial/xmlns_handlers.py", line 168, in handle self.callback.on_roster_received(FetchRosterResponse(data)) File "ic.py", line 27, in on_roster_received friends[m.jid] = m AttributeError: 'NoneType' object has no attribute 'jid'

What could be the reason?

tomer8007 commented 4 years ago

It appears that one your chat partner's XML object does not have a jid attribute. Can you maybe post the stanzas you get from it (enable DEBUG logging)?

automator87 commented 4 years ago

It appears that one your chat partner's XML object does not have a jid attribute. Can you maybe post the stanzas you get from it (enable DEBUG logging)?

I cropped the part which i think is causing the issue, i replaced the real usernames data with user1,2,3,4 for privacy reasons. This is the final part of the roster i get, last 2 usernames (user3 and user4) seems different from others.

</item><item jid="user1_fkl@talk.kik.com"><username>user1</username><display-name>user1</display-name></item><item jid="user2_d7x@talk.kik.com"><username>user2</username><display-name>user2</display-name><pic ts="user2">http://profilepics.cf.kik.com/user2</pic></item><remove jid="user3@talk.kik.com"/><remove jid="user4@talk.kik.com"/></query></iq>'

tomer8007 commented 4 years ago

Yes, this explains the issue. parse_peer returns None because the element type is remove and not item.

Considering what you know about the last two mentioned JIDs, can you guess what is the meaning of the remove tag? We'll add it to the roster parsing.

automator87 commented 4 years ago

I looked them up on the kik app but couldn't find them. Might be accounts were deleted but kik is still keeping them on roster? Not sure if there is any other explanation.

tomer8007 commented 4 years ago

Well, whatever it is, I tried to add parsing of it, please tell me if it works for you now.

automator87 commented 4 years ago

Well, whatever it is, I tried to add parsing of it, please tell me if it works for you now.

Sadly still getting the same message. Also forgot to tell the roster ends at those 2 broken jids, even if i add new friends (using add_friend(chat_message.from_jid)) they won't show up on roster

Exception in thread Thread-22: Traceback (most recent call last): File "/data/data/com.termux/files/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner self.run() File "/data/data/com.termux/files/usr/lib/python3.8/threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "/storage/emulated/0/myPythons/kik-bot-api-unofficial/kik_unofficial/client.py", line 512, in _on_new_data_received self._handle_received_iq_element(xml_element) File "/storage/emulated/0/myPythons/kik-bot-api-unofficial/kik_unofficial/client.py", line 554, in _handle_received_iq_element self._handle_response(xml_namespace, iq_element) File "/storage/emulated/0/myPythons/kik-bot-api-unofficial/kik_unofficial/client.py", line 569, in _handle_response xmlns_handlers.RosterResponseHandler(self.callback, self).handle(iq_element) File "/storage/emulated/0/myPythons/kik-bot-api-unofficial/kik_unofficial/xmlns_handlers.py", line 168, in handle self.callback.on_roster_received(FetchRosterResponse(data)) File "mb5.py", line 81, in on_roster_received friends[m.jid] = m AttributeError: 'NoneType' object has no attribute 'jid'

tomer8007 commented 4 years ago

Seems to be a typo of mine, try with this commit.

automator87 commented 4 years ago

Seems to be a typo of mine, try with this commit.

Thank you the error is now gone but there is still one issue, the roster stops at those 2 removed usernames (which are both shown as none by echo_bot.py), if i add new friends by api they won't show up in the roster

Even if i add friends by kik app the roster stops at those 2 removed jids

tomer8007 commented 4 years ago

When you add a friend, do you see it in the real kik app?

automator87 commented 4 years ago

When you add a friend, do you see it in the real kik app?

Yes i do, so apparently there is some blocking point while generating roster when users with remove tag are found

tomer8007 commented 4 years ago

What happens if you add the same JID as a friend from a new kik account? Does it show in the roster?

automator87 commented 4 years ago

No it doesn't. This is what i get (myuser is my account and deleted user is the deleted jid)

[2020-08-04 06:39:01,701] DEBUG (thread Kik Connection): [+] Received raw data: b'<iq to="myuser@talk.kik.com/CAN62030843678b7376a707ca3d11e87836" id="fba8a8f9-e305-4208-be96-2f211947dd22" type="error"><query xmlns="kik:iq:friend"><add jid="deleteduser@talk.kik.com"/></query><error type="cancel" code="404"><item-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/><text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" xml:lang="en">User not found</text><not-registered xmlns="kik:error"/></error></iq>'

tomer8007 commented 4 years ago

So deleted accounts don't show in roster and you can't add them as a frined (which makes sense)?

automator87 commented 4 years ago

The jid is shown in roster with the "removed" tag in debug mode, in the roster showing usernames they are shown as "none", any friend added after them is not shown in the roster, i can't add them as a friend on a new account.

tomer8007 commented 4 years ago

It is weird if there is a "blocking point" in the roster, it does makes sense if deleted accounts aren't shown. Other than that I'm not sure how I can debug that.

automator87 commented 4 years ago

I will try to understand more, not sure if you have any private contact method, i could maybe provide more detailed info

tomer8007 commented 4 years ago

When you say that these users don't show up in the roster, do you mean they're not even on the XML, or just that the API does not parse them?

bluemods commented 4 years ago

<remove and <remove-group tags are both used for when a group or user no longer exists / you are no longer chatting with them (I'm pretty sure) so don't forget those.

remove is for PM jids and remove-group is for group jids.

tomer8007 commented 4 years ago

Thanks, I added support for remove-group as well.

automator87 commented 4 years ago

When you say that these users don't show up in the roster, do you mean they're not even on the XML, or just that the API does not parse them?

They show up in the xml, but they show up as none in the usernames roster

tomer8007 commented 4 years ago

So it's just a python bug? Sounds pretty easy to debug.

automator87 commented 4 years ago

I am on vacation now so i am using termux from my phone, i will do something more when i am on pc