diff --git a/docs/intro.rst b/docs/intro.rst index c660805..6a9e956 100644 --- a/docs/intro.rst +++ b/docs/intro.rst @@ -14,7 +14,7 @@ Logging In ---------- Simply create an instance of :class:`Client`. If you have two factor authentication enabled, type the code in the terminal prompt -(If you want to supply the code in another fashion, overwrite :func:`Client.on2FACode`):: +(If you want to supply the code in another fashion, overwrite :func:`Client.on_2fa_code`):: from fbchat import Client from fbchat.models import * @@ -28,10 +28,10 @@ Replace ```` and ```` with your email and password respectively If you want to change how verbose ``fbchat`` is, change the logging level (in :class:`Client`) -Throughout your code, if you want to check whether you are still logged in, use :func:`Client.isLoggedIn`. +Throughout your code, if you want to check whether you are still logged in, use :func:`Client.is_logged_in`. An example would be to login again if you've been logged out, using :func:`Client.login`:: - if not client.isLoggedIn(): + if not client.is_logged_in(): client.login('', '') When you're done using the client, and want to securely logout, use :func:`Client.logout`:: @@ -50,8 +50,8 @@ A thread can refer to two things: A Messenger group chat or a single Facebook us These will specify whether the thread is a single user chat or a group chat. This is required for many of ``fbchat``'s functions, since Facebook differentiates between these two internally -Searching for group chats and finding their ID can be done via. :func:`Client.searchForGroups`, -and searching for users is possible via. :func:`Client.searchForUsers`. See :ref:`intro_fetching` +Searching for group chats and finding their ID can be done via. :func:`Client.search_for_groups`, +and searching for users is possible via. :func:`Client.search_for_users`. See :ref:`intro_fetching` You can get your own user ID by using :any:`Client.uid` @@ -71,10 +71,10 @@ corresponds to the ID of a single user, and the ID of a group respectively:: client.send(Message(text=''), thread_id='', thread_type=ThreadType.USER) client.send(Message(text=''), thread_id='', thread_type=ThreadType.GROUP) -Some functions (e.g. :func:`Client.changeThreadColor`) don't require a thread type, so in these cases you just provide the thread ID:: +Some functions (e.g. :func:`Client.change_thread_color`) don't require a thread type, so in these cases you just provide the thread ID:: - client.changeThreadColor(ThreadColor.BILOBA_FLOWER, thread_id='') - client.changeThreadColor(ThreadColor.MESSENGER_BLUE, thread_id='') + client.change_thread_color(ThreadColor.BILOBA_FLOWER, thread_id='') + client.change_thread_color(ThreadColor.MESSENGER_BLUE, thread_id='') .. _intro_message_ids: @@ -85,12 +85,12 @@ Message IDs Every message you send on Facebook has a unique ID, and every action you do in a thread, like changing a nickname or adding a person, has a unique ID too. -Some of ``fbchat``'s functions require these ID's, like :func:`Client.reactToMessage`, -and some of then provide this ID, like :func:`Client.sendMessage`. +Some of ``fbchat``'s functions require these ID's, like :func:`Client.react_to_message`, +and some of then provide this ID, like :func:`Client.send`. This snippet shows how to send a message, and then use the returned ID to react to that message with a 😍 emoji:: message_id = client.send(Message(text='message'), thread_id=thread_id, thread_type=thread_type) - client.reactToMessage(message_id, MessageReaction.LOVE) + client.react_to_message(message_id, MessageReaction.LOVE) .. _intro_interacting: @@ -118,10 +118,10 @@ Fetching Information You can use ``fbchat`` to fetch basic information like user names, profile pictures, thread names and user IDs -You can retrieve a user's ID with :func:`Client.searchForUsers`. +You can retrieve a user's ID with :func:`Client.search_for_users`. The following snippet will search for users by their name, take the first (and most likely) user, and then get their user ID from the result:: - users = client.searchForUsers('') + users = client.search_for_users('') user = users[0] print("User's ID: {}".format(user.uid)) print("User's name: {}".format(user.name)) @@ -140,13 +140,13 @@ Sessions ``fbchat`` provides functions to retrieve and set the session cookies. This will enable you to store the session cookies in a separate file, so that you don't have to login each time you start your script. -Use :func:`Client.getSession` to retrieve the cookies:: +Use :func:`Client.get_gession` to retrieve the cookies:: - session_cookies = client.getSession() + session_cookies = client.get_gession() -Then you can use :func:`Client.setSession`:: +Then you can use :func:`Client.set_gession`:: - client.setSession(session_cookies) + client.set_gession(session_cookies) Or you can set the ``session_cookies`` on your initial login. (If the session cookies are invalid, your email and password will be used to login instead):: @@ -168,12 +168,12 @@ By default, (most) events will just be a `logging.info` statement, meaning it will simply print information to the console when an event happens .. note:: - You can identify the event methods by their ``on`` prefix, e.g. `onMessage` + You can identify the event methods by their ``on`` prefix, e.g. ``on_message`` The event actions can be changed by subclassing the :class:`Client`, and then overwriting the event methods:: class CustomClient(Client): - def onMessage(self, mid, author_id, message_object, thread_id, thread_type, ts, metadata, msg, **kwargs): + def on_message(self, mid, author_id, message_object, thread_id, thread_type, ts, metadata, msg, **kwargs): # Do something with message_object here pass @@ -182,13 +182,13 @@ The event actions can be changed by subclassing the :class:`Client`, and then ov **Notice:** The following snippet is as equally valid as the previous one:: class CustomClient(Client): - def onMessage(self, message_object, author_id, thread_id, thread_type, **kwargs): + def on_message(self, message_object, author_id, thread_id, thread_type, **kwargs): # Do something with message_object here pass client = CustomClient('', '') -The change was in the parameters that our `onMessage` method took: ``message_object`` and ``author_id`` got swapped, +The change was in the parameters that our ``on_message`` method took: ``message_object`` and ``author_id`` got swapped, and ``mid``, ``ts``, ``metadata`` and ``msg`` got removed, but the function still works, since we included ``**kwargs`` .. note:: diff --git a/docs/todo.rst b/docs/todo.rst index f94135c..18d063d 100644 --- a/docs/todo.rst +++ b/docs/todo.rst @@ -9,7 +9,7 @@ This page will be periodically updated to show missing features and documentatio Missing Functionality --------------------- -- Implement ``Client.searchForMessage`` +- Implement ``Client.search_for_message`` - This will use the GraphQL request API - Implement chatting with pages properly - Write better FAQ diff --git a/examples/echobot.py b/examples/echobot.py index f504ed5..2a4ae0f 100644 --- a/examples/echobot.py +++ b/examples/echobot.py @@ -2,9 +2,9 @@ from fbchat import Client # Subclass fbchat.Client and override required methods class EchoBot(Client): - def onMessage(self, author_id, message_object, thread_id, thread_type, **kwargs): - self.markAsDelivered(thread_id, message_object.uid) - self.markAsRead(thread_id) + def on_message(self, author_id, message_object, thread_id, thread_type, **kwargs): + self.mark_as_delivered(thread_id, message_object.uid) + self.mark_as_read(thread_id) print("{} from {} in {}".format(message_object, thread_id, thread_type.name)) diff --git a/examples/fetch.py b/examples/fetch.py index f18c048..26be45b 100644 --- a/examples/fetch.py +++ b/examples/fetch.py @@ -5,24 +5,24 @@ from fbchat.models import * client = Client("", "") # Fetches a list of all users you're currently chatting with, as `User` objects -users = client.fetchAllUsers() +users = client.fetch_all_users() print("users' IDs: {}".format([user.uid for user in users])) print("users' names: {}".format([user.name for user in users])) -# If we have a user id, we can use `fetchUserInfo` to fetch a `User` object -user = client.fetchUserInfo("")[""] +# If we have a user id, we can use `fetch_user_info` to fetch a `User` object +user = client.fetch_user_info("")[""] # We can also query both mutiple users together, which returns list of `User` objects -users = client.fetchUserInfo("<1st user id>", "<2nd user id>", "<3rd user id>") +users = client.fetch_user_info("<1st user id>", "<2nd user id>", "<3rd user id>") print("user's name: {}".format(user.name)) print("users' names: {}".format([users[k].name for k in users])) -# `searchForUsers` searches for the user and gives us a list of the results, +# `search_for_users` searches for the user and gives us a list of the results, # and then we just take the first one, aka. the most likely one: -user = client.searchForUsers("")[0] +user = client.search_for_users("")[0] print("user ID: {}".format(user.uid)) print("user's name: {}".format(user.name)) @@ -31,15 +31,15 @@ print("Is user client's friend: {}".format(user.is_friend)) # Fetches a list of the 20 top threads you're currently chatting with -threads = client.fetchThreadList() +threads = client.fetch_thread_list() # Fetches the next 10 threads -threads += client.fetchThreadList(offset=20, limit=10) +threads += client.fetch_thread_list(offset=20, limit=10) print("Threads: {}".format(threads)) # Gets the last 10 messages sent to the thread -messages = client.fetchThreadMessages(thread_id="", limit=10) +messages = client.fetch_thread_messages(thread_id="", limit=10) # Since the message come in reversed order, reverse them messages.reverse() @@ -48,14 +48,14 @@ for message in messages: print(message.text) -# If we have a thread id, we can use `fetchThreadInfo` to fetch a `Thread` object -thread = client.fetchThreadInfo("")[""] +# If we have a thread id, we can use `fetch_thread_info` to fetch a `Thread` object +thread = client.fetch_thread_info("")[""] print("thread's name: {}".format(thread.name)) print("thread's type: {}".format(thread.type)) -# `searchForThreads` searches works like `searchForUsers`, but gives us a list of threads instead -thread = client.searchForThreads("")[0] +# `search_for_threads` searches works like `search_for_users`, but gives us a list of threads instead +thread = client.search_for_threads("")[0] print("thread's name: {}".format(thread.name)) print("thread's type: {}".format(thread.type)) @@ -64,6 +64,6 @@ print("thread's type: {}".format(thread.type)) # Print image url for 20 last images from thread. -images = client.fetchThreadImages("") +images = client.fetch_thread_images("") for image in islice(image, 20): print(image.large_preview_url) diff --git a/examples/interract.py b/examples/interract.py index f40f1ca..2d2ed27 100644 --- a/examples/interract.py +++ b/examples/interract.py @@ -38,7 +38,7 @@ client.send( ) # Will send the image located at `` -client.sendLocalImage( +client.send_local_image( "", message=Message(text="This is a local image"), thread_id=thread_id, @@ -46,7 +46,7 @@ client.sendLocalImage( ) # Will download the image at the URL ``, and then send it -client.sendRemoteImage( +client.send_remote_image( "", message=Message(text="This is a remote image"), thread_id=thread_id, @@ -57,35 +57,35 @@ client.sendRemoteImage( # Only do these actions if the thread is a group if thread_type == ThreadType.GROUP: # Will remove the user with ID `` from the thread - client.removeUserFromGroup("", thread_id=thread_id) + client.remove_user_from_group("", thread_id=thread_id) # Will add the user with ID `` to the thread - client.addUsersToGroup("", thread_id=thread_id) + client.add_users_to_group("", thread_id=thread_id) # Will add the users with IDs `<1st user id>`, `<2nd user id>` and `<3th user id>` to the thread - client.addUsersToGroup( + client.add_users_to_group( ["<1st user id>", "<2nd user id>", "<3rd user id>"], thread_id=thread_id ) # Will change the nickname of the user `` to `` -client.changeNickname( +client.change_nickname( "", "", thread_id=thread_id, thread_type=thread_type ) # Will change the title of the thread to `` -client.changeThreadTitle("<title>", thread_id=thread_id, thread_type=thread_type) +client.change_thread_title("<title>", thread_id=thread_id, thread_type=thread_type) # Will set the typing status of the thread to `TYPING` -client.setTypingStatus( +client.set_typing_status( TypingStatus.TYPING, thread_id=thread_id, thread_type=thread_type ) # Will change the thread color to `MESSENGER_BLUE` -client.changeThreadColor(ThreadColor.MESSENGER_BLUE, thread_id=thread_id) +client.change_thread_color(ThreadColor.MESSENGER_BLUE, thread_id=thread_id) # Will change the thread emoji to `👍` -client.changeThreadEmoji("👍", thread_id=thread_id) +client.change_thread_emoji("👍", thread_id=thread_id) # Will react to a message with a 😍 emoji -client.reactToMessage("<message id>", MessageReaction.LOVE) +client.react_to_message("<message id>", MessageReaction.LOVE) diff --git a/examples/keepbot.py b/examples/keepbot.py index 43b4382..e4a701b 100644 --- a/examples/keepbot.py +++ b/examples/keepbot.py @@ -17,27 +17,27 @@ old_nicknames = { class KeepBot(Client): - def onColorChange(self, author_id, new_color, thread_id, thread_type, **kwargs): + def on_color_change(self, author_id, new_color, thread_id, thread_type, **kwargs): if old_thread_id == thread_id and old_color != new_color: print( "{} changed the thread color. It will be changed back".format(author_id) ) - self.changeThreadColor(old_color, thread_id=thread_id) + self.change_thread_color(old_color, thread_id=thread_id) - def onEmojiChange(self, author_id, new_emoji, thread_id, thread_type, **kwargs): + def on_emoji_change(self, author_id, new_emoji, thread_id, thread_type, **kwargs): if old_thread_id == thread_id and new_emoji != old_emoji: print( "{} changed the thread emoji. It will be changed back".format(author_id) ) - self.changeThreadEmoji(old_emoji, thread_id=thread_id) + self.change_thread_emoji(old_emoji, thread_id=thread_id) - def onPeopleAdded(self, added_ids, author_id, thread_id, **kwargs): + def on_people_added(self, added_ids, author_id, thread_id, **kwargs): if old_thread_id == thread_id and author_id != self.uid: print("{} got added. They will be removed".format(added_ids)) for added_id in added_ids: - self.removeUserFromGroup(added_id, thread_id=thread_id) + self.remove_user_from_group(added_id, thread_id=thread_id) - def onPersonRemoved(self, removed_id, author_id, thread_id, **kwargs): + def on_person_removed(self, removed_id, author_id, thread_id, **kwargs): # No point in trying to add ourself if ( old_thread_id == thread_id @@ -45,18 +45,18 @@ class KeepBot(Client): and author_id != self.uid ): print("{} got removed. They will be re-added".format(removed_id)) - self.addUsersToGroup(removed_id, thread_id=thread_id) + self.add_users_to_group(removed_id, thread_id=thread_id) - def onTitleChange(self, author_id, new_title, thread_id, thread_type, **kwargs): + def on_title_change(self, author_id, new_title, thread_id, thread_type, **kwargs): if old_thread_id == thread_id and old_title != new_title: print( "{} changed the thread title. It will be changed back".format(author_id) ) - self.changeThreadTitle( + self.change_thread_title( old_title, thread_id=thread_id, thread_type=thread_type ) - def onNicknameChange( + def on_nickname_change( self, author_id, changed_for, new_nickname, thread_id, thread_type, **kwargs ): if ( @@ -69,7 +69,7 @@ class KeepBot(Client): author_id, changed_for ) ) - self.changeNickname( + self.change_nickname( old_nicknames[changed_for], changed_for, thread_id=thread_id, diff --git a/examples/removebot.py b/examples/removebot.py index 61571fb..1e76608 100644 --- a/examples/removebot.py +++ b/examples/removebot.py @@ -3,14 +3,14 @@ from fbchat.models import * class RemoveBot(Client): - def onMessage(self, author_id, message_object, thread_id, thread_type, **kwargs): + def on_message(self, author_id, message_object, thread_id, thread_type, **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 thread_type == ThreadType.GROUP: print("{} will be removed from {}".format(author_id, thread_id)) - self.removeUserFromGroup(author_id, thread_id=thread_id) + self.remove_user_from_group(author_id, thread_id=thread_id) else: - # Sends the data to the inherited onMessage, so that we can still see when a message is recieved - super(RemoveBot, self).onMessage( + # 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_id=thread_id, diff --git a/fbchat/_client.py b/fbchat/_client.py index b0f2915..34501f5 100644 --- a/fbchat/_client.py +++ b/fbchat/_client.py @@ -65,14 +65,14 @@ class Client: self._sticky, self._pool = (None, None) self._seq = "0" self._pull_channel = 0 - self._markAlive = True + self._mark_alive = True self._buddylist = dict() # If session cookies aren't set, not properly loaded or gives us an invalid session, then do the login if ( not session_cookies - or not self.setSession(session_cookies) - or not self.isLoggedIn() + or not self.set_gession(session_cookies) + or not self.is_logged_in() ): self.login(email, password) @@ -119,7 +119,7 @@ class Client: LOGIN METHODS """ - def isLoggedIn(self): + def is_logged_in(self): """Send a request to Facebook to check the login status. Returns: @@ -127,7 +127,7 @@ class Client: """ return self._state.is_logged_in() - def getSession(self): + def get_session(self): """Retrieve session cookies. Returns: @@ -135,7 +135,7 @@ class Client: """ return self._state.get_cookies() - def setSession(self, session_cookies): + def set_session(self, session_cookies): """Load session cookies. Args: @@ -165,16 +165,16 @@ class Client: Raises: FBchatException: On failed login """ - self.onLoggingIn(email=email) + self.on_logging_in(email=email) if not (email and password): raise ValueError("Email and password not set") self._state = _state.State.login( - email, password, on_2fa_callback=self.on2FACode + email, password, on_2fa_callback=self.on_2fa_code ) self._uid = self._state.user_id - self.onLoggedIn(email=email) + self.on_logged_in(email=email) def logout(self): """Safely log out the client. @@ -196,12 +196,12 @@ class Client: FETCH METHODS """ - def _forcedFetch(self, thread_id, mid): + def _forced_fetch(self, thread_id, mid): params = {"thread_and_message_id": {"thread_id": thread_id, "message_id": mid}} j, = self.graphql_requests(_graphql.from_doc_id("1768656253222505", params)) return j - def fetchThreads(self, thread_location, before=None, after=None, limit=None): + def fetch_threads(self, thread_location, before=None, after=None, limit=None): """Fetch all threads in ``thread_location``. Threads will be sorted from newest to oldest. @@ -228,8 +228,8 @@ class Client: if limit and len(threads) >= limit: break - # fetchThreadList returns at max 20 threads before last_thread_dt (included) - candidates = self.fetchThreadList( + # fetch_thread_list returns at max 20 threads before last_thread_dt (included) + candidates = self.fetch_thread_list( before=last_thread_dt, thread_location=thread_location ) @@ -259,7 +259,7 @@ class Client: return threads - def fetchAllUsersFromThreads(self, threads): + def fetch_all_users_from_threads(self, threads): """Fetch all users involved in given threads. Args: @@ -284,11 +284,11 @@ class Client: and user_id not in users_to_fetch ): users_to_fetch.append(user_id) - for user_id, user in self.fetchUserInfo(*users_to_fetch).items(): + for user_id, user in self.fetch_user_info(*users_to_fetch).items(): users.append(user) return users - def fetchAllUsers(self): + def fetch_all_users(self): """Fetch all users the client is currently chatting with. Returns: @@ -309,7 +309,7 @@ class Client: users.append(User._from_all_fetch(data)) return users - def searchForUsers(self, name, limit=10): + def search_for_users(self, name, limit=10): """Find and get users by their name. Args: @@ -327,7 +327,7 @@ class Client: return [User._from_graphql(node) for node in j[name]["users"]["nodes"]] - def searchForPages(self, name, limit=10): + def search_for_pages(self, name, limit=10): """Find and get pages by their name. Args: @@ -344,7 +344,7 @@ class Client: return [Page._from_graphql(node) for node in j[name]["pages"]["nodes"]] - def searchForGroups(self, name, limit=10): + def search_for_groups(self, name, limit=10): """Find and get group threads by their name. Args: @@ -362,7 +362,7 @@ class Client: return [Group._from_graphql(node) for node in j["viewer"]["groups"]["nodes"]] - def searchForThreads(self, name, limit=10): + def search_for_threads(self, name, limit=10): """Find and get threads by their name. Args: @@ -397,7 +397,7 @@ class Client: return rtn - def searchForMessageIDs(self, query, offset=0, limit=5, thread_id=None): + def search_for_message_ids(self, query, offset=0, limit=5, thread_id=None): """Find and get message IDs by query. Args: @@ -426,7 +426,7 @@ class Client: for snippet in snippets: yield snippet["message_id"] - def searchForMessages(self, query, offset=0, limit=5, thread_id=None): + def search_for_messages(self, query, offset=0, limit=5, thread_id=None): """Find and get `Message` objects by query. Warning: @@ -444,11 +444,11 @@ class Client: Raises: FBchatException: If request failed """ - message_ids = self.searchForMessageIDs( + message_ids = self.search_for_message_ids( query, offset=offset, limit=limit, thread_id=thread_id ) for mid in message_ids: - yield self.fetchMessageInfo(mid, thread_id) + yield self.fetch_message_info(mid, thread_id) def search(self, query, fetch_messages=False, thread_limit=5, message_limit=5): """Search for messages in all threads. @@ -473,16 +473,16 @@ class Client: return {} if fetch_messages: - search_method = self.searchForMessages + search_method = self.search_for_messages else: - search_method = self.searchForMessageIDs + search_method = self.search_for_message_ids return { thread_id: search_method(query, limit=message_limit, thread_id=thread_id) for thread_id in result } - def _fetchInfo(self, *ids): + def _fetch_info(self, *ids): data = {"ids[{}]".format(i): _id for i, _id in enumerate(ids)} j = self._payload_post("/chat/user_info/", data) @@ -519,7 +519,7 @@ class Client: log.debug(entries) return entries - def fetchUserInfo(self, *user_ids): + def fetch_user_info(self, *user_ids): """Fetch users' info from IDs, unordered. Warning: @@ -534,7 +534,7 @@ class Client: Raises: FBchatException: If request failed """ - threads = self.fetchThreadInfo(*user_ids) + threads = self.fetch_thread_info(*user_ids) users = {} for id_, thread in threads.items(): if thread.type == ThreadType.USER: @@ -544,7 +544,7 @@ class Client: return users - def fetchPageInfo(self, *page_ids): + def fetch_page_info(self, *page_ids): """Fetch pages' info from IDs, unordered. Warning: @@ -559,7 +559,7 @@ class Client: Raises: FBchatException: If request failed """ - threads = self.fetchThreadInfo(*page_ids) + threads = self.fetch_thread_info(*page_ids) pages = {} for id_, thread in threads.items(): if thread.type == ThreadType.PAGE: @@ -569,7 +569,7 @@ class Client: return pages - def fetchGroupInfo(self, *group_ids): + def fetch_group_info(self, *group_ids): """Fetch groups' info from IDs, unordered. Args: @@ -581,7 +581,7 @@ class Client: Raises: FBchatException: If request failed """ - threads = self.fetchThreadInfo(*group_ids) + threads = self.fetch_thread_info(*group_ids) groups = {} for id_, thread in threads.items(): if thread.type == ThreadType.GROUP: @@ -591,7 +591,7 @@ class Client: return groups - def fetchThreadInfo(self, *thread_ids): + def fetch_thread_info(self, *thread_ids): """Fetch threads' info from IDs, unordered. Warning: @@ -634,7 +634,7 @@ class Client: ] pages_and_users = {} if len(pages_and_user_ids) != 0: - pages_and_users = self._fetchInfo(*pages_and_user_ids) + pages_and_users = self._fetch_info(*pages_and_user_ids) rtn = {} for i, entry in enumerate(j): @@ -658,7 +658,7 @@ class Client: return rtn - def fetchThreadMessages(self, thread_id=None, limit=20, before=None): + def fetch_thread_messages(self, thread_id=None, limit=20, before=None): """Fetch messages in a thread, ordered by most recent. Args: @@ -702,7 +702,7 @@ class Client: return messages - def fetchThreadList( + def fetch_thread_list( self, limit=20, thread_location=ThreadLocation.INBOX, before=None ): """Fetch the client's thread list. @@ -748,7 +748,7 @@ class Client: ) return rtn - def fetchUnread(self): + def fetch_unread(self): """Fetch unread threads. Returns: @@ -768,7 +768,7 @@ class Client: result = j["unread_thread_fbids"][0] return result["thread_fbids"] + result["other_user_fbids"] - def fetchUnseen(self): + def fetch_unseen(self): """Fetch unseen / new threads. Returns: @@ -782,7 +782,7 @@ class Client: result = j["unseen_thread_fbids"][0] return result["thread_fbids"] + result["other_user_fbids"] - def fetchImageUrl(self, image_id): + def fetch_image_url(self, image_id): """Fetch URL to download the original image from an image attachment ID. Args: @@ -804,7 +804,7 @@ class Client: raise FBchatException("Could not fetch image URL from: {}".format(j)) return url - def fetchMessageInfo(self, mid, thread_id=None): + def fetch_message_info(self, mid, thread_id=None): """Fetch `Message` object from the given message id. Args: @@ -817,10 +817,10 @@ class Client: Raises: FBchatException: If request failed """ - message_info = self._forcedFetch(thread_id, mid).get("message") + message_info = self._forced_fetch(thread_id, mid).get("message") return Message._from_graphql(message_info) - def fetchPollOptions(self, poll_id): + def fetch_poll_options(self, poll_id): """Fetch list of `PollOption` objects from the poll id. Args: @@ -836,7 +836,7 @@ class Client: j = self._payload_post("/ajax/mercury/get_poll_options", data) return [PollOption._from_graphql(m) for m in j] - def fetchPlanInfo(self, plan_id): + def fetch_plan_info(self, plan_id): """Fetch `Plan` object from the plan id. Args: @@ -852,31 +852,31 @@ class Client: j = self._payload_post("/ajax/eventreminder", data) return Plan._from_fetch(j) - def _getPrivateData(self): + def _get_private_data(self): j, = self.graphql_requests(_graphql.from_doc_id("1868889766468115", {})) return j["viewer"] - def getPhoneNumbers(self): + def get_phone_numbers(self): """Fetch list of user's phone numbers. Returns: list: List of phone numbers """ - data = self._getPrivateData() + data = self._get_private_data() return [ j["phone_number"]["universal_number"] for j in data["user"]["all_phones"] ] - def getEmails(self): + def get_emails(self): """Fetch list of user's emails. Returns: list: List of emails """ - data = self._getPrivateData() + data = self._get_private_data() return [j["display_email"] for j in data["all_emails"]] - def getUserActiveStatus(self, user_id): + def get_user_active_status(self, user_id): """Fetch friend active status as an `ActiveStatus` object. Return ``None`` if status isn't known. @@ -892,7 +892,7 @@ class Client: """ return self._buddylist.get(str(user_id)) - def fetchThreadImages(self, thread_id=None): + def fetch_thread_images(self, thread_id=None): """Fetch images posted in thread. Args: @@ -937,10 +937,10 @@ class Client: SEND METHODS """ - def _oldMessage(self, message): + def _old_message(self, message): return message if isinstance(message, Message) else Message(text=message) - def _doSendRequest(self, data, get_thread_id=False): + def _do_send_request(self, data, get_thread_id=False): """Send the data to `SendURL`, and returns the message ID or None on failure.""" mid, thread_id = self._state._do_send_request(data) if get_thread_id: @@ -965,7 +965,7 @@ class Client: thread = thread_type._to_class()(thread_id) data = thread._to_send_data() data.update(message._to_send_data()) - return self._doSendRequest(data) + return self._do_send_request(data) def wave(self, wave_first=True, thread_id=None, thread_type=None): """Wave hello to a thread. @@ -990,9 +990,9 @@ class Client: data["lightweight_action_attachment[lwa_type]"] = "WAVE" if thread_type == ThreadType.USER: data["specific_to_list[0]"] = "fbid:{}".format(thread_id) - return self._doSendRequest(data) + return self._do_send_request(data) - def quickReply(self, quick_reply, payload=None, thread_id=None, thread_type=None): + def quick_reply(self, quick_reply, payload=None, thread_id=None, thread_type=None): """Reply to chosen quick reply. Args: @@ -1017,18 +1017,18 @@ class Client: raise TypeError( "Payload must be an instance of `fbchat.LocationAttachment`" ) - return self.sendLocation( + return self.send_location( payload, thread_id=thread_id, thread_type=thread_type ) elif isinstance(quick_reply, QuickReplyEmail): if not payload: - payload = self.getEmails()[0] + payload = self.get_emails()[0] quick_reply.external_payload = quick_reply.payload quick_reply.payload = payload return self.send(Message(text=payload, quick_replies=[quick_reply])) elif isinstance(quick_reply, QuickReplyPhoneNumber): if not payload: - payload = self.getPhoneNumbers()[0] + payload = self.get_phone_numbers()[0] quick_reply.external_payload = quick_reply.payload quick_reply.payload = payload return self.send(Message(text=payload, quick_replies=[quick_reply])) @@ -1042,7 +1042,7 @@ class Client: data = {"message_id": mid} j = self._payload_post("/messaging/unsend_message/?dpr=1", data) - def _sendLocation( + def _send_location( self, location, current=True, message=None, thread_id=None, thread_type=None ): thread = thread_type._to_class()(thread_id) @@ -1053,9 +1053,9 @@ class Client: data["location_attachment[coordinates][latitude]"] = location.latitude data["location_attachment[coordinates][longitude]"] = location.longitude data["location_attachment[is_current_location]"] = current - return self._doSendRequest(data) + return self._do_send_request(data) - def sendLocation(self, location, message=None, thread_id=None, thread_type=None): + def send_location(self, location, message=None, thread_id=None, thread_type=None): """Send a given location to a thread as the user's current location. Args: @@ -1070,7 +1070,7 @@ class Client: Raises: FBchatException: If request failed """ - self._sendLocation( + self._send_location( location=location, current=True, message=message, @@ -1078,7 +1078,7 @@ class Client: thread_type=thread_type, ) - def sendPinnedLocation( + def send_pinned_location( self, location, message=None, thread_id=None, thread_type=None ): """Send a given location to a thread as a pinned location. @@ -1095,7 +1095,7 @@ class Client: Raises: FBchatException: If request failed """ - self._sendLocation( + self._send_location( location=location, current=False, message=message, @@ -1106,7 +1106,7 @@ class Client: def _upload(self, files, voice_clip=False): return self._state._upload(files, voice_clip=voice_clip) - def _sendFiles( + def _send_files( self, files, message=None, thread_id=None, thread_type=ThreadType.USER ): """Send files from file IDs to a thread. @@ -1115,16 +1115,16 @@ class Client: """ thread = thread_type._to_class()(thread_id) data = thread._to_send_data() - data.update(self._oldMessage(message)._to_send_data()) + data.update(self._old_message(message)._to_send_data()) data["action_type"] = "ma-type:user-generated-message" data["has_attachment"] = True for i, (file_id, mimetype) in enumerate(files): data["{}s[{}]".format(_util.mimetype_to_key(mimetype), i)] = file_id - return self._doSendRequest(data) + return self._do_send_request(data) - def sendRemoteFiles( + def send_remote_files( self, file_urls, message=None, thread_id=None, thread_type=ThreadType.USER ): """Send files from URLs to a thread. @@ -1143,11 +1143,11 @@ class Client: """ file_urls = _util.require_list(file_urls) files = self._upload(_util.get_files_from_urls(file_urls)) - return self._sendFiles( + return self._send_files( files=files, message=message, thread_id=thread_id, thread_type=thread_type ) - def sendLocalFiles( + def send_local_files( self, file_paths, message=None, thread_id=None, thread_type=ThreadType.USER ): """Send local files to a thread. @@ -1167,11 +1167,11 @@ class Client: file_paths = _util.require_list(file_paths) with _util.get_files_from_paths(file_paths) as x: files = self._upload(x) - return self._sendFiles( + return self._send_files( files=files, message=message, thread_id=thread_id, thread_type=thread_type ) - def sendRemoteVoiceClips( + def send_remote_voice_clips( self, clip_urls, message=None, thread_id=None, thread_type=ThreadType.USER ): """Send voice clips from URLs to a thread. @@ -1190,11 +1190,11 @@ class Client: """ clip_urls = _util.require_list(clip_urls) files = self._upload(_util.get_files_from_urls(clip_urls), voice_clip=True) - return self._sendFiles( + return self._send_files( files=files, message=message, thread_id=thread_id, thread_type=thread_type ) - def sendLocalVoiceClips( + def send_local_voice_clips( self, clip_paths, message=None, thread_id=None, thread_type=ThreadType.USER ): """Send local voice clips to a thread. @@ -1214,11 +1214,11 @@ class Client: clip_paths = _util.require_list(clip_paths) with _util.get_files_from_paths(clip_paths) as x: files = self._upload(x, voice_clip=True) - return self._sendFiles( + return self._send_files( files=files, message=message, thread_id=thread_id, thread_type=thread_type ) - def forwardAttachment(self, attachment_id, thread_id=None): + def forward_attachment(self, attachment_id, thread_id=None): """Forward an attachment. Args: @@ -1230,7 +1230,9 @@ class Client: """ data = { "attachment_id": attachment_id, - "recipient_map[{}]".format(_util.generateOfflineThreadingID()): thread_id, + "recipient_map[{}]".format( + _util.generate_offline_threading_id() + ): thread_id, } j = self._payload_post("/mercury/attachments/forward/", data) if not j.get("success"): @@ -1239,7 +1241,7 @@ class Client: fb_error_message=j["error"], ) - def createGroup(self, message, user_ids): + def create_group(self, message, user_ids): """Create a group with the given user ids. Args: @@ -1252,7 +1254,7 @@ class Client: Raises: FBchatException: If request failed """ - data = self._oldMessage(message)._to_send_data() + data = self._old_message(message)._to_send_data() if len(user_ids) < 2: raise ValueError("Error when creating group: Not enough participants") @@ -1260,14 +1262,14 @@ class Client: for i, user_id in enumerate(user_ids + [self._uid]): data["specific_to_list[{}]".format(i)] = "fbid:{}".format(user_id) - message_id, thread_id = self._doSendRequest(data, get_thread_id=True) + message_id, thread_id = self._do_send_request(data, get_thread_id=True) if not thread_id: raise FBchatException( "Error when creating group: No thread_id could be found" ) return thread_id - def addUsersToGroup(self, user_ids, thread_id=None): + def add_users_to_group(self, user_ids, thread_id=None): """Add users to a group. Args: @@ -1294,9 +1296,9 @@ class Client: "log_message_data[added_participants][{}]".format(i) ] = "fbid:{}".format(user_id) - return self._doSendRequest(data) + return self._do_send_request(data) - def removeUserFromGroup(self, user_id, thread_id=None): + def remove_user_from_group(self, user_id, thread_id=None): """Remove user from a group. Args: @@ -1309,7 +1311,7 @@ class Client: data = {"uid": user_id, "tid": thread_id} j = self._payload_post("/chat/remove_participants/", data) - def _adminStatus(self, admin_ids, admin, thread_id=None): + def _admin_status(self, admin_ids, admin, thread_id=None): data = {"add": admin, "thread_fbid": thread_id} admin_ids = _util.require_list(admin_ids) @@ -1319,7 +1321,7 @@ class Client: j = self._payload_post("/messaging/save_admins/?dpr=1", data) - def addGroupAdmins(self, admin_ids, thread_id=None): + def add_group_admins(self, admin_ids, thread_id=None): """Set specified users as group admins. Args: @@ -1329,9 +1331,9 @@ class Client: Raises: FBchatException: If request failed """ - self._adminStatus(admin_ids, True, thread_id) + self._admin_status(admin_ids, True, thread_id) - def removeGroupAdmins(self, admin_ids, thread_id=None): + def remove_group_admins(self, admin_ids, thread_id=None): """Remove admin status from specified users. Args: @@ -1341,9 +1343,9 @@ class Client: Raises: FBchatException: If request failed """ - self._adminStatus(admin_ids, False, thread_id) + self._admin_status(admin_ids, False, thread_id) - def changeGroupApprovalMode(self, require_admin_approval, thread_id=None): + def change_group_approval_mode(self, require_admin_approval, thread_id=None): """Change group's approval mode. Args: @@ -1356,7 +1358,7 @@ class Client: data = {"set_mode": int(require_admin_approval), "thread_fbid": thread_id} j = self._payload_post("/messaging/set_approval_mode/?dpr=1", data) - def _usersApproval(self, user_ids, approve, thread_id=None): + def _users_approval(self, user_ids, approve, thread_id=None): user_ids = _util.require_list(user_ids) data = { @@ -1371,7 +1373,7 @@ class Client: _graphql.from_doc_id("1574519202665847", {"data": data}) ) - def acceptUsersToGroup(self, user_ids, thread_id=None): + def accept_users_to_group(self, user_ids, thread_id=None): """Accept users to the group from the group's approval. Args: @@ -1381,9 +1383,9 @@ class Client: Raises: FBchatException: If request failed """ - self._usersApproval(user_ids, True, thread_id) + self._users_approval(user_ids, True, thread_id) - def denyUsersFromGroup(self, user_ids, thread_id=None): + def deny_users_from_group(self, user_ids, thread_id=None): """Deny users from joining the group. Args: @@ -1393,9 +1395,9 @@ class Client: Raises: FBchatException: If request failed """ - self._usersApproval(user_ids, False, thread_id) + self._users_approval(user_ids, False, thread_id) - def _changeGroupImage(self, image_id, thread_id=None): + def _change_group_image(self, image_id, thread_id=None): """Change a thread image from an image id. Args: @@ -1410,7 +1412,7 @@ class Client: j = self._payload_post("/messaging/set_thread_image/?dpr=1", data) return image_id - def changeGroupImageRemote(self, image_url, thread_id=None): + def change_group_image_remote(self, image_url, thread_id=None): """Change a thread image from a URL. Args: @@ -1421,9 +1423,9 @@ class Client: FBchatException: If request failed """ (image_id, mimetype), = self._upload(_util.get_files_from_urls([image_url])) - return self._changeGroupImage(image_id, thread_id) + return self._change_group_image(image_id, thread_id) - def changeGroupImageLocal(self, image_path, thread_id=None): + def change_group_image_local(self, image_path, thread_id=None): """Change a thread image from a local path. Args: @@ -1436,9 +1438,9 @@ class Client: with _util.get_files_from_paths([image_path]) as files: (image_id, mimetype), = self._upload(files) - return self._changeGroupImage(image_id, thread_id) + return self._change_group_image(image_id, thread_id) - def changeThreadTitle(self, title, thread_id=None, thread_type=ThreadType.USER): + def change_thread_title(self, title, thread_id=None, thread_type=ThreadType.USER): """Change title of a thread. If this is executed on a user thread, this will change the nickname of that @@ -1454,14 +1456,14 @@ class Client: """ if thread_type == ThreadType.USER: # The thread is a user, so we change the user's nickname - return self.changeNickname( + return self.change_nickname( title, thread_id, thread_id=thread_id, thread_type=thread_type ) data = {"thread_name": title, "thread_id": thread_id} j = self._payload_post("/messaging/set_thread_name/?dpr=1", data) - def changeNickname( + def change_nickname( self, nickname, user_id, thread_id=None, thread_type=ThreadType.USER ): """Change the nickname of a user in a thread. @@ -1484,7 +1486,7 @@ class Client: "/messaging/save_thread_nickname/?source=thread_settings&dpr=1", data ) - def changeThreadColor(self, color, thread_id=None): + def change_thread_color(self, color, thread_id=None): """Change thread color. Args: @@ -1502,7 +1504,7 @@ class Client: "/messaging/save_thread_color/?source=thread_settings&dpr=1", data ) - def changeThreadEmoji(self, emoji, thread_id=None): + def change_thread_emoji(self, emoji, thread_id=None): """Change thread color. Note: @@ -1521,7 +1523,7 @@ class Client: "/messaging/save_thread_emoji/?source=thread_settings&dpr=1", data ) - def reactToMessage(self, message_id, reaction): + def react_to_message(self, message_id, reaction): """React to a message, or removes reaction. Args: @@ -1542,7 +1544,7 @@ class Client: j = self._payload_post("/webgraphql/mutation", data) _util.handle_graphql_errors(j) - def createPlan(self, plan, thread_id=None): + def create_plan(self, plan, thread_id=None): """Set a plan. Args: @@ -1568,7 +1570,7 @@ class Client: fb_error_message=j["error"], ) - def editPlan(self, plan, new_plan): + def edit_plan(self, plan, new_plan): """Edit a plan. Args: @@ -1589,7 +1591,7 @@ class Client: } j = self._payload_post("/ajax/eventreminder/submit", data) - def deletePlan(self, plan): + def delete_plan(self, plan): """Delete a plan. Args: @@ -1601,7 +1603,7 @@ class Client: data = {"event_reminder_id": plan.uid, "delete": "true", "acontext": ACONTEXT} j = self._payload_post("/ajax/eventreminder/submit", data) - def changePlanParticipation(self, plan, take_part=True): + def change_plan_participation(self, plan, take_part=True): """Change participation in a plan. Args: @@ -1618,7 +1620,7 @@ class Client: } j = self._payload_post("/ajax/eventreminder/rsvp", data) - def createPoll(self, poll, thread_id=None): + def create_poll(self, poll, thread_id=None): """Create poll in a group thread. Args: @@ -1645,7 +1647,7 @@ class Client: fb_error_message=j.get("errorMessage"), ) - def updatePollVote(self, poll_id, option_ids=[], new_options=[]): + def update_poll_vote(self, poll_id, option_ids=[], new_options=[]): """Update a poll vote. Args: @@ -1673,7 +1675,7 @@ class Client: fb_error_message=j.get("errorMessage"), ) - def setTypingStatus(self, status, thread_id=None, thread_type=None): + def set_typing_status(self, status, thread_id=None, thread_type=None): """Set users typing status in a thread. Args: @@ -1696,7 +1698,7 @@ class Client: END SEND METHODS """ - def markAsDelivered(self, thread_id, message_id): + def mark_as_delivered(self, thread_id, message_id): """Mark a message as delivered. Args: @@ -1717,7 +1719,7 @@ class Client: j = self._payload_post("/ajax/mercury/delivery_receipts.php", data) return True - def _readStatus(self, read, thread_ids): + def _read_status(self, read, thread_ids): thread_ids = _util.require_list(thread_ids) data = {"watermarkTimestamp": _util.now(), "shouldSendReadReceipt": "true"} @@ -1727,7 +1729,7 @@ class Client: j = self._payload_post("/ajax/mercury/change_read_status.php", data) - def markAsRead(self, thread_ids=None): + def mark_as_read(self, thread_ids=None): """Mark threads as read. All messages inside the specified threads will be marked as read. @@ -1738,9 +1740,9 @@ class Client: Raises: FBchatException: If request failed """ - self._readStatus(True, thread_ids) + self._read_status(True, thread_ids) - def markAsUnread(self, thread_ids=None): + def mark_as_unread(self, thread_ids=None): """Mark threads as unread. All messages inside the specified threads will be marked as unread. @@ -1751,9 +1753,9 @@ class Client: Raises: FBchatException: If request failed """ - self._readStatus(False, thread_ids) + self._read_status(False, thread_ids) - def markAsSeen(self): + def mark_as_seen(self): """ Todo: Documenting this @@ -1762,7 +1764,7 @@ class Client: "/ajax/mercury/mark_seen.php", {"seen_timestamp": _util.now()} ) - def friendConnect(self, friend_id): + def friend_connect(self, friend_id): """ Todo: Documenting this @@ -1771,7 +1773,7 @@ class Client: j = self._payload_post("/ajax/add_friend/action.php?dpr=1", data) - def removeFriend(self, friend_id=None): + def remove_friend(self, friend_id=None): """Remove a specified friend from the client's friend list. Args: @@ -1787,7 +1789,7 @@ class Client: j = self._payload_post("/ajax/profile/removefriendconfirm.php", data) return True - def blockUser(self, user_id): + def block_user(self, user_id): """Block messages from a specified user. Args: @@ -1803,7 +1805,7 @@ class Client: j = self._payload_post("/messaging/block_messages/?dpr=1", data) return True - def unblockUser(self, user_id): + def unblock_user(self, user_id): """Unblock a previously blocked user. Args: @@ -1819,7 +1821,7 @@ class Client: j = self._payload_post("/messaging/unblock_messages/?dpr=1", data) return True - def moveThreads(self, location, thread_ids): + def move_threads(self, location, thread_ids): """Move threads to specified location. Args: @@ -1856,7 +1858,7 @@ class Client: j = self._payload_post("/ajax/mercury/move_thread.php", data) return True - def deleteThreads(self, thread_ids): + def delete_threads(self, thread_ids): """Delete threads. Args: @@ -1883,7 +1885,7 @@ class Client: ) return True - def markAsSpam(self, thread_id=None): + def mark_as_spam(self, thread_id=None): """Mark a thread as spam, and delete it. Args: @@ -1898,7 +1900,7 @@ class Client: j = self._payload_post("/ajax/mercury/mark_spam.php?dpr=1", {"id": thread_id}) return True - def deleteMessages(self, message_ids): + def delete_messages(self, message_ids): """Delete specified messages. Args: @@ -1917,7 +1919,7 @@ class Client: j = self._payload_post("/ajax/mercury/delete_messages.php?dpr=1", data) return True - def muteThread(self, mute_time=None, thread_id=None): + def mute_thread(self, mute_time=None, thread_id=None): """Mute thread. Args: @@ -1931,15 +1933,15 @@ class Client: data = {"mute_settings": str(mute_settings), "thread_fbid": thread_id} j = self._payload_post("/ajax/mercury/change_mute_thread.php?dpr=1", data) - def unmuteThread(self, thread_id=None): + def unmute_thread(self, thread_id=None): """Unmute thread. Args: thread_id: User/Group ID to unmute. See :ref:`intro_threads` """ - return self.muteThread(datetime.timedelta(0), thread_id) + return self.mute_thread(datetime.timedelta(0), thread_id) - def muteThreadReactions(self, mute=True, thread_id=None): + def mute_thread_reactions(self, mute=True, thread_id=None): """Mute thread reactions. Args: @@ -1951,15 +1953,15 @@ class Client: "/ajax/mercury/change_reactions_mute_thread/?dpr=1", data ) - def unmuteThreadReactions(self, thread_id=None): + def unmute_thread_reactions(self, thread_id=None): """Unmute thread reactions. Args: thread_id: User/Group ID to unmute. See :ref:`intro_threads` """ - return self.muteThreadReactions(False, thread_id) + return self.mute_thread_reactions(False, thread_id) - def muteThreadMentions(self, mute=True, thread_id=None): + def mute_thread_mentions(self, mute=True, thread_id=None): """Mute thread mentions. Args: @@ -1969,13 +1971,13 @@ class Client: data = {"mentions_mute_mode": int(mute), "thread_fbid": thread_id} j = self._payload_post("/ajax/mercury/change_mentions_mute_thread/?dpr=1", data) - def unmuteThreadMentions(self, thread_id=None): + def unmute_thread_mentions(self, thread_id=None): """Unmute thread mentions. Args: thread_id: User/Group ID to unmute. See :ref:`intro_threads` """ - return self.muteThreadMentions(False, thread_id) + return self.mute_thread_mentions(False, thread_id) """ LISTEN METHODS @@ -2000,7 +2002,7 @@ class Client: ) _util.handle_payload_error(j) - def _pullMessage(self): + def _pull_message(self): """Call pull api to fetch message data.""" data = { "seq": self._seq, @@ -2008,7 +2010,7 @@ class Client: "sticky_token": self._sticky, "sticky_pool": self._pool, "clientid": self._state._client_id, - "state": "active" if self._markAlive else "offline", + "state": "active" if self._mark_alive else "offline", } j = self._get( "https://{}-edge-chat.facebook.com/pull".format(self._pull_channel), data @@ -2016,8 +2018,8 @@ class Client: _util.handle_payload_error(j) return j - def _parseDelta(self, m): - def getThreadIdAndThreadType(msg_metadata): + def _parse_delta(self, m): + def get_thread_id_and_thread_type(msg_metadata): """Return a tuple consisting of thread ID and thread type.""" id_thread = None type_thread = None @@ -2043,7 +2045,7 @@ class Client: if "addedParticipants" in delta: added_ids = [str(x["userFbId"]) for x in delta["addedParticipants"]] thread_id = str(metadata["threadKey"]["threadFbId"]) - self.onPeopleAdded( + self.on_people_added( mid=mid, added_ids=added_ids, author_id=author_id, @@ -2056,7 +2058,7 @@ class Client: elif "leftParticipantFbId" in delta: removed_id = str(delta["leftParticipantFbId"]) thread_id = str(metadata["threadKey"]["threadFbId"]) - self.onPersonRemoved( + self.on_person_removed( mid=mid, removed_id=removed_id, author_id=author_id, @@ -2068,8 +2070,8 @@ class Client: # Color change elif delta_type == "change_thread_theme": new_color = ThreadColor._from_graphql(delta["untypedData"]["theme_color"]) - thread_id, thread_type = getThreadIdAndThreadType(metadata) - self.onColorChange( + thread_id, thread_type = get_thread_id_and_thread_type(metadata) + self.on_color_change( mid=mid, author_id=author_id, new_color=new_color, @@ -2083,8 +2085,8 @@ class Client: # Emoji change elif delta_type == "change_thread_icon": new_emoji = delta["untypedData"]["thread_icon"] - thread_id, thread_type = getThreadIdAndThreadType(metadata) - self.onEmojiChange( + thread_id, thread_type = get_thread_id_and_thread_type(metadata) + self.on_emoji_change( mid=mid, author_id=author_id, new_emoji=new_emoji, @@ -2098,8 +2100,8 @@ class Client: # Thread title change elif delta_class == "ThreadName": new_title = delta["name"] - thread_id, thread_type = getThreadIdAndThreadType(metadata) - self.onTitleChange( + thread_id, thread_type = get_thread_id_and_thread_type(metadata) + self.on_title_change( mid=mid, author_id=author_id, new_title=new_title, @@ -2114,10 +2116,10 @@ class Client: elif delta_class == "ForcedFetch": mid = delta.get("messageId") if mid is None: - self.onUnknownMesssageType(msg=m) + self.on_unknown_messsage_type(msg=m) else: thread_id = str(delta["threadKey"]["threadFbId"]) - fetch_info = self._forcedFetch(thread_id, mid) + fetch_info = self._forced_fetch(thread_id, mid) fetch_data = fetch_info["message"] author_id = fetch_data["message_sender"]["id"] at = _util.millis_to_datetime(int(fetch_data["timestamp_precise"])) @@ -2129,7 +2131,7 @@ class Client: if image_metadata else None ) - self.onImageChange( + self.on_image_change( mid=mid, author_id=author_id, new_image=image_id, @@ -2143,8 +2145,8 @@ class Client: elif delta_type == "change_thread_nickname": changed_for = str(delta["untypedData"]["participant_id"]) new_nickname = delta["untypedData"]["nickname"] - thread_id, thread_type = getThreadIdAndThreadType(metadata) - self.onNicknameChange( + thread_id, thread_type = get_thread_id_and_thread_type(metadata) + self.on_nickname_change( mid=mid, author_id=author_id, changed_for=changed_for, @@ -2158,11 +2160,11 @@ class Client: # Admin added or removed in a group thread elif delta_type == "change_thread_admins": - thread_id, thread_type = getThreadIdAndThreadType(metadata) + thread_id, thread_type = get_thread_id_and_thread_type(metadata) target_id = delta["untypedData"]["TARGET_ID"] admin_event = delta["untypedData"]["ADMIN_EVENT"] if admin_event == "add_admin": - self.onAdminAdded( + self.on_admin_added( mid=mid, added_id=target_id, author_id=author_id, @@ -2172,7 +2174,7 @@ class Client: msg=m, ) elif admin_event == "remove_admin": - self.onAdminRemoved( + self.on_admin_removed( mid=mid, removed_id=target_id, author_id=author_id, @@ -2184,9 +2186,9 @@ class Client: # Group approval mode change elif delta_type == "change_thread_approval_mode": - thread_id, thread_type = getThreadIdAndThreadType(metadata) + thread_id, thread_type = get_thread_id_and_thread_type(metadata) approval_mode = bool(int(delta["untypedData"]["APPROVAL_MODE"])) - self.onApprovalModeChange( + self.on_approval_mode_change( mid=mid, approval_mode=approval_mode, author_id=author_id, @@ -2203,8 +2205,8 @@ class Client: delta.get("actorFbId") or delta["threadKey"]["otherUserFbId"] ) at = _util.millis_to_datetime(int(delta["deliveredWatermarkTimestampMs"])) - thread_id, thread_type = getThreadIdAndThreadType(delta) - self.onMessageDelivered( + thread_id, thread_type = get_thread_id_and_thread_type(delta) + self.on_message_delivered( msg_ids=message_ids, delivered_for=delivered_for, thread_id=thread_id, @@ -2219,8 +2221,8 @@ class Client: seen_by = str(delta.get("actorFbId") or delta["threadKey"]["otherUserFbId"]) seen_at = _util.millis_to_datetime(int(delta["actionTimestampMs"])) at = _util.millis_to_datetime(int(delta["watermarkTimestampMs"])) - thread_id, thread_type = getThreadIdAndThreadType(delta) - self.onMessageSeen( + thread_id, thread_type = get_thread_id_and_thread_type(delta) + self.on_message_seen( seen_by=seen_by, thread_id=thread_id, thread_type=thread_type, @@ -2243,12 +2245,12 @@ class Client: threads = [] if "folders" not in delta: threads = [ - getThreadIdAndThreadType({"threadKey": thr}) + get_thread_id_and_thread_type({"threadKey": thr}) for thr in delta.get("threadKeys") ] - # thread_id, thread_type = getThreadIdAndThreadType(delta) - self.onMarkedSeen( + # thread_id, thread_type = get_thread_id_and_thread_type(delta) + self.on_marked_seen( threads=threads, seen_at=seen_at, at=at, metadata=delta, msg=m ) @@ -2262,8 +2264,8 @@ class Client: leaderboard = delta["untypedData"].get("leaderboard") if leaderboard is not None: leaderboard = json.loads(leaderboard)["scores"] - thread_id, thread_type = getThreadIdAndThreadType(metadata) - self.onGamePlayed( + thread_id, thread_type = get_thread_id_and_thread_type(metadata) + self.on_game_played( mid=mid, author_id=author_id, game_id=game_id, @@ -2279,14 +2281,14 @@ class Client: # Group call started/ended elif delta_type == "rtc_call_log": - thread_id, thread_type = getThreadIdAndThreadType(metadata) + thread_id, thread_type = get_thread_id_and_thread_type(metadata) call_status = delta["untypedData"]["event"] call_duration = _util.seconds_to_timedelta( int(delta["untypedData"]["call_duration"]) ) is_video_call = bool(int(delta["untypedData"]["is_video_call"])) if call_status == "call_started": - self.onCallStarted( + self.on_call_started( mid=mid, caller_id=author_id, is_video_call=is_video_call, @@ -2297,7 +2299,7 @@ class Client: msg=m, ) elif call_status == "call_ended": - self.onCallEnded( + self.on_call_ended( mid=mid, caller_id=author_id, is_video_call=is_video_call, @@ -2311,9 +2313,9 @@ class Client: # User joined to group call elif delta_type == "participant_joined_group_call": - thread_id, thread_type = getThreadIdAndThreadType(metadata) + thread_id, thread_type = get_thread_id_and_thread_type(metadata) is_video_call = bool(int(delta["untypedData"]["group_call_type"])) - self.onUserJoinedCall( + self.on_user_joined_call( mid=mid, joined_id=author_id, is_video_call=is_video_call, @@ -2326,13 +2328,13 @@ class Client: # Group poll event elif delta_type == "group_poll": - thread_id, thread_type = getThreadIdAndThreadType(metadata) + thread_id, thread_type = get_thread_id_and_thread_type(metadata) event_type = delta["untypedData"]["event_type"] poll_json = json.loads(delta["untypedData"]["question_json"]) poll = Poll._from_graphql(poll_json) if event_type == "question_creation": # User created group poll - self.onPollCreated( + self.on_poll_created( mid=mid, poll=poll, author_id=author_id, @@ -2346,7 +2348,7 @@ class Client: # User voted on group poll added_options = json.loads(delta["untypedData"]["added_option_ids"]) removed_options = json.loads(delta["untypedData"]["removed_option_ids"]) - self.onPollVoted( + self.on_poll_voted( mid=mid, poll=poll, added_options=added_options, @@ -2361,8 +2363,8 @@ class Client: # Plan created elif delta_type == "lightweight_event_create": - thread_id, thread_type = getThreadIdAndThreadType(metadata) - self.onPlanCreated( + thread_id, thread_type = get_thread_id_and_thread_type(metadata) + self.on_plan_created( mid=mid, plan=Plan._from_pull(delta["untypedData"]), author_id=author_id, @@ -2375,8 +2377,8 @@ class Client: # Plan ended elif delta_type == "lightweight_event_notify": - thread_id, thread_type = getThreadIdAndThreadType(metadata) - self.onPlanEnded( + thread_id, thread_type = get_thread_id_and_thread_type(metadata) + self.on_plan_ended( mid=mid, plan=Plan._from_pull(delta["untypedData"]), thread_id=thread_id, @@ -2388,8 +2390,8 @@ class Client: # Plan edited elif delta_type == "lightweight_event_update": - thread_id, thread_type = getThreadIdAndThreadType(metadata) - self.onPlanEdited( + thread_id, thread_type = get_thread_id_and_thread_type(metadata) + self.on_plan_edited( mid=mid, plan=Plan._from_pull(delta["untypedData"]), author_id=author_id, @@ -2402,8 +2404,8 @@ class Client: # Plan deleted elif delta_type == "lightweight_event_delete": - thread_id, thread_type = getThreadIdAndThreadType(metadata) - self.onPlanDeleted( + thread_id, thread_type = get_thread_id_and_thread_type(metadata) + self.on_plan_deleted( mid=mid, plan=Plan._from_pull(delta["untypedData"]), author_id=author_id, @@ -2416,9 +2418,9 @@ class Client: # Plan participation change elif delta_type == "lightweight_event_rsvp": - thread_id, thread_type = getThreadIdAndThreadType(metadata) + thread_id, thread_type = get_thread_id_and_thread_type(metadata) take_part = delta["untypedData"]["guest_status"] == "GOING" - self.onPlanParticipation( + self.on_plan_participation( mid=mid, plan=Plan._from_pull(delta["untypedData"]), take_part=take_part, @@ -2439,7 +2441,7 @@ class Client: # Message reaction if d.get("deltaMessageReaction"): i = d["deltaMessageReaction"] - thread_id, thread_type = getThreadIdAndThreadType(i) + thread_id, thread_type = get_thread_id_and_thread_type(i) mid = i["messageId"] author_id = str(i["userId"]) reaction = ( @@ -2447,7 +2449,7 @@ class Client: ) add_reaction = not bool(i["action"]) if add_reaction: - self.onReactionAdded( + self.on_reaction_added( mid=mid, reaction=reaction, author_id=author_id, @@ -2457,7 +2459,7 @@ class Client: msg=m, ) else: - self.onReactionRemoved( + self.on_reaction_removed( mid=mid, author_id=author_id, thread_id=thread_id, @@ -2469,13 +2471,13 @@ class Client: # Viewer status change elif d.get("deltaChangeViewerStatus"): i = d["deltaChangeViewerStatus"] - thread_id, thread_type = getThreadIdAndThreadType(i) + thread_id, thread_type = get_thread_id_and_thread_type(i) author_id = str(i["actorFbid"]) reason = i["reason"] can_reply = i["canViewerReply"] if reason == 2: if can_reply: - self.onUnblock( + self.on_unblock( author_id=author_id, thread_id=thread_id, thread_type=thread_type, @@ -2483,7 +2485,7 @@ class Client: msg=m, ) else: - self.onBlock( + self.on_block( author_id=author_id, thread_id=thread_id, thread_type=thread_type, @@ -2494,12 +2496,12 @@ class Client: # Live location info elif d.get("liveLocationData"): i = d["liveLocationData"] - thread_id, thread_type = getThreadIdAndThreadType(i) + thread_id, thread_type = get_thread_id_and_thread_type(i) for l in i["messageLiveLocations"]: mid = l["messageId"] author_id = str(l["senderId"]) location = LiveLocationAttachment._from_pull(l) - self.onLiveLocation( + self.on_live_location( mid=mid, location=location, author_id=author_id, @@ -2512,11 +2514,11 @@ class Client: # Message deletion elif d.get("deltaRecallMessageData"): i = d["deltaRecallMessageData"] - thread_id, thread_type = getThreadIdAndThreadType(i) + thread_id, thread_type = get_thread_id_and_thread_type(i) mid = i["messageID"] at = _util.millis_to_datetime(i["deletionTimestamp"]) author_id = str(i["senderID"]) - self.onMessageUnsent( + self.on_message_unsent( mid=mid, author_id=author_id, thread_id=thread_id, @@ -2528,11 +2530,11 @@ class Client: elif d.get("deltaMessageReply"): i = d["deltaMessageReply"] metadata = i["message"]["messageMetadata"] - thread_id, thread_type = getThreadIdAndThreadType(metadata) + thread_id, thread_type = get_thread_id_and_thread_type(metadata) message = Message._from_reply(i["message"]) message.replied_to = Message._from_reply(i["repliedToMessage"]) message.reply_to_id = message.replied_to.uid - self.onMessage( + self.on_message( mid=message.uid, author_id=message.author, message_object=message, @@ -2545,8 +2547,8 @@ class Client: # New message elif delta.get("class") == "NewMessage": - thread_id, thread_type = getThreadIdAndThreadType(metadata) - self.onMessage( + thread_id, thread_type = get_thread_id_and_thread_type(metadata) + self.on_message( mid=mid, author_id=author_id, message_object=Message._from_pull( @@ -2565,9 +2567,9 @@ class Client: # Unknown message type else: - self.onUnknownMesssageType(msg=m) + self.on_unknown_messsage_type(msg=m) - def _parseMessage(self, content): + def _parse_message(self, content): """Get message and author name from content. May contain multiple messages in the content. @@ -2580,7 +2582,7 @@ class Client: if "batches" in content: for batch in content["batches"]: - self._parseMessage(batch) + self._parse_message(batch) if "ms" not in content: return @@ -2590,10 +2592,10 @@ class Client: try: # Things that directly change chat if mtype == "delta": - self._parseDelta(m) + self._parse_delta(m) # Inbox elif mtype == "inbox": - self.onInbox( + self.on_inbox( unseen=m["unseen"], unread=m["unread"], recent_unread=m["recent_unread"], @@ -2614,7 +2616,7 @@ class Client: else: thread_id = author_id typing_status = TypingStatus(m.get("st")) - self.onTyping( + self.on_typing( author_id=author_id, status=typing_status, thread_id=thread_id, @@ -2627,15 +2629,15 @@ class Client: # Seen # elif mtype == "m_read_receipt": # - # self.onSeen(m.get('realtime_viewer_fbid'), m.get('reader'), m.get('time')) + # self.on_seen(m.get('realtime_viewer_fbid'), m.get('reader'), m.get('time')) elif mtype in ["jewel_requests_add"]: from_id = m["from"] - self.onFriendRequest(from_id=from_id, msg=m) + self.on_friend_request(from_id=from_id, msg=m) # Happens on every login elif mtype == "qprimer": - self.onQprimer( + self.on_qprimer( at=_util.millis_to_datetime(int(m.get("made"))), msg=m ) @@ -2650,7 +2652,7 @@ class Client: statuses[id_] = ActiveStatus._from_chatproxy_presence(id_, data) self._buddylist[id_] = statuses[id_] - self.onChatTimestamp(buddylist=statuses, msg=m) + self.on_chat_timestamp(buddylist=statuses, msg=m) # Buddylist overlay elif mtype == "buddylist_overlay": @@ -2665,22 +2667,22 @@ class Client: ) self._buddylist[id_] = statuses[id_] - self.onBuddylistOverlay(statuses=statuses, msg=m) + self.on_buddylist_overlay(statuses=statuses, msg=m) # Unknown message type else: - self.onUnknownMesssageType(msg=m) + self.on_unknown_messsage_type(msg=m) except Exception as e: - self.onMessageError(exception=e, msg=m) + self.on_message_error(exception=e, msg=m) - def _doOneListen(self): + def _do_one_listen(self): try: - if self._markAlive: + if self._mark_alive: self._ping() - content = self._pullMessage() + content = self._pull_message() if content: - self._parseMessage(content) + self._parse_message(content) except KeyboardInterrupt: return False except requests.Timeout: @@ -2696,7 +2698,7 @@ class Client: else: raise e except Exception as e: - return self.onListenError(exception=e) + return self.on_listen_error(exception=e) return True @@ -2707,22 +2709,22 @@ class Client: markAlive (bool): Whether this should ping the Facebook server each time the loop runs """ if markAlive is not None: - self.setActiveStatus(markAlive) + self.set_active_status(markAlive) - self.onListening() + self.on_listening() - while self._doOneListen(): + while self._do_one_listen(): pass self._sticky, self._pool = (None, None) - def setActiveStatus(self, markAlive): + def set_active_status(self, markAlive): """Change active status while listening. Args: markAlive (bool): Whether to show if client is active """ - self._markAlive = markAlive + self._mark_alive = markAlive """ END LISTEN METHODS @@ -2732,7 +2734,7 @@ class Client: EVENTS """ - def onLoggingIn(self, email=None): + def on_logging_in(self, email=None): """Called when the client is logging in. Args: @@ -2740,11 +2742,11 @@ class Client: """ log.info("Logging in {}...".format(email)) - def on2FACode(self): + def on_2fa_code(self): """Called when a 2FA code is needed to progress.""" return input("Please enter your 2FA code --> ") - def onLoggedIn(self, email=None): + def on_logged_in(self, email=None): """Called when the client is successfully logged in. Args: @@ -2752,11 +2754,11 @@ class Client: """ log.info("Login of {} successful.".format(email)) - def onListening(self): + def on_listening(self): """Called when the client is listening.""" log.info("Listening...") - def onListenError(self, exception=None): + def on_listen_error(self, exception=None): """Called when an error was encountered while listening. Args: @@ -2768,7 +2770,7 @@ class Client: log.exception("Got exception while listening") return True - def onMessage( + def on_message( self, mid=None, author_id=None, @@ -2793,7 +2795,7 @@ class Client: """ log.info("{} from {} in {}".format(message_object, thread_id, thread_type.name)) - def onColorChange( + def on_color_change( self, mid=None, author_id=None, @@ -2822,7 +2824,7 @@ class Client: ) ) - def onEmojiChange( + def on_emoji_change( self, mid=None, author_id=None, @@ -2851,7 +2853,7 @@ class Client: ) ) - def onTitleChange( + def on_title_change( self, mid=None, author_id=None, @@ -2880,7 +2882,7 @@ class Client: ) ) - def onImageChange( + def on_image_change( self, mid=None, author_id=None, @@ -2903,7 +2905,7 @@ class Client: """ log.info("{} changed thread image in {}".format(author_id, thread_id)) - def onNicknameChange( + def on_nickname_change( self, mid=None, author_id=None, @@ -2934,7 +2936,7 @@ class Client: ) ) - def onAdminAdded( + def on_admin_added( self, mid=None, added_id=None, @@ -2956,7 +2958,7 @@ class Client: """ log.info("{} added admin: {} in {}".format(author_id, added_id, thread_id)) - def onAdminRemoved( + def on_admin_removed( self, mid=None, removed_id=None, @@ -2978,7 +2980,7 @@ class Client: """ log.info("{} removed admin: {} in {}".format(author_id, removed_id, thread_id)) - def onApprovalModeChange( + def on_approval_mode_change( self, mid=None, approval_mode=None, @@ -3003,7 +3005,7 @@ class Client: else: log.info("{} disabled approval mode in {}".format(author_id, thread_id)) - def onMessageSeen( + def on_message_seen( self, seen_by=None, thread_id=None, @@ -3030,7 +3032,7 @@ class Client: ) ) - def onMessageDelivered( + def on_message_delivered( self, msg_ids=None, delivered_for=None, @@ -3057,7 +3059,7 @@ class Client: ) ) - def onMarkedSeen( + def on_marked_seen( self, threads=None, seen_at=None, at=None, metadata=None, msg=None ): """Called when the client is listening, and the client has successfully marked threads as seen. @@ -3076,7 +3078,7 @@ class Client: ) ) - def onMessageUnsent( + def on_message_unsent( self, mid=None, author_id=None, @@ -3101,7 +3103,7 @@ class Client: ) ) - def onPeopleAdded( + def on_people_added( self, mid=None, added_ids=None, @@ -3124,7 +3126,7 @@ class Client: "{} added: {} in {}".format(author_id, ", ".join(added_ids), thread_id) ) - def onPersonRemoved( + def on_person_removed( self, mid=None, removed_id=None, @@ -3145,7 +3147,7 @@ class Client: """ log.info("{} removed: {} in {}".format(author_id, removed_id, thread_id)) - def onFriendRequest(self, from_id=None, msg=None): + def on_friend_request(self, from_id=None, msg=None): """Called when the client is listening, and somebody sends a friend request. Args: @@ -3154,7 +3156,7 @@ class Client: """ log.info("Friend request from {}".format(from_id)) - def onInbox(self, unseen=None, unread=None, recent_unread=None, msg=None): + def on_inbox(self, unseen=None, unread=None, recent_unread=None, msg=None): """ Todo: Documenting this @@ -3167,7 +3169,7 @@ class Client: """ log.info("Inbox event: {}, {}, {}".format(unseen, unread, recent_unread)) - def onTyping( + def on_typing( self, author_id=None, status=None, thread_id=None, thread_type=None, msg=None ): """Called when the client is listening, and somebody starts or stops typing into a chat. @@ -3181,7 +3183,7 @@ class Client: """ pass - def onGamePlayed( + def on_game_played( self, mid=None, author_id=None, @@ -3216,7 +3218,7 @@ class Client: ) ) - def onReactionAdded( + def on_reaction_added( self, mid=None, reaction=None, @@ -3244,7 +3246,7 @@ class Client: ) ) - def onReactionRemoved( + def on_reaction_removed( self, mid=None, author_id=None, @@ -3269,7 +3271,7 @@ class Client: ) ) - def onBlock( + def on_block( self, author_id=None, thread_id=None, thread_type=None, at=None, msg=None ): """Called when the client is listening, and somebody blocks client. @@ -3285,7 +3287,7 @@ class Client: "{} blocked {} ({}) thread".format(author_id, thread_id, thread_type.name) ) - def onUnblock( + def on_unblock( self, author_id=None, thread_id=None, thread_type=None, at=None, msg=None ): """Called when the client is listening, and somebody blocks client. @@ -3301,7 +3303,7 @@ class Client: "{} unblocked {} ({}) thread".format(author_id, thread_id, thread_type.name) ) - def onLiveLocation( + def on_live_location( self, mid=None, location=None, @@ -3328,7 +3330,7 @@ class Client: ) ) - def onCallStarted( + def on_call_started( self, mid=None, caller_id=None, @@ -3358,7 +3360,7 @@ class Client: "{} started call in {} ({})".format(caller_id, thread_id, thread_type.name) ) - def onCallEnded( + def on_call_ended( self, mid=None, caller_id=None, @@ -3390,7 +3392,7 @@ class Client: "{} ended call in {} ({})".format(caller_id, thread_id, thread_type.name) ) - def onUserJoinedCall( + def on_user_joined_call( self, mid=None, joined_id=None, @@ -3417,7 +3419,7 @@ class Client: "{} joined call in {} ({})".format(joined_id, thread_id, thread_type.name) ) - def onPollCreated( + def on_poll_created( self, mid=None, poll=None, @@ -3446,7 +3448,7 @@ class Client: ) ) - def onPollVoted( + def on_poll_voted( self, mid=None, poll=None, @@ -3477,7 +3479,7 @@ class Client: ) ) - def onPlanCreated( + def on_plan_created( self, mid=None, plan=None, @@ -3506,7 +3508,7 @@ class Client: ) ) - def onPlanEnded( + def on_plan_ended( self, mid=None, plan=None, @@ -3531,7 +3533,7 @@ class Client: "Plan {} has ended in {} ({})".format(plan, thread_id, thread_type.name) ) - def onPlanEdited( + def on_plan_edited( self, mid=None, plan=None, @@ -3560,7 +3562,7 @@ class Client: ) ) - def onPlanDeleted( + def on_plan_deleted( self, mid=None, plan=None, @@ -3589,7 +3591,7 @@ class Client: ) ) - def onPlanParticipation( + def on_plan_participation( self, mid=None, plan=None, @@ -3627,7 +3629,7 @@ class Client: ) ) - def onQprimer(self, at=None, msg=None): + def on_qprimer(self, at=None, msg=None): """Called when the client just started listening. Args: @@ -3636,7 +3638,7 @@ class Client: """ pass - def onChatTimestamp(self, buddylist=None, msg=None): + def on_chat_timestamp(self, buddylist=None, msg=None): """Called when the client receives chat online presence update. Args: @@ -3645,7 +3647,7 @@ class Client: """ log.debug("Chat Timestamps received: {}".format(buddylist)) - def onBuddylistOverlay(self, statuses=None, msg=None): + def on_buddylist_overlay(self, statuses=None, msg=None): """Called when the client is listening and client receives information about friend active status. Args: @@ -3654,7 +3656,7 @@ class Client: """ log.debug("Buddylist overlay received: {}".format(statuses)) - def onUnknownMesssageType(self, msg=None): + def on_unknown_messsage_type(self, msg=None): """Called when the client is listening, and some unknown data was received. Args: @@ -3662,7 +3664,7 @@ class Client: """ log.debug("Unknown message received: {}".format(msg)) - def onMessageError(self, exception=None, msg=None): + def on_message_error(self, exception=None, msg=None): """Called when an error was encountered while parsing received data. Args: diff --git a/fbchat/_file.py b/fbchat/_file.py index b475663..10edf9c 100644 --- a/fbchat/_file.py +++ b/fbchat/_file.py @@ -59,7 +59,7 @@ class AudioAttachment(Attachment): class ImageAttachment(Attachment): """Represents an image that has been sent as a Facebook attachment. - To retrieve the full image URL, use: `Client.fetchImageUrl`, and pass it the id of + To retrieve the full image URL, use: `Client.fetch_image_url`, and pass it the id of the image attachment. """ diff --git a/fbchat/_message.py b/fbchat/_message.py index 97eb2e9..329fe85 100644 --- a/fbchat/_message.py +++ b/fbchat/_message.py @@ -72,7 +72,7 @@ class Message: created_at = attr.ib(None, init=False) #: Whether the message is read is_read = attr.ib(None, init=False) - #: A list of people IDs who read the message, works only with :func:`fbchat.Client.fetchThreadMessages` + #: A list of people IDs who read the message, works only with :func:`fbchat.Client.fetch_thread_messages` read_by = attr.ib(factory=list, init=False) #: A dictionary with user's IDs as keys, and their :class:`MessageReaction` as values reactions = attr.ib(factory=dict, init=False) @@ -92,15 +92,15 @@ class Message: forwarded = attr.ib(False, init=False) @classmethod - def formatMentions(cls, text, *args, **kwargs): + def format_mentions(cls, text, *args, **kwargs): """Like `str.format`, but takes tuples with a thread id and text instead. Return a `Message` object, with the formatted string and relevant mentions. - >>> Message.formatMentions("Hey {!r}! My name is {}", ("1234", "Peter"), ("4321", "Michael")) + >>> Message.format_mentions("Hey {!r}! My name is {}", ("1234", "Peter"), ("4321", "Michael")) <Message (None): "Hey 'Peter'! My name is Michael", mentions=[<Mention 1234: offset=4 length=7>, <Mention 4321: offset=24 length=7>] emoji_size=None attachments=[]> - >>> Message.formatMentions("Hey {p}! My name is {}", ("1234", "Michael"), p=("4321", "Peter")) + >>> Message.format_mentions("Hey {p}! My name is {}", ("1234", "Michael"), p=("4321", "Peter")) <Message (None): 'Hey Peter! My name is Michael', mentions=[<Mention 4321: offset=4 length=5>, <Mention 1234: offset=22 length=7>] emoji_size=None attachments=[]> """ result = "" diff --git a/fbchat/_poll.py b/fbchat/_poll.py index 08c6de6..12a29b2 100644 --- a/fbchat/_poll.py +++ b/fbchat/_poll.py @@ -7,7 +7,7 @@ class Poll: #: Title of the poll title = attr.ib() - #: List of :class:`PollOption`, can be fetched with :func:`fbchat.Client.fetchPollOptions` + #: List of :class:`PollOption`, can be fetched with :func:`fbchat.Client.fetch_poll_options` options = attr.ib() #: Options count options_count = attr.ib(None) diff --git a/fbchat/_state.py b/fbchat/_state.py index 5215229..38cf767 100644 --- a/fbchat/_state.py +++ b/fbchat/_state.py @@ -264,14 +264,14 @@ class State: ] def _do_send_request(self, data): - offline_threading_id = _util.generateOfflineThreadingID() + offline_threading_id = _util.generate_offline_threading_id() data["client"] = "mercury" data["author"] = "fbid:{}".format(self.user_id) data["timestamp"] = _util.now() data["source"] = "source:chat:web" data["offline_threading_id"] = offline_threading_id data["message_id"] = offline_threading_id - data["threading_id"] = _util.generateMessageID(self._client_id) + data["threading_id"] = _util.generate_message_id(self._client_id) data["ephemeral_ttl_mode:"] = "0" j = self._post("/messaging/send/", data) diff --git a/fbchat/_util.py b/fbchat/_util.py index 00aa189..6e53360 100644 --- a/fbchat/_util.py +++ b/fbchat/_util.py @@ -55,7 +55,7 @@ def parse_json(content): raise FBchatFacebookError("Error while parsing JSON: {!r}".format(content)) -def digitToChar(digit): +def digit_to_char(digit): if digit < 10: return str(digit) return chr(ord("a") + digit - 10) @@ -66,21 +66,21 @@ def str_base(number, base): return "-" + str_base(-number, base) (d, m) = divmod(number, base) if d > 0: - return str_base(d, base) + digitToChar(m) - return digitToChar(m) + return str_base(d, base) + digit_to_char(m) + return digit_to_char(m) -def generateMessageID(client_id=None): +def generate_message_id(client_id=None): k = now() l = int(random.random() * 4294967295) return "<{}:{}-{}@mail.projektitan.com>".format(k, l, client_id) -def getSignatureID(): +def get_signature_id(): return hex(int(random.random() * 2147483648)) -def generateOfflineThreadingID(): +def generate_offline_threading_id(): ret = now() value = int(random.random() * 4294967295) string = ("0000000000000000000000" + format(value, "b"))[-22:] diff --git a/tests/conftest.py b/tests/conftest.py index f2a8a34..b673cf5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -88,7 +88,7 @@ def catch_event(client2): try: # Make the client send a messages to itself, so the blocking pull request will return # This is probably not safe, since the client is making two requests simultaneously - client2.sendMessage(random_hex(), client2.uid) + client2.send(Message(text=random_hex()), client2.uid) finally: t.join() diff --git a/tests/test_base.py b/tests/test_base.py index 6cdf43a..ebd2a79 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -16,25 +16,25 @@ def test_examples(): @pytest.mark.trylast @pytest.mark.expensive def test_login(client1): - assert client1.isLoggedIn() + assert client1.is_logged_in() email = client1.email password = client1.password client1.logout() - assert not client1.isLoggedIn() + assert not client1.is_logged_in() with pytest.raises(FBchatException): client1.login("<invalid email>", "<invalid password>", max_tries=1) client1.login(email, password) - assert client1.isLoggedIn() + assert client1.is_logged_in() @pytest.mark.trylast def test_sessions(client1): - session = client1.getSession() + session = client1.get_session() Client("no email needed", "no password needed", session_cookies=session) - client1.setSession(session) - assert client1.isLoggedIn() + client1.set_session(session) + assert client1.is_logged_in() diff --git a/tests/test_fetch.py b/tests/test_fetch.py index 451d2b1..ee86f6e 100644 --- a/tests/test_fetch.py +++ b/tests/test_fetch.py @@ -6,24 +6,24 @@ from utils import subset, STICKER_LIST, EMOJI_LIST def test_fetch_all_users(client1): - users = client1.fetchAllUsers() + users = client1.fetch_all_users() assert len(users) > 0 def test_fetch_thread_list(client1): - threads = client1.fetchThreadList(limit=2) + threads = client1.fetch_thread_list(limit=2) assert len(threads) == 2 def test_fetch_threads(client1): - threads = client1.fetchThreads(limit=2) + threads = client1.fetch_threads(limit=2) assert len(threads) == 2 @pytest.mark.parametrize("emoji, emoji_size", EMOJI_LIST) def test_fetch_message_emoji(client, emoji, emoji_size): - mid = client.sendEmoji(emoji, emoji_size) - message, = client.fetchThreadMessages(limit=1) + mid = client.send_emoji(emoji, emoji_size) + message, = client.fetch_thread_messages(limit=1) assert subset( vars(message), uid=mid, author=client.uid, text=emoji, emoji_size=emoji_size @@ -32,8 +32,8 @@ def test_fetch_message_emoji(client, emoji, emoji_size): @pytest.mark.parametrize("emoji, emoji_size", EMOJI_LIST) def test_fetch_message_info_emoji(client, thread, emoji, emoji_size): - mid = client.sendEmoji(emoji, emoji_size) - message = client.fetchMessageInfo(mid, thread_id=thread["id"]) + mid = client.send_emoji(emoji, emoji_size) + message = client.fetch_message_info(mid, thread_id=thread["id"]) assert subset( vars(message), uid=mid, author=client.uid, text=emoji, emoji_size=emoji_size @@ -42,7 +42,7 @@ def test_fetch_message_info_emoji(client, thread, emoji, emoji_size): def test_fetch_message_mentions(client, thread, message_with_mentions): mid = client.send(message_with_mentions) - message, = client.fetchThreadMessages(limit=1) + message, = client.fetch_thread_messages(limit=1) assert subset( vars(message), uid=mid, author=client.uid, text=message_with_mentions.text @@ -54,7 +54,7 @@ def test_fetch_message_mentions(client, thread, message_with_mentions): def test_fetch_message_info_mentions(client, thread, message_with_mentions): mid = client.send(message_with_mentions) - message = client.fetchMessageInfo(mid, thread_id=thread["id"]) + message = client.fetch_message_info(mid, thread_id=thread["id"]) assert subset( vars(message), uid=mid, author=client.uid, text=message_with_mentions.text @@ -67,7 +67,7 @@ def test_fetch_message_info_mentions(client, thread, message_with_mentions): @pytest.mark.parametrize("sticker", STICKER_LIST) def test_fetch_message_sticker(client, sticker): mid = client.send(Message(sticker=sticker)) - message, = client.fetchThreadMessages(limit=1) + message, = client.fetch_thread_messages(limit=1) assert subset(vars(message), uid=mid, author=client.uid) assert subset(vars(message.sticker), uid=sticker.uid) @@ -76,22 +76,24 @@ def test_fetch_message_sticker(client, sticker): @pytest.mark.parametrize("sticker", STICKER_LIST) def test_fetch_message_info_sticker(client, thread, sticker): mid = client.send(Message(sticker=sticker)) - message = client.fetchMessageInfo(mid, thread_id=thread["id"]) + message = client.fetch_message_info(mid, thread_id=thread["id"]) assert subset(vars(message), uid=mid, author=client.uid) assert subset(vars(message.sticker), uid=sticker.uid) def test_fetch_info(client1, group): - info = client1.fetchUserInfo("4")["4"] + info = client1.fetch_user_info("4")["4"] assert info.name == "Mark Zuckerberg" - info = client1.fetchGroupInfo(group["id"])[group["id"]] + info = client1.fetch_group_info(group["id"])[group["id"]] assert info.type == ThreadType.GROUP def test_fetch_image_url(client): - client.sendLocalFiles([path.join(path.dirname(__file__), "resources", "image.png")]) - message, = client.fetchThreadMessages(limit=1) + client.send_local_files( + [path.join(path.dirname(__file__), "resources", "image.png")] + ) + message, = client.fetch_thread_messages(limit=1) - assert client.fetchImageUrl(message.attachments[0].uid) + assert client.fetch_image_url(message.attachments[0].uid) diff --git a/tests/test_message_management.py b/tests/test_message_management.py index 7a9a2a0..83a12bd 100644 --- a/tests/test_message_management.py +++ b/tests/test_message_management.py @@ -6,14 +6,14 @@ from utils import subset def test_set_reaction(client): mid = client.send(Message(text="This message will be reacted to")) - client.reactToMessage(mid, MessageReaction.LOVE) + client.react_to_message(mid, MessageReaction.LOVE) def test_delete_messages(client): text1 = "This message will stay" text2 = "This message will be removed" - mid1 = client.sendMessage(text1) - mid2 = client.sendMessage(text2) - client.deleteMessages(mid2) - message, = client.fetchThreadMessages(limit=1) + mid1 = client.send(Message(text=text1)) + mid2 = client.send(Message(text=text2)) + client.delete_messages(mid2) + message, = client.fetch_thread_messages(limit=1) assert subset(vars(message), uid=mid1, author=client.uid, text=text1) diff --git a/tests/test_plans.py b/tests/test_plans.py index 49815b6..bd762c2 100644 --- a/tests/test_plans.py +++ b/tests/test_plans.py @@ -17,8 +17,8 @@ from time import time ], ) def plan_data(request, client, user, thread, catch_event, compare): - with catch_event("onPlanCreated") as x: - client.createPlan(request.param, thread["id"]) + with catch_event("on_plan_created") as x: + client.create_plan(request.param, thread["id"]) assert compare(x) assert subset( vars(x.res["plan"]), @@ -32,8 +32,8 @@ def plan_data(request, client, user, thread, catch_event, compare): assert user["id"] in x.res["plan"].invited request.param.uid = x.res["plan"].uid yield x.res, request.param - with catch_event("onPlanDeleted") as x: - client.deletePlan(plan_id) + with catch_event("on_plan_deleted") as x: + client.delete_plan(plan_id) assert compare(x) @@ -44,7 +44,7 @@ def test_create_delete_plan(plan_data): def test_fetch_plan_info(client, catch_event, plan_data): event, plan = plan_data - fetched_plan = client.fetchPlanInfo(plan.uid) + fetched_plan = client.fetch_plan_info(plan.uid) assert subset( vars(fetched_plan), time=plan.time, title=plan.title, author_id=int(client.uid) ) @@ -55,8 +55,8 @@ def test_change_plan_participation( client, thread, catch_event, compare, plan_data, take_part ): event, plan = plan_data - with catch_event("onPlanParticipation") as x: - client.changePlanParticipation(plan, take_part=take_part) + with catch_event("on_plan_participation") as x: + client.change_plan_participation(plan, take_part=take_part) assert compare(x, take_part=take_part) assert subset( vars(x.res["plan"]), @@ -72,8 +72,8 @@ def test_change_plan_participation( def test_edit_plan(client, thread, catch_event, compare, plan_data): event, plan = plan_data new_plan = Plan(plan.time + 100, random_hex()) - with catch_event("onPlanEdited") as x: - client.editPlan(plan, new_plan) + with catch_event("on_plan_edited") as x: + client.edit_plan(plan, new_plan) assert compare(x) assert subset( vars(x.res["plan"]), @@ -86,8 +86,8 @@ def test_edit_plan(client, thread, catch_event, compare, plan_data): @pytest.mark.trylast @pytest.mark.expensive def test_on_plan_ended(client, thread, catch_event, compare): - with catch_event("onPlanEnded") as x: - client.createPlan(Plan(int(time()) + 120, "Wait for ending")) + with catch_event("on_plan_ended") as x: + client.create_plan(Plan(int(time()) + 120, "Wait for ending")) x.wait(180) assert subset( x.res, @@ -96,15 +96,15 @@ def test_on_plan_ended(client, thread, catch_event, compare): ) -# createPlan(self, plan, thread_id=None) -# editPlan(self, plan, new_plan) -# deletePlan(self, plan) -# changePlanParticipation(self, plan, take_part=True) +# create_plan(self, plan, thread_id=None) +# edit_plan(self, plan, new_plan) +# delete_plan(self, plan) +# change_plan_participation(self, plan, take_part=True) -# onPlanCreated(self, mid=None, plan=None, author_id=None, thread_id=None, thread_type=None, ts=None, metadata=None, msg=None) -# onPlanEnded(self, mid=None, plan=None, thread_id=None, thread_type=None, ts=None, metadata=None, msg=None) -# onPlanEdited(self, mid=None, plan=None, author_id=None, thread_id=None, thread_type=None, ts=None, metadata=None, msg=None) -# onPlanDeleted(self, mid=None, plan=None, author_id=None, thread_id=None, thread_type=None, ts=None, metadata=None, msg=None) -# onPlanParticipation(self, mid=None, plan=None, take_part=None, author_id=None, thread_id=None, thread_type=None, ts=None, metadata=None, msg=None) +# on_plan_created(self, mid=None, plan=None, author_id=None, thread_id=None, thread_type=None, ts=None, metadata=None, msg=None) +# on_plan_ended(self, mid=None, plan=None, thread_id=None, thread_type=None, ts=None, metadata=None, msg=None) +# on_plan_edited(self, mid=None, plan=None, author_id=None, thread_id=None, thread_type=None, ts=None, metadata=None, msg=None) +# on_plan_deleted(self, mid=None, plan=None, author_id=None, thread_id=None, thread_type=None, ts=None, metadata=None, msg=None) +# on_plan_participation(self, mid=None, plan=None, take_part=None, author_id=None, thread_id=None, thread_type=None, ts=None, metadata=None, msg=None) -# fetchPlanInfo(self, plan_id) +# fetch_plan_info(self, plan_id) diff --git a/tests/test_polls.py b/tests/test_polls.py index 6fd05fd..d4ffb24 100644 --- a/tests/test_polls.py +++ b/tests/test_polls.py @@ -39,9 +39,9 @@ from utils import random_hex, subset ], ) def poll_data(request, client1, group, catch_event): - with catch_event("onPollCreated") as x: - client1.createPoll(request.param, thread_id=group["id"]) - options = client1.fetchPollOptions(x.res["poll"].uid) + with catch_event("on_poll_created") as x: + client1.create_poll(request.param, thread_id=group["id"]) + options = client1.fetch_poll_options(x.res["poll"].uid) return x.res, request.param, options @@ -79,8 +79,8 @@ def test_update_poll_vote(client1, group, catch_event, poll_data): new_vote_ids = [o.uid for o in options[0 : len(options) : 2] if not o.vote] re_vote_ids = [o.uid for o in options[0 : len(options) : 2] if o.vote] new_options = [random_hex(), random_hex()] - with catch_event("onPollVoted") as x: - client1.updatePollVote( + with catch_event("on_poll_voted") as x: + client1.update_poll_vote( event["poll"].uid, option_ids=new_vote_ids + re_vote_ids, new_options=new_options, diff --git a/tests/test_search.py b/tests/test_search.py index fabd5cb..54c9cc6 100644 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -2,7 +2,7 @@ from fbchat import ThreadType def test_search_for(client1): - users = client1.searchForUsers("Mark Zuckerberg") + users = client1.search_for_users("Mark Zuckerberg") assert len(users) > 0 u = users[0] diff --git a/tests/test_send.py b/tests/test_send.py index e92192f..fa5f3fa 100644 --- a/tests/test_send.py +++ b/tests/test_send.py @@ -7,8 +7,8 @@ from utils import subset, STICKER_LIST, EMOJI_LIST, TEXT_LIST @pytest.mark.parametrize("text", TEXT_LIST) def test_send_text(client, catch_event, compare, text): - with catch_event("onMessage") as x: - mid = client.sendMessage(text) + with catch_event("on_message") as x: + mid = client.send(Message(text=text)) assert compare(x, mid=mid, message=text) assert subset(vars(x.res["message_object"]), uid=mid, author=client.uid, text=text) @@ -16,8 +16,8 @@ def test_send_text(client, catch_event, compare, text): @pytest.mark.parametrize("emoji, emoji_size", EMOJI_LIST) def test_send_emoji(client, catch_event, compare, emoji, emoji_size): - with catch_event("onMessage") as x: - mid = client.sendEmoji(emoji, emoji_size) + with catch_event("on_message") as x: + mid = client.send_emoji(emoji, emoji_size) assert compare(x, mid=mid, message=emoji) assert subset( @@ -30,7 +30,7 @@ def test_send_emoji(client, catch_event, compare, emoji, emoji_size): def test_send_mentions(client, catch_event, compare, message_with_mentions): - with catch_event("onMessage") as x: + with catch_event("on_message") as x: mid = client.send(message_with_mentions) assert compare(x, mid=mid, message=message_with_mentions.text) @@ -47,7 +47,7 @@ def test_send_mentions(client, catch_event, compare, message_with_mentions): @pytest.mark.parametrize("sticker", STICKER_LIST) def test_send_sticker(client, catch_event, compare, sticker): - with catch_event("onMessage") as x: + with catch_event("on_message") as x: mid = client.send(Message(sticker=sticker)) assert compare(x, mid=mid) @@ -68,7 +68,7 @@ def test_send_sticker(client, catch_event, compare, sticker): ) def test_send_images(client, catch_event, compare, method_name, url): text = "An image sent with {}".format(method_name) - with catch_event("onMessage") as x: + with catch_event("on_message") as x: mid = getattr(client, method_name)(url, Message(text)) assert compare(x, mid=mid, message=text) @@ -87,8 +87,8 @@ def test_send_local_files(client, catch_event, compare): "video.mp4", ] text = "Files sent locally" - with catch_event("onMessage") as x: - mid = client.sendLocalFiles( + with catch_event("on_message") as x: + mid = client.send_local_files( [path.join(path.dirname(__file__), "resources", f) for f in files], message=Message(text), ) @@ -102,8 +102,8 @@ def test_send_local_files(client, catch_event, compare): def test_send_remote_files(client, catch_event, compare): files = ["image.png", "data.json"] text = "Files sent from remote" - with catch_event("onMessage") as x: - mid = client.sendRemoteFiles( + with catch_event("on_message") as x: + mid = client.send_remote_files( [ "https://github.com/carpedm20/fbchat/raw/master/tests/{}".format(f) for f in files diff --git a/tests/test_tests.py b/tests/test_tests.py index 2132f8f..23f32f7 100644 --- a/tests/test_tests.py +++ b/tests/test_tests.py @@ -3,6 +3,6 @@ import pytest def test_catch_event(client2, catch_event): mid = "test" - with catch_event("onMessage") as x: - client2.onMessage(mid=mid) + with catch_event("on_message") as x: + client2.on_message(mid=mid) assert x.res["mid"] == mid diff --git a/tests/test_thread_interraction.py b/tests/test_thread_interraction.py index 6e426a3..34dac97 100644 --- a/tests/test_thread_interraction.py +++ b/tests/test_thread_interraction.py @@ -8,14 +8,14 @@ from os import path def test_remove_from_and_add_to_group(client1, client2, group, catch_event): # Test both methods, while ensuring that the user gets added to the group try: - with catch_event("onPersonRemoved") as x: - client1.removeUserFromGroup(client2.uid, group["id"]) + with catch_event("on_person_removed") as x: + client1.remove_user_from_group(client2.uid, group["id"]) assert subset( x.res, removed_id=client2.uid, author_id=client1.uid, thread_id=group["id"] ) finally: - with catch_event("onPeopleAdded") as x: - client1.addUsersToGroup(client2.uid, group["id"]) + with catch_event("on_people_added") as x: + client1.add_users_to_group(client2.uid, group["id"]) assert subset( x.res, added_ids=[client2.uid], author_id=client1.uid, thread_id=group["id"] ) @@ -24,14 +24,14 @@ def test_remove_from_and_add_to_group(client1, client2, group, catch_event): def test_remove_from_and_add_admins_to_group(client1, client2, group, catch_event): # Test both methods, while ensuring that the user gets added as group admin try: - with catch_event("onAdminRemoved") as x: - client1.removeGroupAdmins(client2.uid, group["id"]) + with catch_event("on_admin_removed") as x: + client1.remove_group_admins(client2.uid, group["id"]) assert subset( x.res, removed_id=client2.uid, author_id=client1.uid, thread_id=group["id"] ) finally: - with catch_event("onAdminAdded") as x: - client1.addGroupAdmins(client2.uid, group["id"]) + with catch_event("on_admin_added") as x: + client1.add_group_admins(client2.uid, group["id"]) assert subset( x.res, added_id=client2.uid, author_id=client1.uid, thread_id=group["id"] ) @@ -39,8 +39,8 @@ def test_remove_from_and_add_admins_to_group(client1, client2, group, catch_even def test_change_title(client1, group, catch_event): title = random_hex() - with catch_event("onTitleChange") as x: - client1.changeThreadTitle(title, group["id"], thread_type=ThreadType.GROUP) + with catch_event("on_title_change") as x: + client1.change_thread_title(title, group["id"], thread_type=ThreadType.GROUP) assert subset( x.res, author_id=client1.uid, @@ -52,8 +52,8 @@ def test_change_title(client1, group, catch_event): def test_change_nickname(client, client_all, catch_event, compare): nickname = random_hex() - with catch_event("onNicknameChange") as x: - client.changeNickname(nickname, client_all.uid) + with catch_event("on_nickname_change") as x: + client.change_nickname(nickname, client_all.uid) assert compare(x, changed_for=client_all.uid, new_nickname=nickname) @@ -71,15 +71,15 @@ def test_change_nickname(client, client_all, catch_event, compare): ], ) def test_change_emoji(client, catch_event, compare, emoji): - with catch_event("onEmojiChange") as x: - client.changeThreadEmoji(emoji) + with catch_event("on_emoji_change") as x: + client.change_thread_emoji(emoji) assert compare(x, new_emoji=emoji) def test_change_image_local(client1, group, catch_event): url = path.join(path.dirname(__file__), "resources", "image.png") - with catch_event("onImageChange") as x: - image_id = client1.changeGroupImageLocal(url, group["id"]) + with catch_event("on_image_change") as x: + image_id = client1.change_group_image_local(url, group["id"]) assert subset( x.res, new_image=image_id, author_id=client1.uid, thread_id=group["id"] ) @@ -88,8 +88,8 @@ def test_change_image_local(client1, group, catch_event): # To be changed when merged into master def test_change_image_remote(client1, group, catch_event): url = "https://github.com/carpedm20/fbchat/raw/master/tests/image.png" - with catch_event("onImageChange") as x: - image_id = client1.changeGroupImageRemote(url, group["id"]) + with catch_event("on_image_change") as x: + image_id = client1.change_group_image_remote(url, group["id"]) assert subset( x.res, new_image=image_id, author_id=client1.uid, thread_id=group["id"] ) @@ -105,8 +105,8 @@ def test_change_image_remote(client1, group, catch_event): ], ) def test_change_color(client, catch_event, compare, color): - with catch_event("onColorChange") as x: - client.changeThreadColor(color) + with catch_event("on_color_change") as x: + client.change_thread_color(color) assert compare(x, new_color=color) @@ -115,20 +115,20 @@ def test_change_color_invalid(client): class InvalidColor: value = "#0077ff" - client.changeThreadColor(InvalidColor()) + client.change_thread_color(InvalidColor()) @pytest.mark.parametrize("status", TypingStatus) def test_typing_status(client, catch_event, compare, status): - with catch_event("onTyping") as x: - client.setTypingStatus(status) + with catch_event("on_typing") as x: + client.set_typing_status(status) assert compare(x, status=status) @pytest.mark.parametrize("require_admin_approval", [True, False]) def test_change_approval_mode(client1, group, catch_event, require_admin_approval): - with catch_event("onApprovalModeChange") as x: - client1.changeGroupApprovalMode(require_admin_approval, group["id"]) + with catch_event("on_approval_mode_change") as x: + client1.change_group_approval_mode(require_admin_approval, group["id"]) assert subset( x.res, @@ -140,15 +140,15 @@ def test_change_approval_mode(client1, group, catch_event, require_admin_approva @pytest.mark.parametrize("mute_time", [0, 10, 100, 1000, -1]) def test_mute_thread(client, mute_time): - assert client.muteThread(mute_time) - assert client.unmuteThread() + assert client.mute_thread(mute_time) + assert client.unmute_thread() def test_mute_thread_reactions(client): - assert client.muteThreadReactions() - assert client.unmuteThreadReactions() + assert client.mute_thread_reactions() + assert client.unmute_thread_reactions() def test_mute_thread_mentions(client): - assert client.muteThreadMentions() - assert client.unmuteThreadMentions() + assert client.mute_thread_mentions() + assert client.unmute_thread_mentions() diff --git a/tests/utils.py b/tests/utils.py index 1e44c92..93e762b 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -46,11 +46,11 @@ class ClientThread(threading.Thread): super(ClientThread, self).__init__(*args, **kwargs) def start(self): - self.client._doOneListen() # QPrimer, Facebook now knows we're about to start pulling + self.client._do_one_listen() # QPrimer, Facebook now knows we're about to start pulling super(ClientThread, self).start() def run(self): - while not self.should_stop.is_set() and self.client._doOneListen(): + while not self.should_stop.is_set() and self.client._do_one_listen(): pass @@ -95,4 +95,4 @@ def load_client(n, cache): max_tries=1, ) yield client - cache.set("client{}_session".format(n), client.getSession()) + cache.set("client{}_session".format(n), client.get_session())