fbchat-dev / fbchat

Facebook Chat (Messenger) for Python
https://fbchat.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.19k stars 412 forks source link

client.listen() not working as intended #387

Closed DAMO238 closed 5 years ago

DAMO238 commented 5 years ago

I had a few simple bots running, and wanted to upgrade one of them, after fixing a couple bugs, suddenly it couldn't trigger the OnEmoteChange callback anymore. I then realised no output of events was going into the console, so I tried restarting a different script which caused that (unaltered) script to also exhibit this behaviour. So I restarted my VM and tried again, same result. Tried restarting my host (incase it was some weird connection error). Tried a pip3 upgrade. Even tried reloading a snapshot from when it was working and it still didn't work. One thing to note was that when closing the terminal, it didn't throw a warning that a process was running, yet it did not return to bash.

My code (or at least one of them):

from fbchat import log, Client
from fbchat.models import *

from getpass import getpass

p = getpass()
old_thread_id = <Target Thread Here>

old_emoji = '💿'

class KeepBot(Client):

    def onEmojiChange(self, author_id, new_emoji, thread_id, thread_type, **kwargs):
        print("detected")
        if old_thread_id == thread_id and new_emoji != old_emoji:
            print("detected")
            author = self.fetchUserInfo(author_id)
            self.send(Message("{}, why did you change the emoji?! I will be change it back".format(author[author_id].first_name)), thread_id, thread_type)
            self.changeThreadEmoji(old_emoji, thread_id=thread_id)

client = KeepBot(<My Email Here>, p)
client.listen()

output:

Password: logging in login of successful Listening... <No matter what happens in messenger, no output>

Environment information

If you have done any research, include that. Make sure to redact all personal information.

madsmtm commented 5 years ago

Thanks for the report 👍. I'm not home right now, but I'll investigate it ASAP!

In the meantime, you can enable debug logging, which might give you some more insight:

import logging
logging.basicConfig(level=loggin.DEBUG)
DAMO238 commented 5 years ago

Thanks for the reply, I just woke up, (didn't turn off my scripts) and they mysteriously started working again during the night. My hypothesis is that facebook saw 'suspicious activity' and refused to send me my data, and then relaxed that restriction during the night.

Thanks anyway!