Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions examples/mention_everyone.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""
This script allows you to do @everyone,
just like on Discord, but on messenger!
You can use it on your personal or separate account
(but this account needs to be added to group, obviously).
"""

import fbchat

session = fbchat.Session.login("<email", "<password>")

listener = fbchat.Listener.connect(session, chat_on=False, foreground=False)


def on_message(event):
print(f"{event.message.text} from {event.author.id} in {event.thread.id}")
thread = event.thread
if not isinstance(thread, fbchat.Group):
# Skip if it's not group
return
if event.message.text.lower() == "@everyone":
mentions = []
message = ""
# TODO: Get group's participants and add their mentions
for user in participants:
username = "" # TODO
message += username + " "
mentions.append(
fbchat.Mention(thread.id, offset=len(message), lenght=len(username))
)
thread.send_text(message, mentions=mentions)


for event in listener.listen():
if isinstance(event, fbchat.MessageEvent):
on_message(event)