Move listen methods out of Client and into MQTT class
Make MQTT class / `Listener` public
This commit is contained in:
@@ -1,23 +1,19 @@
|
||||
import fbchat
|
||||
|
||||
|
||||
class RemoveBot(fbchat.Client):
|
||||
def on_message(self, author_id, message_object, thread, **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 isinstance(thread, fbchat.Group):
|
||||
print("{} will be removed from {}".format(author_id, thread))
|
||||
thread.remove_participant(author_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=thread,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
|
||||
session = fbchat.Session.login("<email>", "<password>")
|
||||
|
||||
remove_bot = RemoveBot(session)
|
||||
remove_bot.listen()
|
||||
listener = fbchat.Listener.connect(session, chat_on=False, foreground=False)
|
||||
|
||||
|
||||
def on_message(event):
|
||||
# We can only kick people from group chats, so no need to try if it's a user chat
|
||||
if not isinstance(event.thread, fbchat.Group):
|
||||
return
|
||||
if message.text == "Remove me!":
|
||||
print(f"{event.author.id} will be removed from {event.thread.id}")
|
||||
event.thread.remove_participant(event.author.id)
|
||||
|
||||
|
||||
for event in listener.listen():
|
||||
if isinstance(event, fbchat.MessageEvent):
|
||||
on_message(event)
|
||||
|
Reference in New Issue
Block a user