Add Session.user in favor of Session.user_id
This commit is contained in:
@@ -3,13 +3,10 @@ import fbchat
|
||||
# Log the user in
|
||||
session = fbchat.Session.login("<email>", "<password>")
|
||||
|
||||
print("Own id: {}".format(session.user_id))
|
||||
|
||||
# Create helper User class
|
||||
user = fbchat.Thread(session=session, id=session.user_id)
|
||||
print("Own id: {}".format(session.user.id))
|
||||
|
||||
# Send a message to yourself
|
||||
user.send_text("Hi me!")
|
||||
session.user.send_text("Hi me!")
|
||||
|
||||
# Log the user out
|
||||
session.logout()
|
||||
|
@@ -8,7 +8,7 @@ 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}")
|
||||
# If you're not the author, echo
|
||||
if event.author.id != session.user_id:
|
||||
if event.author.id != session.user.id:
|
||||
event.thread.send_text(event.message.text)
|
||||
|
||||
|
||||
|
@@ -5,7 +5,7 @@ session = fbchat.Session.login("<email>", "<password>")
|
||||
|
||||
client = fbchat.Client(session)
|
||||
|
||||
thread = fbchat.User(session=session, id=session.user_id)
|
||||
thread = session.user
|
||||
# thread = fbchat.User(session=session, id="0987654321")
|
||||
# thread = fbchat.Group(session=session, id="1234567890")
|
||||
|
||||
@@ -48,7 +48,7 @@ if isinstance(thread, fbchat.Group):
|
||||
thread.set_title("<title>")
|
||||
|
||||
|
||||
# Will change the nickname of the user `<user_id>` to `<new nickname>`
|
||||
# Will change the nickname of the user `<user id>` to `<new nickname>`
|
||||
thread.set_nickname(fbchat.User(session=session, id="<user id>"), "<new nickname>")
|
||||
|
||||
# Will set the typing status of the thread
|
||||
|
@@ -58,7 +58,7 @@ def on_nickname_set(event: fbchat.NicknameSet):
|
||||
def on_people_added(event: fbchat.PeopleAdded):
|
||||
if old_thread_id != event.thread.id:
|
||||
return
|
||||
if event.author.id != session.user_id:
|
||||
if event.author.id != session.user.id:
|
||||
print(f"{', '.join(x.id for x in event.added)} got added. They will be removed")
|
||||
for added in event.added:
|
||||
event.thread.remove_participant(added.id)
|
||||
@@ -68,9 +68,9 @@ def on_person_removed(event: fbchat.PersonRemoved):
|
||||
if old_thread_id != event.thread.id:
|
||||
return
|
||||
# No point in trying to add ourself
|
||||
if event.removed.id == session.user_id:
|
||||
if event.removed.id == session.user.id:
|
||||
return
|
||||
if event.author.id != session.user_id:
|
||||
if event.author.id != session.user.id:
|
||||
print(f"{event.removed.id} got removed. They will be re-added")
|
||||
event.thread.add_participants([removed.id])
|
||||
|
||||
|
Reference in New Issue
Block a user