From f968e583e8fd1c2319fc91b2fbc36435ead078ee Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Thu, 9 Jan 2020 10:54:07 +0100 Subject: [PATCH] Make Client.session attribute public --- examples/echobot.py | 2 +- examples/keepbot.py | 6 +++--- fbchat/_client.py | 14 +++++++------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/examples/echobot.py b/examples/echobot.py index 8e482e9..3dda78c 100644 --- a/examples/echobot.py +++ b/examples/echobot.py @@ -9,7 +9,7 @@ class EchoBot(fbchat.Client): print("{} from {} in {}".format(message_object, thread_id, thread_type.name)) # If you're not the author, echo - if author_id != session.user_id: + if author_id != self.session.user_id: self.send(message_object, thread_id=thread_id, thread_type=thread_type) diff --git a/examples/keepbot.py b/examples/keepbot.py index 7ce8874..eb89d42 100644 --- a/examples/keepbot.py +++ b/examples/keepbot.py @@ -31,7 +31,7 @@ class KeepBot(fbchat.Client): self.change_thread_emoji(old_emoji, thread_id=thread_id) def on_people_added(self, added_ids, author_id, thread_id, **kwargs): - if old_thread_id == thread_id and author_id != session.user_id: + if old_thread_id == thread_id and author_id != self.session.user_id: print("{} got added. They will be removed".format(added_ids)) for added_id in added_ids: self.remove_user_from_group(added_id, thread_id=thread_id) @@ -40,8 +40,8 @@ class KeepBot(fbchat.Client): # No point in trying to add ourself if ( old_thread_id == thread_id - and removed_id != session.user_id - and author_id != session.user_id + and removed_id != self.session.user_id + and author_id != self.session.user_id ): print("{} got removed. They will be re-added".format(removed_id)) self.add_users_to_group(removed_id, thread_id=thread_id) diff --git a/fbchat/_client.py b/fbchat/_client.py index e5fa3d8..2dad8c1 100644 --- a/fbchat/_client.py +++ b/fbchat/_client.py @@ -44,15 +44,10 @@ class Client: """ def __init__(self, session): - """Initialize and log in the client. + """Initialize the client model. Args: - email: Facebook ``email``, ``id`` or ``phone number`` - password: Facebook account password - session_cookies (dict): Cookies from a previous session (Will default to login if these are invalid) - - Raises: - FBchatException: On failed login + session: The session to use when making requests. """ self._sticky, self._pool = (None, None) self._seq = "0" @@ -61,6 +56,11 @@ class Client: self._buddylist = dict() self._session = session + @property + def session(self): + """The session that's used when making requests.""" + return self._session + """ INTERNAL REQUEST METHODS """