This repository has been archived on 2025-07-31. You can view files and clone it, but cannot push or open issues or pull requests.
Files
fbchat/examples/removebot.py
Mads Marquart 78949e8ad5 Update examples
Only `import fbchat`, and update to initialize Client using Session
2020-01-08 10:45:41 +01:00

28 lines
985 B
Python

import fbchat
class RemoveBot(fbchat.Client):
def on_message(self, author_id, message_object, thread_id, thread_type, **kwargs):
# We can only kick people from group chats, so no need to try if it's a user chat
if (
message_object.text == "Remove me!"
and thread_type == fbchat.ThreadType.GROUP
):
print("{} will be removed from {}".format(author_id, thread_id))
self.remove_user_from_group(author_id, thread_id=thread_id)
else:
# Sends the data to the inherited on_message, so that we can still see when a message is recieved
super(RemoveBot, self).on_message(
author_id=author_id,
message_object=message_object,
thread_id=thread_id,
thread_type=thread_type,
**kwargs,
)
session = fbchat.Session.login("<email>", "<password>")
remove_bot = RemoveBot(session)
remove_bot.listen()