Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add @everyone example #521

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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)