From 0b69299d4842c20a5044b66352fb891378e225cd Mon Sep 17 00:00:00 2001 From: AugustLigh Date: Mon, 1 Jul 2024 19:49:26 +0300 Subject: [PATCH] code cleanup --- AminoLightPy/client.py | 231 +++++++------- AminoLightPy/constants.py | 6 +- AminoLightPy/sub_client.py | 636 ++++++++++++++++++------------------- 3 files changed, 421 insertions(+), 452 deletions(-) diff --git a/AminoLightPy/client.py b/AminoLightPy/client.py index 1a2531c..d448f42 100644 --- a/AminoLightPy/client.py +++ b/AminoLightPy/client.py @@ -93,7 +93,7 @@ def login(self, email: str, password: str, self_device: bool = True): "v": 2, } - response = self.session.post(f"{api}/g/s/auth/login", json=data) + response = self.session.post("/g/s/auth/login", json=data) self.authenticated = True json = response.json() self.sid = json["sid"] @@ -136,7 +136,7 @@ def login_phone(self, phoneNumber: str, password: str, self_device: bool = True) "action": "normal", } - response = self.session.post(f"{api}/g/s/auth/login", json=data) + response = self.session.post("/g/s/auth/login", json=data) self.authenticated = True json = response.json() self.sid = json["sid"] @@ -178,7 +178,7 @@ def login_secret(self, secret: str, self_device: bool = True): "action": "normal", } - response = self.session.post(f"{api}/g/s/auth/login", json=data) + response = self.session.post("/g/s/auth/login", json=data) self.authenticated = True json = response.json() self.sid = json["sid"] @@ -234,7 +234,7 @@ def register(self, nickname: str, email: str, password: str, verificationCode: s "type": 1, "identity": email} - response = self.session.post(f"{api}/g/s/auth/register", json=data) + response = self.session.post("/g/s/auth/register", json=data) return response.json() def restore(self, email: str, password: str): @@ -256,7 +256,7 @@ def restore(self, email: str, password: str): "email": email } - response = self.session.post(f"{api}/g/s/account/delete-request/cancel", json=data) + response = self.session.post("/g/s/account/delete-request/cancel", json=data) return response.status_code def logout(self): @@ -276,7 +276,7 @@ def logout(self): "clientType": 100 } - response = self.session.post(f"{api}/g/s/auth/logout", json=data) + response = self.session.post("/g/s/auth/logout", json=data) self.authenticated = False self.sid = None self.profile = None @@ -316,7 +316,7 @@ def configure(self, age: int, gender: str): "gender": gender_mapping[gender], } - response = self.session.post(f"{api}/g/s/persona/profile/basic", json=data) + response = self.session.post("/g/s/persona/profile/basic", json=data) return response.status_code def verify(self, email: str, code: str): @@ -340,7 +340,7 @@ def verify(self, email: str, code: str): "deviceID": self.device_id, } - response = self.session.post(f"{api}/g/s/auth/check-security-validation", json=data) + response = self.session.post("/g/s/auth/check-security-validation", json=data) return response.status_code def request_verify_code(self, email: str, resetPassword: bool = False): @@ -366,7 +366,7 @@ def request_verify_code(self, email: str, resetPassword: bool = False): data["level"] = 2 data["purpose"] = "reset-password" - response = self.session.post(f"{api}/g/s/auth/request-security-validation", json=data) + response = self.session.post("/g/s/auth/request-security-validation", json=data) return response.status_code def activate_account(self, email: str, code: str): @@ -390,7 +390,7 @@ def activate_account(self, email: str, code: str): "deviceID": self.device_id } - response = self.session.post(f"{api}/g/s/auth/activate-email", json=data) + response = self.session.post("/g/s/auth/activate-email", json=data) return response.status_code # Provided by "𝑰 𝑵 𝑻 𝑬 𝑹 𝑳 𝑼 𝑫 𝑬#4082" @@ -412,7 +412,7 @@ def delete_account(self, password: str): "secret": f"0 {password}" } - response = self.session.post(f"{api}/g/s/account/delete-request", json=data) + response = self.session.post("/g/s/account/delete-request", json=data) return response.status_code def change_password(self, email: str, password: str, code: str): @@ -445,7 +445,7 @@ def change_password(self, email: str, password: str, code: str): "deviceID": self.device_id } - response = self.session.post(f"{api}/g/s/auth/reset-password", json=data) + response = self.session.post("/g/s/auth/reset-password", json=data) return response.status_code @@ -458,7 +458,7 @@ def get_account_info(self): - **Fail** : :meth:`Exceptions ` """ - response = self.session.get(f"{api}/g/s/account") + response = self.session.get("/g/s/account") return objects.UserProfile(response.json()["account"]).UserProfile def handle_socket_message(self, data): @@ -475,7 +475,7 @@ def get_eventlog(self): - **Fail** : :meth:`Exceptions ` """ params = {"language": "en"} - response = self.session.get(f"{api}/g/s/eventlog/profile", params=params) + response = self.session.get("/g/s/eventlog/profile", params=params) return response.json() def sub_clients(self, start: int = 0, size: int = 25): @@ -493,7 +493,7 @@ def sub_clients(self, start: int = 0, size: int = 25): """ if not self.authenticated: raise exceptions.NotLoggedIn - response = self.session.get(f"{api}/g/s/community/joined?v=1&start={start}&size={size}") + response = self.session.get(f"/g/s/community/joined?v=1&start={start}&size={size}") return objects.CommunityList(response.json()["communityList"]).CommunityList def sub_clients_profile(self, start: int = 0, size: int = 25): @@ -511,7 +511,7 @@ def sub_clients_profile(self, start: int = 0, size: int = 25): """ if not self.authenticated: raise exceptions.NotLoggedIn - response = self.session.get(f"{api}/g/s/community/joined?v=1&start={start}&size={size}") + response = self.session.get(f"/g/s/community/joined?v=1&start={start}&size={size}") return response.json()["userInfoInCommunities"] def get_user_info(self, userId: str): @@ -526,7 +526,7 @@ def get_user_info(self, userId: str): - **Fail** : :meth:`Exceptions ` """ - response = self.session.get(f"{api}/g/s/user-profile/{userId}") + response = self.session.get(f"/g/s/user-profile/{userId}") return objects.UserProfile(response.json()["userProfile"]).UserProfile def get_chat_threads(self, start: int = 0, size: int = 25): @@ -547,7 +547,7 @@ def get_chat_threads(self, start: int = 0, size: int = 25): "size": size, "type": "joined-me" } - response = self.session.get(f"{api}/g/s/chat/thread", params=params) + response = self.session.get("/g/s/chat/thread", params=params) return objects.ThreadList(response.json()["threadList"]).ThreadList def get_chat_thread(self, chatId: str): @@ -562,7 +562,7 @@ def get_chat_thread(self, chatId: str): - **Fail** : :meth:`Exceptions ` """ - response = self.session.get(f"{api}/g/s/chat/thread/{chatId}") + response = self.session.get(f"/g/s/chat/thread/{chatId}") return objects.Thread(response.json()["thread"]).Thread def get_chat_users(self, chatId: str, start: int = 0, size: int = 25): @@ -585,7 +585,7 @@ def get_chat_users(self, chatId: str, start: int = 0, size: int = 25): "cv": "1.2" } - response = self.session.get(f"{api}/g/s/chat/thread/{chatId}/member", params=params) + response = self.session.get(f"/g/s/chat/thread/{chatId}/member", params=params) return objects.UserProfileList(response.json()["memberList"]).UserProfileList def join_chat(self, chatId: str): @@ -601,7 +601,7 @@ def join_chat(self, chatId: str): - **Fail** : :meth:`Exceptions ` """ userId = self.session.headers["AUID"] - response = self.session.post(f"{api}/g/s/chat/thread/{chatId}/member/{userId}") + response = self.session.post(f"/g/s/chat/thread/{chatId}/member/{userId}") return response.status_code def leave_chat(self, chatId: str): @@ -617,7 +617,7 @@ def leave_chat(self, chatId: str): - **Fail** : :meth:`Exceptions ` """ userId = self.session.headers["AUID"] - response = self.session.delete(f"{api}/g/s/chat/thread/{chatId}/member/{userId}") + response = self.session.delete(f"/g/s/chat/thread/{chatId}/member/{userId}") return response.status_code def start_chat(self, userId: Union[str, list], message: str, @@ -656,7 +656,7 @@ def start_chat(self, userId: Union[str, list], message: str, if isGlobal: data["eventSource"] = "GlobalComposeMenu" - response = self.session.post(f"{api}/g/s/chat/thread", json=data) + response = self.session.post("/g/s/chat/thread", json=data) return objects.Thread(response.json()["thread"]).Thread @@ -682,7 +682,7 @@ def invite_to_chat(self, userId: Union[str, list], chatId: str): "uids": userIds } - response = self.session.post(f"{api}/g/s/chat/thread/{chatId}/member/invite", json=data) + response = self.session.post(f"/g/s/chat/thread/{chatId}/member/invite", json=data) return response.status_code @@ -703,7 +703,7 @@ def kick(self, userId: str, chatId: str, allowRejoin: bool = True): params = {"allowRejoin": int(allowRejoin)} return self.session.delete( - url=f"{api}/g/s/chat/thread/{chatId}/member/{userId}", + url=f"/g/s/chat/thread/{chatId}/member/{userId}", params=params ).status_code @@ -729,7 +729,7 @@ def get_chat_messages(self, chatId: str, size: int = 25, pageToken: str = None): if pageToken: params["pageToken"] = pageToken - response = self.session.get(f"{api}/g/s/chat/thread/{chatId}/message", params=params) + response = self.session.get(f"/g/s/chat/thread/{chatId}/message", params=params) return objects.GetMessages(response.json()).GetMessages def get_message_info(self, chatId: str, messageId: str): @@ -745,7 +745,7 @@ def get_message_info(self, chatId: str, messageId: str): - **Fail** : :meth:`Exceptions ` """ - response = self.session.get(f"{api}/g/s/chat/thread/{chatId}/message/{messageId}") + response = self.session.get(f"/g/s/chat/thread/{chatId}/message/{messageId}") return objects.Message(response.json()["message"]).Message def get_community_info(self, comId: int): @@ -760,7 +760,7 @@ def get_community_info(self, comId: int): - **Fail** : :meth:`Exceptions ` """ - response = self.session.get(f"{api}/g/s-x{comId}/community/info?withInfluencerList=1&withTopicList=true&influencerListOrderStrategy=fansCount") + response = self.session.get(f"/g/s-x{comId}/community/info?withInfluencerList=1&withTopicList=true&influencerListOrderStrategy=fansCount") return objects.Community(response.json()["community"]).Community def search_community(self, aminoId: str): @@ -775,7 +775,7 @@ def search_community(self, aminoId: str): - **Fail** : :meth:`Exceptions ` """ - response = self.session.get(f"{api}/g/s/search/amino-id-and-link?q={aminoId}") + response = self.session.get(f"/g/s/search/amino-id-and-link?q={aminoId}") result = response.json()["resultList"] if not result: raise exceptions.CommunityNotFound(aminoId) @@ -795,7 +795,7 @@ def get_user_following(self, userId: str, start: int = 0, size: int = 25): - **Fail** : :meth:`Exceptions ` """ - response = self.session.get(f"{api}/g/s/user-profile/{userId}/joined?start={start}&size={size}") + response = self.session.get(f"/g/s/user-profile/{userId}/joined?start={start}&size={size}") return objects.UserProfileList(response.json()["userProfileList"]).UserProfileList def get_user_followers(self, userId: str, start: int = 0, size: int = 25): @@ -812,7 +812,7 @@ def get_user_followers(self, userId: str, start: int = 0, size: int = 25): - **Fail** : :meth:`Exceptions ` """ - response = self.session.get(f"{api}/g/s/user-profile/{userId}/member?start={start}&size={size}") + response = self.session.get(f"/g/s/user-profile/{userId}/member?start={start}&size={size}") return objects.UserProfileList(response.json()["userProfileList"]).UserProfileList def get_blocked_users(self, start: int = 0, size: int = 25): @@ -828,7 +828,7 @@ def get_blocked_users(self, start: int = 0, size: int = 25): - **Fail** : :meth:`Exceptions ` """ - response = self.session.get(f"{api}/g/s/block?start={start}&size={size}") + response = self.session.get(f"/g/s/block?start={start}&size={size}") return objects.UserProfileList(response.json()["userProfileList"]).UserProfileList def get_blog_info(self, blogId: str = None, wikiId: str = None, quizId: str = None, fileId: str = None): @@ -846,15 +846,15 @@ def get_blog_info(self, blogId: str = None, wikiId: str = None, quizId: str = No """ if blogId or quizId: blogId = quizId if quizId is not None else blogId - response = self.session.get(f"{api}/g/s/blog/{blogId}") + response = self.session.get(f"/g/s/blog/{blogId}") return objects.GetBlogInfo(response.json()).GetBlogInfo if wikiId: - response = self.session.get(f"{api}/g/s/item/{wikiId}") + response = self.session.get(f"/g/s/item/{wikiId}") return objects.GetWikiInfo(response.json()).GetWikiInfo if fileId: - response = self.session.get(f"{api}/g/s/shared-folder/files/{fileId}") + response = self.session.get(f"/g/s/shared-folder/files/{fileId}") return objects.SharedFolderFile(response.json()["file"]).SharedFolderFile raise exceptions.SpecifyType() @@ -884,11 +884,11 @@ def get_blog_comments(self, blogId: str = None, wikiId: str = None, quizId: str if blogId or quizId: blogId = quizId if not blogId else blogId - url = f"{api}/g/s/blog/{blogId}/comment" + url = f"/g/s/blog/{blogId}/comment" elif wikiId: - url = f"{api}/g/s/item/{wikiId}/comment" + url = f"/g/s/item/{wikiId}/comment" elif fileId: - url = f"{api}/g/s/shared-folder/files/{fileId}/comment" + url = f"/g/s/shared-folder/files/{fileId}/comment" else: raise exceptions.SpecifyType @@ -909,7 +909,7 @@ def get_blocker_users(self, start: int = 0, size: int = 25): - **Fail** : :meth:`Exceptions ` """ - response = self.session.get(f"{api}/g/s/block/full-list?start={start}&size={size}") + response = self.session.get(f"/g/s/block/full-list?start={start}&size={size}") return response.json()["blockerUidList"] def get_wall_comments(self, userId: str, sorting: str = "newest", start: int = 0, size: int = 25): @@ -937,7 +937,7 @@ def get_wall_comments(self, userId: str, sorting: str = "newest", start: int = 0 else: raise exceptions.WrongType(sorting) - response = self.session.get(f"{api}/g/s/user-profile/{userId}/g-comment?sort={sorting}&start={start}&size={size}") + response = self.session.get(f"/g/s/user-profile/{userId}/g-comment?sort={sorting}&start={start}&size={size}") return objects.CommentList(response.json()["commentList"]).CommentList def flag(self, reason: str, flagType: int, userId: str = None, blogId: str = None, wikiId: str = None, asGuest: bool = False): @@ -987,7 +987,7 @@ def flag(self, reason: str, flagType: int, userId: str = None, blogId: str = Non else: flg = "flag" - response = self.session.post(f"{api}/g/s/{flg}", json=data) + response = self.session.post(f"/g/s/{flg}", json=data) return response.status_code def check_values(self, *args): @@ -1071,7 +1071,7 @@ def send_message(self, chatId: str, message: str = None, messageType: int = 0, url = upload_media(self, file) data["mediaValue"] = url - response = self.session.post(f"{api}/g/s/chat/thread/{chatId}/message", json=data) + response = self.session.post(f"/g/s/chat/thread/{chatId}/message", json=data) return response.status_code def delete_message(self, chatId: str, messageId: str, asStaff: bool = False, reason: str = None): @@ -1096,9 +1096,9 @@ def delete_message(self, chatId: str, messageId: str, asStaff: bool = False, rea if asStaff and reason: data["adminOpNote"] = {"content": reason} if not asStaff: - response = self.session.delete(f"{api}/g/s/chat/thread/{chatId}/message/{messageId}") + response = self.session.delete(f"/g/s/chat/thread/{chatId}/message/{messageId}") else: - response = self.session.post(f"{api}/g/s/chat/thread/{chatId}/message/{messageId}/admin", json=data) + response = self.session.post(f"/g/s/chat/thread/{chatId}/message/{messageId}/admin", json=data) return response.status_code def mark_as_read(self, chatId: str, messageId: str): @@ -1117,7 +1117,7 @@ def mark_as_read(self, chatId: str, messageId: str): data = { "messageId": messageId, } - response = self.session.post(f"{api}/g/s/chat/thread/{chatId}/mark-as-read", json=data) + response = self.session.post(f"/g/s/chat/thread/{chatId}/mark-as-read", json=data) return response.status_code def edit_chat(self, chatId: str, doNotDisturb: bool = None, pinChat: bool = None, @@ -1180,27 +1180,27 @@ def edit_chat(self, chatId: str, doNotDisturb: bool = None, pinChat: bool = None if doNotDisturb: data = {"alertOption": 2} res.append(self.session.post( - url=f"{api}/g/s/chat/thread/{chatId}/member/{userId}/alert", + url=f"/g/s/chat/thread/{chatId}/member/{userId}/alert", json=data ).status_code ) else: data = {"alertOption": 1} response = self.session.post( - url=f"{api}/g/s/chat/thread/{chatId}/member/{userId}/alert", + url=f"/g/s/chat/thread/{chatId}/member/{userId}/alert", json=data ) res.append(response.status_code) if pinChat is not None: if pinChat: response = self.session.post( - url=f"{api}/g/s/chat/thread/{chatId}/pin", + url=f"/g/s/chat/thread/{chatId}/pin", json=data ) res.append(response.status_code) else: response = self.session.post( - url=f"{api}/g/s/chat/thread/{chatId}/unpin", + url=f"/g/s/chat/thread/{chatId}/unpin", json=data ) res.append(response.status_code) @@ -1208,58 +1208,58 @@ def edit_chat(self, chatId: str, doNotDisturb: bool = None, pinChat: bool = None userId = self.session.headers["AUID"] data = {"media": [100, backgroundImage, None]} response = self.session.post( - url=f"{api}/g/s/chat/thread/{chatId}/member/{userId}/background", + url=f"/g/s/chat/thread/{chatId}/member/{userId}/background", json=data ) res.append(response.status_code) if coHosts is not None: data = {"uidList": coHosts} response = self.session.post( - url=f"{api}/g/s/chat/thread/{chatId}/co-host", + url=f"/g/s/chat/thread/{chatId}/co-host", son=data ) res.append(response.status_code) if viewOnly is not None: if viewOnly: response = self.session.post( - url=f"{api}/g/s/chat/thread/{chatId}/view-only/enable" + url=f"/g/s/chat/thread/{chatId}/view-only/enable" ) res.append(response.status_code) else: response = self.session.post( - url=f"{api}/g/s/chat/thread/{chatId}/view-only/disable" + url=f"/g/s/chat/thread/{chatId}/view-only/disable" ) res.append(response.status_code) if canInvite is not None: if canInvite: response = self.session.post( - url=f"{api}/g/s/chat/thread/{chatId}/members-can-invite/enable", + url=f"/g/s/chat/thread/{chatId}/members-can-invite/enable", json=data ) res.append(response.status_code) else: response = self.session.post( - url=f"{api}/g/s/chat/thread/{chatId}/members-can-invite/disable", + url=f"/g/s/chat/thread/{chatId}/members-can-invite/disable", json=data ) res.append(response.status_code) if canTip is not None: if canTip: response = self.session.post( - url=f"{api}/g/s/chat/thread/{chatId}/tipping-perm-status/enable", + url=f"/g/s/chat/thread/{chatId}/tipping-perm-status/enable", json=data ) res.append(response.status_code) else: response = self.session.post( - url=f"{api}/g/s/chat/thread/{chatId}/tipping-perm-status/disable", + url=f"/g/s/chat/thread/{chatId}/tipping-perm-status/disable", json=data ) res.append(response.status_code) response = self.session.post( - url=f"{api}/g/s/chat/thread/{chatId}", + url=f"/g/s/chat/thread/{chatId}", json=data ) res.append(response.status_code) @@ -1282,7 +1282,8 @@ def send_coins(self, coins: int, blogId: str = None, chatId: str = None, objectI - **Fail** : :meth:`Exceptions ` """ - if not transactionId: transactionId = str(uuid4()) + if not transactionId: + transactionId = str(uuid4()) data = { "coins": coins, @@ -1290,13 +1291,13 @@ def send_coins(self, coins: int, blogId: str = None, chatId: str = None, objectI } if blogId: - url = f"{api}/g/s/blog/{blogId}/tipping" + url = f"/g/s/blog/{blogId}/tipping" elif chatId: - url = f"{api}/g/s/chat/thread/{chatId}/tipping" + url = f"/g/s/chat/thread/{chatId}/tipping" elif objectId: data["objectId"] = objectId data["objectType"] = 2 - url = f"{api}/g/s/tipping" + url = "/g/s/tipping" else: raise exceptions.SpecifyType @@ -1316,12 +1317,12 @@ def follow(self, userId: Union[str, list]): - **Fail** : :meth:`Exceptions ` """ if isinstance(userId, str): - response = self.session.post(f"{api}/g/s/user-profile/{userId}/member") + response = self.session.post(f"/g/s/user-profile/{userId}/member") elif isinstance(userId, list): userId = self.session.headers["AUID"] data = {"targetUidList": userId} - response = self.session.post(f"{api}/g/s/user-profile/{userId}/joined", json=data) + response = self.session.post(f"/g/s/user-profile/{userId}/joined", json=data) else: raise exceptions.WrongType @@ -1340,7 +1341,7 @@ def unfollow(self, userId: str): - **Fail** : :meth:`Exceptions ` """ userId = self.session.headers["AUID"] - response = self.session.delete(f"{api}/g/s/user-profile/{userId}/member/{userId}") + response = self.session.delete(f"/g/s/user-profile/{userId}/member/{userId}") return response.status_code def block(self, userId: str): @@ -1355,7 +1356,7 @@ def block(self, userId: str): - **Fail** : :meth:`Exceptions ` """ - response = self.session.post(f"{api}/g/s/block/{userId}") + response = self.session.post(f"/g/s/block/{userId}") return response.status_code def unblock(self, userId: str): @@ -1370,7 +1371,7 @@ def unblock(self, userId: str): - **Fail** : :meth:`Exceptions ` """ - response = self.session.delete(f"{api}/g/s/block/{userId}") + response = self.session.delete(f"/g/s/block/{userId}") return response.status_code def join_community(self, comId: int, invitationId: str = None): @@ -1390,7 +1391,7 @@ def join_community(self, comId: int, invitationId: str = None): if invitationId: data["invitationId"] = invitationId - response = self.session.post(f"{api}/x{comId}/s/community/join", json=data) + response = self.session.post(f"/x{comId}/s/community/join", json=data) return response.status_code def request_join_community(self, comId: int, message: str = None): @@ -1408,7 +1409,7 @@ def request_join_community(self, comId: int, message: str = None): """ data = {"message": message} - response = self.session.post(f"{api}/x{comId}/s/community/membership-request", jaon=data) + response = self.session.post(f"/x{comId}/s/community/membership-request", jaon=data) return response.status_code def leave_community(self, comId: int): @@ -1423,7 +1424,7 @@ def leave_community(self, comId: int): - **Fail** : :meth:`Exceptions ` """ - response = self.session.post(f"{api}/x{comId}/s/community/leave") + response = self.session.post(f"/x{comId}/s/community/leave") return response.status_code def flag_community(self, comId: int, reason: str, flagType: int, isGuest: bool = False): @@ -1456,7 +1457,7 @@ def flag_community(self, comId: int, reason: str, flagType: int, isGuest: bool = flg = "g-flag" else: flg = "flag" - response = self.session.post(f"{api}/x{comId}/s/{flg}", json=data) + response = self.session.post(f"/x{comId}/s/{flg}", json=data) return response.status_code def edit_profile(self, nickname: str = None, content: str = None, icon: BinaryIO = None, backgroundColor: str = None, backgroundImage: str = None, defaultBubbleId: str = None): @@ -1498,7 +1499,7 @@ def edit_profile(self, nickname: str = None, content: str = None, icon: BinaryIO data["extensions"] = {"defaultBubbleId": defaultBubbleId} userId = self.session.headers["AUID"] - response = self.session.post(f"{api}/g/s/user-profile/{userId}", json=data) + response = self.session.post(f"/g/s/user-profile/{userId}", json=data) return response.status_code def set_amino_id(self, aminoId: str): @@ -1515,7 +1516,7 @@ def set_amino_id(self, aminoId: str): """ data = {"aminoId": aminoId} - response = self.session.post(f"{api}/g/s/account/change-amino-id", json=data) + response = self.session.post("/g/s/account/change-amino-id", json=data) return response.status_code def get_linked_communities(self, userId: str): @@ -1530,7 +1531,7 @@ def get_linked_communities(self, userId: str): - **Fail** : :meth:`Exceptions ` """ - response = self.session.get(f"{api}/g/s/user-profile/{userId}/linked-community") + response = self.session.get(f"/g/s/user-profile/{userId}/linked-community") return objects.CommunityList(response.json()["linkedCommunityList"]).CommunityList def get_unlinked_communities(self, userId: str): @@ -1545,7 +1546,7 @@ def get_unlinked_communities(self, userId: str): - **Fail** : :meth:`Exceptions ` """ - response = self.session.get(f"{api}/g/s/user-profile/{userId}/linked-community") + response = self.session.get(f"/g/s/user-profile/{userId}/linked-community") return objects.CommunityList(response.json()["unlinkedCommunityList"]).CommunityList def reorder_linked_communities(self, comIds: list): @@ -1563,7 +1564,7 @@ def reorder_linked_communities(self, comIds: list): data = {"ndcIds": comIds} userId = self.session.headers["AUID"] return self.session.post( - url=f"{api}/g/s/user-profile/{userId}/linked-community/reorder", + url=f"/g/s/user-profile/{userId}/linked-community/reorder", json=data ).status_code @@ -1581,7 +1582,7 @@ def add_linked_community(self, comId: int): """ userId = self.session.headers["AUID"] return self.session.post( - url=f"{api}/g/s/user-profile/{userId}/linked-community/{comId}" + url=f"/g/s/user-profile/{userId}/linked-community/{comId}" ).status_code @@ -1599,7 +1600,7 @@ def remove_linked_community(self, comId: int): """ userId = self.session.headers["AUID"] return self.session.delete( - url=f"{api}/g/s/user-profile/{userId}/linked-community/{comId}" + url=f"/g/s/user-profile/{userId}/linked-community/{comId}" ).status_code def comment(self, message: str, userId: str = None, blogId: str = None, wikiId: str = None, replyTo: str = None): @@ -1632,15 +1633,15 @@ def comment(self, message: str, userId: str = None, blogId: str = None, wikiId: if userId: data["eventSource"] = "UserProfileView" - url = f"{api}/g/s/user-profile/{userId}/g-comment" + url = f"/g/s/user-profile/{userId}/g-comment" elif blogId: data["eventSource"] = "PostDetailView" - url = f"{api}/g/s/blog/{blogId}/g-comment" + url = f"/g/s/blog/{blogId}/g-comment" elif wikiId: data["eventSource"] = "PostDetailView" - url = f"{api}/g/s/item/{wikiId}/g-comment" + url = f"/g/s/item/{wikiId}/g-comment" else: raise exceptions.SpecifyType @@ -1663,11 +1664,11 @@ def delete_comment(self, commentId: str, userId: str = None, blogId: str = None, - **Fail** : :meth:`Exceptions ` """ if userId: - url = f"{api}/g/s/user-profile/{userId}/g-comment/{commentId}" + url = f"/g/s/user-profile/{userId}/g-comment/{commentId}" elif blogId: - url = f"{api}/g/s/blog/{blogId}/g-comment/{commentId}" + url = f"/g/s/blog/{blogId}/g-comment/{commentId}" elif wikiId: - url = f"{api}/g/s/item/{wikiId}/g-comment/{commentId}" + url = f"/g/s/item/{wikiId}/g-comment/{commentId}" else: raise exceptions.SpecifyType @@ -1693,17 +1694,17 @@ def like_blog(self, blogId: Union[str, list] = None, wikiId: str = None): if blogId: if isinstance(blogId, str): data["eventSource"] = "UserProfileView" - url = f"{api}/g/s/blog/{blogId}/g-vote?cv=1.2" + url = f"/g/s/blog/{blogId}/g-vote?cv=1.2" elif isinstance(blogId, list): data["targetIdList"] = blogId - url = f"{api}/g/s/feed/g-vote" + url = "/g/s/feed/g-vote" else: raise exceptions.WrongType(type(blogId)) elif wikiId: data["eventSource"] = "PostDetailView" - url = f"{api}/g/s/item/{wikiId}/g-vote?cv=1.2" + url = f"/g/s/item/{wikiId}/g-vote?cv=1.2" else: raise exceptions.SpecifyType @@ -1723,9 +1724,9 @@ def unlike_blog(self, blogId: str = None, wikiId: str = None): - **Fail** : :meth:`Exceptions ` """ if blogId: - url = f"{api}/g/s/blog/{blogId}/g-vote?eventSource=UserProfileView" + url = f"/g/s/blog/{blogId}/g-vote?eventSource=UserProfileView" elif wikiId: - url = f"{api}/g/s/item/{wikiId}/g-vote?eventSource=PostDetailView" + url = f"/g/s/item/{wikiId}/g-vote?eventSource=PostDetailView" else: raise exceptions.SpecifyType @@ -1752,15 +1753,15 @@ def like_comment(self, commentId: str, userId: str = None, blogId: str = None, w if userId: data["eventSource"] = "UserProfileView" - url = f"{api}/g/s/user-profile/{userId}/comment/{commentId}/g-vote?cv=1.2&value=1" + url = f"/g/s/user-profile/{userId}/comment/{commentId}/g-vote?cv=1.2&value=1" elif blogId: data["eventSource"] = "PostDetailView" - url = f"{api}/g/s/blog/{blogId}/comment/{commentId}/g-vote?cv=1.2&value=1" + url = f"/g/s/blog/{blogId}/comment/{commentId}/g-vote?cv=1.2&value=1" elif wikiId: data["eventSource"] = "PostDetailView" - url = f"{api}/g/s/item/{wikiId}/comment/{commentId}/g-vote?cv=1.2&value=1" + url = f"/g/s/item/{wikiId}/comment/{commentId}/g-vote?cv=1.2&value=1" else: raise exceptions.SpecifyType @@ -1782,11 +1783,11 @@ def unlike_comment(self, commentId: str, userId: str = None, blogId: str = None, - **Fail** : :meth:`Exceptions ` """ if userId: - url = f"{api}/g/s/user-profile/{userId}/comment/{commentId}/g-vote?eventSource=UserProfileView" + url = f"/g/s/user-profile/{userId}/comment/{commentId}/g-vote?eventSource=UserProfileView" elif blogId: - url = f"{api}/g/s/blog/{blogId}/comment/{commentId}/g-vote?eventSource=PostDetailView" + url = f"/g/s/blog/{blogId}/comment/{commentId}/g-vote?eventSource=PostDetailView" elif wikiId: - url = f"{api}/g/s/item/{wikiId}/comment/{commentId}/g-vote?eventSource=PostDetailView" + url = f"/g/s/item/{wikiId}/comment/{commentId}/g-vote?eventSource=PostDetailView" else: raise exceptions.SpecifyType @@ -1804,7 +1805,7 @@ def get_membership_info(self): - **Fail** : :meth:`Exceptions ` """ - response = self.session.get(f"{api}/g/s/membership?force=true") + response = self.session.get("/g/s/membership?force=true") return objects.Membership(response.json()).Membership def get_ta_announcements(self, language: str = "en", start: int = 0, size: int = 25): @@ -1829,7 +1830,7 @@ def get_ta_announcements(self, language: str = "en", start: int = 0, size: int = "start": start, "size": size } - response = self.session.get(f"{api}/g/s/announcement", params=params) + response = self.session.get("/g/s/announcement", params=params) return objects.BlogList(response.json()["blogList"]).BlogList def get_wallet_info(self): @@ -1844,7 +1845,7 @@ def get_wallet_info(self): - **Fail** : :meth:`Exceptions ` """ - response = self.session.get(f"{api}/g/s/wallet") + response = self.session.get("/g/s/wallet") return objects.WalletInfo(response.json()["wallet"]).WalletInfo def get_wallet_history(self, start: int = 0, size: int = 25): @@ -1860,7 +1861,7 @@ def get_wallet_history(self, start: int = 0, size: int = 25): - **Fail** : :meth:`Exceptions ` """ - response = self.session.get(f"{api}/g/s/wallet/coin/history?start={start}&size={size}") + response = self.session.get(f"/g/s/wallet/coin/history?start={start}&size={size}") return objects.WalletHistory(response.json()["coinHistoryList"]).WalletHistory def get_from_deviceid(self, deviceId: str): @@ -1875,7 +1876,7 @@ def get_from_deviceid(self, deviceId: str): - **Fail** : :meth:`Exceptions ` """ - response = self.session.get(f"{api}/g/s/auid?deviceId={deviceId}") + response = self.session.get(f"/g/s/auid?deviceId={deviceId}") return response.json()["auid"] def get_from_code(self, code: str): @@ -1891,7 +1892,7 @@ def get_from_code(self, code: str): - **Fail** : :meth:`Exceptions ` """ - response = self.session.get(f"{api}/g/s/link-resolution?q={code}") + response = self.session.get(f"/g/s/link-resolution?q={code}") return objects.FromCode(response.json()["linkInfoV2"]).FromCode def get_from_id(self, objectId: str, objectType: int, comId: int = None): @@ -1914,9 +1915,9 @@ def get_from_id(self, objectId: str, objectType: int, comId: int = None): "objectType": objectType, } if comId: - url = f"{api}/g/s-x{comId}/link-resolution" + url = f"/g/s-x{comId}/link-resolution" else: - url = f"{api}/g/s/link-resolution" + url = "/g/s/link-resolution" response = self.session.post(url, json=data) return objects.FromCode(response.json()["linkInfoV2"]).FromCode @@ -1933,7 +1934,7 @@ def get_supported_languages(self): - **Fail** : :meth:`Exceptions ` """ - response = self.session.get(f"{api}/g/s/community-collection/supported-languages?start=0&size=100") + response = self.session.get("/g/s/community-collection/supported-languages") return response.json()["supportedLanguages"] def claim_new_user_coupon(self): @@ -1948,7 +1949,7 @@ def claim_new_user_coupon(self): - **Fail** : :meth:`Exceptions ` """ - return self.session.post(f"{api}/g/s/coupon/new-user-coupon/claim").status_code + return self.session.post("/g/s/coupon/new-user-coupon/claim").status_code def get_subscriptions(self, start: int = 0, size: int = 25, objectType: int = 122): """ @@ -1963,7 +1964,7 @@ def get_subscriptions(self, start: int = 0, size: int = 25, objectType: int = 12 - **Fail** : :meth:`Exceptions ` """ - response = self.session.get(f"{api}/g/s/store/subscription?objectType={objectType}&start={start}&size={size}") + response = self.session.get(f"/g/s/store/subscription?objectType={objectType}&start={start}&size={size}") return response.json()["storeSubscriptionItemList"] def get_all_users(self, start: int = 0, size: int = 25, type: str = "recent"): @@ -1979,7 +1980,7 @@ def get_all_users(self, start: int = 0, size: int = 25, type: str = "recent"): - **Fail** : :meth:`Exceptions ` """ - response = self.session.get(f"{api}/g/s/user-profile?type={type}&start={start}&size={size}") + response = self.session.get(f"/g/s/user-profile?type={type}&start={start}&size={size}") return objects.UserProfileCountList(response.json()).UserProfileCountList def accept_host(self, chatId: str, requestId: str): @@ -1995,7 +1996,7 @@ def accept_host(self, chatId: str, requestId: str): - **Fail** : :meth:`Exceptions ` """ return self.session.post( - url=f"{api}/g/s/chat/thread/{chatId}/transfer-organizer/{requestId}/accept" + url=f"/g/s/chat/thread/{chatId}/transfer-organizer/{requestId}/accept" ).status_code def accept_organizer(self, chatId: str, requestId: str): @@ -2024,7 +2025,7 @@ def link_identify(self, code: str): - **Success** : A JSON object with the community link information. - **Fail** : :meth:`Exceptions ` """ - response = self.session.get(f"{api}/g/s/community/link-identify?q=http%3A%2F%2Faminoapps.com%2Finvite%2F{code}") + response = self.session.get(f"/g/s/community/link-identify?q=http%3A%2F%2Faminoapps.com%2Finvite%2F{code}") return response.json() def invite_to_vc(self, chatId: str, userId: str): @@ -2045,7 +2046,7 @@ def invite_to_vc(self, chatId: str, userId: str): "uid": userId } - response = self.session.post(f"{api}/g/s/chat/thread/{chatId}/vvchat-presenter/invite", json=data) + response = self.session.post(f"/g/s/chat/thread/{chatId}/vvchat-presenter/invite", json=data) return response.status_code def wallet_config(self, level: int): @@ -2066,7 +2067,7 @@ def wallet_config(self, level: int): "adsLevel": level, } - response = self.session.post(f"{api}/g/s/wallet/ads/config", json=data) + response = self.session.post("/g/s/wallet/ads/config", json=data) return response.status_code def purchase(self, objectId: str, objectType: int = 114, isAutoRenew: bool = False): @@ -2093,7 +2094,7 @@ def purchase(self, objectId: str, objectType: int = 114, isAutoRenew: bool = Fal }, } - return self.session.post(f"{api}/g/s/store/purchase", json=data).status_code + return self.session.post("/g/s/store/purchase", json=data).status_code def get_public_communities(self, language: str = "en", size: int = 25): """ @@ -2115,7 +2116,7 @@ def get_public_communities(self, language: str = "en", size: int = 25): "pagingType": "t" } - response = self.session.get(f"{api}/g/s/topic/0/feed/community", params=params) + response = self.session.get("/g/s/topic/0/feed/community", params=params) return objects.CommunityList(response.json()["communityList"]).CommunityList def get_blockers(self) -> list[str]: @@ -2127,7 +2128,7 @@ def get_blockers(self) -> list[str]: - **Fail** : :meth:`Exceptions ` """ - response = self.session.get(f"{api}/g/s/block/full-list") + response = self.session.get("/g/s/block/full-list") return response.json()["blockerUidList"] def set_privacy_status(self, isAnonymous: bool = False, getNotifications: bool = False): @@ -2147,7 +2148,7 @@ def set_privacy_status(self, isAnonymous: bool = False, getNotifications: bool = else: data["privacyMode"] = 1 - response = self.session.post(f"{api}/g/s/account/visit-settings", json=data) + response = self.session.post("/g/s/account/visit-settings", json=data) return response.json() def typing(self, chatId: str, comId: int = None) -> Typing: diff --git a/AminoLightPy/constants.py b/AminoLightPy/constants.py index 6dc28b3..91c775a 100644 --- a/AminoLightPy/constants.py +++ b/AminoLightPy/constants.py @@ -6,7 +6,6 @@ from requests import Session from mimetypes import guess_type -from .lib.util.exceptions import SpecifyType from .lib.util import signature, gen_deviceId from .lib.util.exceptions import CheckException @@ -48,6 +47,9 @@ def request(self, method, url, *args, **kwargs): if data is not None: kwargs["data"] = data + if not api in url: + url = api+url + response = super().request(method, url, *args, **kwargs) if response.status_code != 200: @@ -80,7 +82,7 @@ def upload_media(self, file: BinaryIO) -> str: custom_headers["Content-Type"] = fileType response = self.session.post( - url=f"{api}/g/s/media/upload", + url="/g/s/media/upload", data=data, headers=custom_headers, stream=True diff --git a/AminoLightPy/sub_client.py b/AminoLightPy/sub_client.py index 0f58c27..475e973 100644 --- a/AminoLightPy/sub_client.py +++ b/AminoLightPy/sub_client.py @@ -8,10 +8,9 @@ from base64 import b64encode from requests import Session -from .constants import api, upload_media +from .constants import upload_media from .lib.util import exceptions, objects - class SubClient(): "Module for work with community" def __init__(self, comId: int = None, *, profile: objects.UserProfile): @@ -39,7 +38,7 @@ def get_invite_codes(self, status: str = "normal", start: int = 0, size: int = 2 "start": start, "size": size } - response = self.session.get(f"{api}/g/s-x{self.comId}/community/invitation", params=params) + response = self.session.get(f"/g/s-x{self.comId}/community/invitation", params=params) return objects.InviteCodeList(response.json()["communityInvitationList"]).InviteCodeList def generate_invite_code(self, duration: int = 0, force: bool = True): @@ -60,7 +59,7 @@ def generate_invite_code(self, duration: int = 0, force: bool = True): "duration": duration, "force": force } - response = self.session.post(f"{api}/g/s-x{self.comId}/community/invitation", json=data) + response = self.session.post(f"/g/s-x{self.comId}/community/invitation", json=data) return objects.InviteCode(response.json()["communityInvitation"]).InviteCode def delete_invite_code(self, inviteId: str): @@ -77,7 +76,7 @@ def delete_invite_code(self, inviteId: str): **Raises** - **Exceptions** : :meth:`Exceptions ` """ - response = self.session.delete(f"{api}/g/s-x{self.comId}/community/invitation/{inviteId}") + response = self.session.delete(f"/g/s-x{self.comId}/community/invitation/{inviteId}") return response.status_code def post_blog(self, title: str, content: str, imageList: list = None, captionList: list = None, @@ -105,17 +104,16 @@ def post_blog(self, title: str, content: str, imageList: list = None, captionLis """ mediaList = [] - if captionList is not None: + if captionList: for image, caption in zip(imageList, captionList): mediaList.append([100, upload_media(self, image), caption]) else: - if imageList is not None: + if imageList: for image in imageList: mediaList.append([100, upload_media(self, image), None]) data = { - "address": None, "content": content, "title": title, "mediaList": mediaList, @@ -131,7 +129,7 @@ def post_blog(self, title: str, content: str, imageList: list = None, captionLis data["extensions"] = {"style": {"backgroundColor": backgroundColor}} if categoriesList: data["taggedBlogCategoryIdList"] = categoriesList - response = self.session.post(f"{api}/x{self.comId}/s/blog", json=data) + response = self.session.post(f"/x{self.comId}/s/blog", json=data) return response.status_code @@ -163,7 +161,7 @@ def post_wiki(self, title: str, content: str, icon: str = None, imageList: list if backgroundColor: data["extensions"].update({"style": {"backgroundColor": backgroundColor}}) - response = self.session.post(f"{api}/x{self.comId}/s/item", json=data) + response = self.session.post(f"/x{self.comId}/s/item", json=data) return response.status_code def edit_blog(self, blogId: str, title: str = None, content: str = None, @@ -182,25 +180,30 @@ def edit_blog(self, blogId: str, title: str = None, content: str = None, "eventSource": "PostDetailView", } - if title: data["title"] = title - if content: data["content"] = content - if fansOnly: data["extensions"] = {"fansOnly": fansOnly} - if backgroundColor: data["extensions"] = {"style": {"backgroundColor": backgroundColor}} - if categoriesList: data["taggedBlogCategoryIdList"] = categoriesList - response = self.session.post(f"{api}/x{self.comId}/s/blog/{blogId}", json=data) - return response.status_code + if title: + data["title"] = title + if content: + data["content"] = content + if fansOnly: + data["extensions"] = {"fansOnly": fansOnly} + if backgroundColor: + data["extensions"] = {"style": {"backgroundColor": backgroundColor}} + if categoriesList: + data["taggedBlogCategoryIdList"] = categoriesList + + return self.session.post(f"/x{self.comId}/s/blog/{blogId}", json=data).status_code def delete_blog(self, blogId: str): - response = self.session.delete(f"{api}/x{self.comId}/s/blog/{blogId}") - return response.status_code + return self.session.delete(f"/x{self.comId}/s/blog/{blogId}").status_code def delete_wiki(self, wikiId: str): - response = self.session.delete(f"{api}/x{self.comId}/s/item/{wikiId}") - return response.status_code + return self.session.delete(f"/x{self.comId}/s/item/{wikiId}").status_code def repost_blog(self, content: str = None, blogId: str = None, wikiId: str = None): - if blogId is not None: refObjectId, refObjectType = blogId, 1 - elif wikiId is not None: refObjectId, refObjectType = wikiId, 2 + if blogId: + refObjectId, refObjectType = blogId, 1 + elif wikiId: + refObjectId, refObjectType = wikiId, 2 else: raise exceptions.SpecifyType data = { @@ -209,24 +212,24 @@ def repost_blog(self, content: str = None, blogId: str = None, wikiId: str = Non "refObjectType": refObjectType, "type": 2, } - response = self.session.post(f"{api}/x{self.comId}/s/blog", json=data) + response = self.session.post(f"/x{self.comId}/s/blog", json=data) return response.status_code def check_in(self, tz: int = -timezone // 1000): data = { "timezone": tz } - response = self.session.post(f"{api}/x{self.comId}/s/check-in", json=data) + response = self.session.post(f"/x{self.comId}/s/check-in", json=data) return response.status_code def repair_check_in(self, method: int = 0): data = { "repairMethod": str(method+1) } - response = self.session.post(f"{api}/x{self.comId}/s/check-in/repair", json=data) + response = self.session.post(f"/x{self.comId}/s/check-in/repair", json=data) return response.status_code def lottery(self, tz: int = -timezone // 1000): data = { "timezone": tz } - response = self.session.post(f"{api}/x{self.comId}/s/check-in/lottery", json=data) + response = self.session.post(f"/x{self.comId}/s/check-in/lottery", json=data) return objects.LotteryLog(response.json()["lotteryLog"]).LotteryLog def edit_profile(self, nickname: str = None, content: str = None, icon: BinaryIO = None, @@ -236,16 +239,16 @@ def edit_profile(self, nickname: str = None, content: str = None, icon: BinaryIO defaultBubbleId: str = None): mediaList = [] data = {} - if captionList is not None: + if captionList: for image, caption in zip(imageList, captionList): mediaList.append([100, upload_media(self, image), caption]) else: - if imageList is not None: + if imageList: for image in imageList: mediaList.append([100, upload_media(self, image), None]) - if imageList is not None or captionList is not None: + if imageList or captionList: data["mediaList"] = mediaList if nickname: @@ -274,7 +277,7 @@ def edit_profile(self, nickname: str = None, content: str = None, icon: BinaryIO data["extensions"] = {"customTitles": tlt} return self.session.post( - url=f"{api}/x{self.comId}/s/user-profile/{self.profile.userId}", + url=f"/x{self.comId}/s/user-profile/{self.profile.userId}", json=data ).status_code @@ -285,7 +288,7 @@ def vote_poll(self, blogId: str, optionId: str): } return self.session.post( - url=f"{api}/x{self.comId}/s/blog/{blogId}/poll/option/{optionId}/vote", + url=f"/x{self.comId}/s/blog/{blogId}/poll/option/{optionId}/vote", json=data ).status_code @@ -297,22 +300,25 @@ def comment(self, message: str, userId: str = None, blogId: str = None, wikiId: "type": 0 } - if replyTo: data["respondTo"] = replyTo + if replyTo: + data["respondTo"] = replyTo - if isGuest: comType = "g-comment" - else: comType = "comment" + if isGuest: + comType = "g-comment" + else: + comType = "comment" if userId: data["eventSource"] = "UserProfileView" - url = f"{api}/x{self.comId}/s/user-profile/{userId}/{comType}" + url = f"/x{self.comId}/s/user-profile/{userId}/{comType}" elif blogId: data["eventSource"] = "PostDetailView" - url = f"{api}/x{self.comId}/s/blog/{blogId}/{comType}" + url = f"/x{self.comId}/s/blog/{blogId}/{comType}" elif wikiId: data["eventSource"] = "PostDetailView" - url = f"{api}/x{self.comId}/s/item/{wikiId}/{comType}" + url = f"/x{self.comId}/s/item/{wikiId}/{comType}" else: raise exceptions.SpecifyType @@ -321,11 +327,11 @@ def comment(self, message: str, userId: str = None, blogId: str = None, wikiId: def delete_comment(self, commentId: str, userId: str = None, blogId: str = None, wikiId: str = None): if userId: - url = f"{api}/x{self.comId}/s/user-profile/{userId}/comment/{commentId}" + url = f"/x{self.comId}/s/user-profile/{userId}/comment/{commentId}" elif blogId: - url = f"{api}/x{self.comId}/s/blog/{blogId}/comment/{commentId}" + url = f"/x{self.comId}/s/blog/{blogId}/comment/{commentId}" elif wikiId: - url = f"{api}/x{self.comId}/s/item/{wikiId}/comment/{commentId}" + url = f"/x{self.comId}/s/item/{wikiId}/comment/{commentId}" else: raise exceptions.SpecifyType @@ -351,26 +357,29 @@ def like_blog(self, blogId: Union[str, list] = None, wikiId: str = None): if blogId: if isinstance(blogId, str): data["eventSource"] = "UserProfileView" - url = f"{api}/x{self.comId}/s/blog/{blogId}/vote?cv=1.2" + url = f"/x{self.comId}/s/blog/{blogId}/vote?cv=1.2" elif isinstance(blogId, list): data["targetIdList"] = blogId - url = f"{api}/x{self.comId}/s/feed/vote" + url = f"/x{self.comId}/s/feed/vote" else: raise exceptions.WrongType elif wikiId: data["eventSource"] = "PostDetailView" - url = f"{api}/x{self. comId}/s/item/{wikiId}/vote?cv=1.2" + url = f"/x{self. comId}/s/item/{wikiId}/vote?cv=1.2" else: raise exceptions.SpecifyType() return self.session.post(url, json=data).status_code def unlike_blog(self, blogId: str = None, wikiId: str = None): - if blogId: url = f"{api}/x{self.comId}/s/blog/{blogId}/vote?eventSource=UserProfileView" - elif wikiId: url = f"{api}/x{self.comId}/s/item/{wikiId}/vote?eventSource=PostDetailView" - else: raise exceptions.SpecifyType() + if blogId: + url = f"/x{self.comId}/s/blog/{blogId}/vote?eventSource=UserProfileView" + elif wikiId: + url = f"/x{self.comId}/s/item/{wikiId}/vote?eventSource=PostDetailView" + else: + raise exceptions.SpecifyType() return self.session.delete(url).status_code @@ -386,15 +395,15 @@ def like_comment(self, commentId: str, userId: str = None, blogId: str = None, if userId: data["eventSource"] = "UserProfileView" - url = f"{api}/x{self.comId}/s/user-profile/{userId}/comment/{commentId}/vote" + url = f"/x{self.comId}/s/user-profile/{userId}/comment/{commentId}/vote" elif blogId: data["eventSource"] = "PostDetailView" - url = f"{api}/x{self.comId}/s/blog/{blogId}/comment/{commentId}/vote" + url = f"/x{self.comId}/s/blog/{blogId}/comment/{commentId}/vote" elif wikiId: data["eventSource"] = "PostDetailView" - url = f"{api}/x{self.comId}/s/item/{wikiId}/comment/{commentId}/g-vote" + url = f"/x{self.comId}/s/item/{wikiId}/comment/{commentId}/g-vote" else: raise exceptions.SpecifyType() @@ -402,11 +411,11 @@ def like_comment(self, commentId: str, userId: str = None, blogId: str = None, def unlike_comment(self, commentId: str, userId: str = None, blogId: str = None, wikiId: str = None): if userId: - url = f"{api}/x{self.comId}/s/user-profile/{userId}/comment/{commentId}/g-vote?eventSource=UserProfileView" + url = f"/x{self.comId}/s/user-profile/{userId}/comment/{commentId}/g-vote?eventSource=UserProfileView" elif blogId: - url = f"{api}/x{self.comId}/s/blog/{blogId}/comment/{commentId}/g-vote?eventSource=PostDetailView" + url = f"/x{self.comId}/s/blog/{blogId}/comment/{commentId}/g-vote?eventSource=PostDetailView" elif wikiId: - url = f"{api}/x{self.comId}/s/item/{wikiId}/comment/{commentId}/g-vote?eventSource=PostDetailView" + url = f"/x{self.comId}/s/item/{wikiId}/comment/{commentId}/g-vote?eventSource=PostDetailView" else: raise exceptions.SpecifyType() @@ -422,7 +431,7 @@ def upvote_comment(self, blogId: str, commentId: str): "value": "1" } return self.session.post( - url=f"{api}/x{self.comId}/s/blog/{blogId}/comment/{commentId}/vote", + url=f"/x{self.comId}/s/blog/{blogId}/comment/{commentId}/vote", params=params, json=data ).status_code @@ -438,13 +447,13 @@ def downvote_comment(self, blogId: str, commentId: str): } return self.session.post( - url=f"{api}/x{self.comId}/s/blog/{blogId}/comment/{commentId}/vote", + url=f"/x{self.comId}/s/blog/{blogId}/comment/{commentId}/vote", json=data, params=params ).status_code def unvote_comment(self, blogId: str, commentId: str): - response = self.session.delete(f"{api}/x{self.comId}/s/blog/{blogId}/comment/{commentId}/vote?eventSource=PostDetailView") + response = self.session.delete(f"/x{self.comId}/s/blog/{blogId}/comment/{commentId}/vote?eventSource=PostDetailView") return response.status_code def reply_wall(self, userId: str, commentId: str, message: str): @@ -456,7 +465,7 @@ def reply_wall(self, userId: str, commentId: str, message: str): "eventSource": "UserProfileView" } - response = self.session.post(f"{api}/x{self.comId}/s/user-profile/{userId}/comment", json=data) + response = self.session.post(f"/x{self.comId}/s/user-profile/{userId}/comment", json=data) return response.status_code def send_active_obj(self, startTime: int = None, endTime: int = None, @@ -471,7 +480,7 @@ def send_active_obj(self, startTime: int = None, endTime: int = None, } if timers: data["userActiveTimeChunkList"] = timers - response = self.session.post(f"{api}/x{self.comId}/s/community/stats/user-active-time", json=data) + response = self.session.post(f"/x{self.comId}/s/community/stats/user-active-time", json=data) return response.status_code def activity_status(self, status: str): @@ -495,20 +504,18 @@ def activity_status(self, status: str): "duration": 86400 } - response = self.session.post(f"{api}/x{self.comId}/s/user-profile/{self.profile.userId}/online-status", json=data) + response = self.session.post(f"/x{self.comId}/s/user-profile/{self.profile.userId}/online-status", json=data) return response.status_code def check_notifications(self): - response = self.session.post(f"{api}/x{self.comId}/s/notification/checked") - return response.status_code + return self.session.post(f"/x{self.comId}/s/notification/checked").status_code def delete_notification(self, notificationId: str): - response = self.session.delete(f"{api}/x{self.comId}/s/notification/{notificationId}") + response = self.session.delete(f"/x{self.comId}/s/notification/{notificationId}") return response.status_code def clear_notifications(self): - response = self.session.delete(f"{api}/x{self.comId}/s/notification") - return response.status_code + return self.session.delete(f"/x{self.comId}/s/notification").status_code def start_chat(self, userId: Union[str, list, tuple], message: str, title: str = None, content: str = None, isGlobal: bool = False, publishToGlobal: bool = False): @@ -525,13 +532,13 @@ def start_chat(self, userId: Union[str, list, tuple], message: str, title: str = "publishToGlobal": int(publishToGlobal) } - if isGlobal is True: + if isGlobal: data["type"] = 2 data["eventSource"] = "GlobalComposeMenu" else: data["type"] = 0 - response = self.session.post(f"{api}/x{self.comId}/s/chat/thread", json=data) + response = self.session.post(f"/x{self.comId}/s/chat/thread", json=data) return objects.Thread(response.json()["thread"]).Thread def invite_to_chat(self, userId: Union[str, list], chatId: str): @@ -542,12 +549,11 @@ def invite_to_chat(self, userId: Union[str, list], chatId: str): data = { "uids": userIds } - response = self.session.post(f"{api}/x{self.comId}/s/chat/thread/{chatId}/member/invite", json=data) + response = self.session.post(f"/x{self.comId}/s/chat/thread/{chatId}/member/invite", json=data) return response.status_code def add_to_favorites(self, userId: str): - response = self.session.post(f"{api}/x{self.comId}/s/user-group/quick-access/{userId}") - return response.status_code + return self.session.post(f"/x{self.comId}/s/user-group/quick-access/{userId}").status_code def send_coins(self, coins: int, blogId: str = None, chatId: str = None, objectId: str = None, transactionId: str = None): if not transactionId: transactionId = str(uuid4()) @@ -557,12 +563,12 @@ def send_coins(self, coins: int, blogId: str = None, chatId: str = None, objectI "tippingContext": {"transactionId": transactionId} } - if blogId: url = f"{api}/x{self.comId}/s/blog/{blogId}/tipping" - elif chatId: url = f"{api}/x{self.comId}/s/chat/thread/{chatId}/tipping" + if blogId: url = f"/x{self.comId}/s/blog/{blogId}/tipping" + elif chatId: url = f"/x{self.comId}/s/chat/thread/{chatId}/tipping" elif objectId: data["objectId"] = objectId data["objectType"] = 2 - url = f"{api}/x{self.comId}/s/tipping" + url = f"/x{self.comId}/s/tipping" else: raise exceptions.SpecifyType @@ -570,7 +576,7 @@ def send_coins(self, coins: int, blogId: str = None, chatId: str = None, objectI def thank_tip(self, chatId: str, userId: str): return self.session.post( - url=f"{api}/x{self.comId}/s/chat/thread/{chatId}/tipping/tipped-users/{userId}/thank" + url=f"/x{self.comId}/s/chat/thread/{chatId}/tipping/tipped-users/{userId}/thank" ).status_code def follow(self, userId: Union[str, list]): @@ -586,11 +592,11 @@ def follow(self, userId: Union[str, list]): - **Fail** : :meth:`Exceptions ` """ if isinstance(userId, str): - response = self.session.post(f"{api}/x{self.comId}/s/user-profile/{userId}/member") + response = self.session.post(f"/x{self.comId}/s/user-profile/{userId}/member") elif isinstance(userId, list): response = self.session.post( - url=f"{api}/x{self.comId}/s/user-profile/{self.profile.userId}/joined", + url=f"/x{self.comId}/s/user-profile/{self.profile.userId}/joined", json={"targetUidList": userId} ) @@ -610,7 +616,7 @@ def unfollow(self, userId: str): - **Fail** : :meth:`Exceptions ` """ - response = self.session.delete(f"{api}/x{self.comId}/s/user-profile/{self.profile.userId}/joined/{userId}") + response = self.session.delete(f"/x{self.comId}/s/user-profile/{self.profile.userId}/joined/{userId}") return response.status_code def block(self, userId: str): @@ -625,8 +631,7 @@ def block(self, userId: str): - **Fail** : :meth:`Exceptions ` """ - response = self.session.post(f"{api}/x{self.comId}/s/block/{userId}") - return response.status_code + return self.session.post(f"/x{self.comId}/s/block/{userId}").status_code def unblock(self, userId: str): """ @@ -640,8 +645,7 @@ def unblock(self, userId: str): - **Fail** : :meth:`Exceptions ` """ - response = self.session.delete(f"{api}/x{self.comId}/s/block/{userId}") - return response.status_code + return self.session.delete(f"/x{self.comId}/s/block/{userId}").status_code def flag(self, reason: str, flagType: int, userId: str = None, blogId: str = None, wikiId: str = None, @@ -662,8 +666,8 @@ def flag(self, reason: str, flagType: int, - **Fail** : :meth:`Exceptions ` """ - if reason is None: raise exceptions.ReasonNeeded - if flagType is None: raise exceptions.FlagTypeNeeded + if not reason: raise exceptions.ReasonNeeded + if not flagType: raise exceptions.FlagTypeNeeded data = { "flagType": flagType, @@ -687,8 +691,7 @@ def flag(self, reason: str, flagType: int, if asGuest: flg = "g-flag" else: flg = "flag" - response = self.session.post(f"{api}/x{self.comId}/s/{flg}", json=data) - return response.status_code + return self.session.post(f"/x{self.comId}/s/{flg}", json=data).status_code def check_values(self, *args): return any(arg is None for arg in args) @@ -775,7 +778,7 @@ def send_message(self, chatId: str, message: str = None, messageType: int = 0, data["mediaValue"] = url return self.session.post( - url=f"{api}/x{self.comId}/s/chat/thread/{chatId}/message", + url=f"/x{self.comId}/s/chat/thread/{chatId}/message", json=data ).status_code @@ -793,7 +796,7 @@ def full_embed(self, link: str, image: BinaryIO, message: str, chatId: str): "attachedObject": None } - response = self.session.post(f"{api}/x{self.comId}/s/chat/thread/{chatId}/message", json=data) + response = self.session.post(f"/x{self.comId}/s/chat/thread/{chatId}/message", json=data) return response.status_code def delete_message(self, chatId: str, messageId: str, asStaff: bool = False, reason: str = None): @@ -819,9 +822,9 @@ def delete_message(self, chatId: str, messageId: str, asStaff: bool = False, rea data["adminOpNote"] = {"content": reason} if not asStaff: - response = self.session.delete(f"{api}/x{self.comId}/s/chat/thread/{chatId}/message/{messageId}") + response = self.session.delete(f"/x{self.comId}/s/chat/thread/{chatId}/message/{messageId}") else: - response = self.session.post(f"{api}/x{self.comId}/s/chat/thread/{chatId}/message/{messageId}/admin", json=data) + response = self.session.post(f"/x{self.comId}/s/chat/thread/{chatId}/message/{messageId}/admin", json=data) return response.status_code @@ -842,7 +845,7 @@ def mark_as_read(self, chatId: str, messageId: str): "messageId": messageId } - response = self.session.post(f"{api}/x{self.comId}/s/chat/thread/{chatId}/mark-as-read", json=data) + response = self.session.post(f"/x{self.comId}/s/chat/thread/{chatId}/mark-as-read", json=data) return response.status_code def edit_chat(self, chatId: str, doNotDisturb: bool = None, pinChat: bool = None, @@ -852,7 +855,7 @@ def edit_chat(self, chatId: str, doNotDisturb: bool = None, pinChat: bool = None canTip: bool = None, viewOnly: bool = None, canInvite: bool = None, fansOnly: bool = None): """ - Send a Message to a Chat. + Edit a Chat. **Parameters** - **chatId** : ID of the Chat. @@ -874,127 +877,112 @@ def edit_chat(self, chatId: str, doNotDisturb: bool = None, pinChat: bool = None **Returns** - **Success** : 200 (int) - - **Fail** : :meth:`Exceptions ` """ - data = {} - - if title: data["title"] = title - if content: data["content"] = content - if icon: data["icon"] = icon - if keywords: data["keywords"] = keywords - if announcement: data["extensions"] = {"announcement": announcement} - if pinAnnouncement: data["extensions"] = {"pinAnnouncement": pinAnnouncement} - if fansOnly: data["extensions"] = {"fansOnly": fansOnly} - - if publishToGlobal: data["publishToGlobal"] = 0 - if not publishToGlobal: data["publishToGlobal"] = 1 - + data = self._prepare_data(title, content, icon, keywords, announcement, pinAnnouncement, fansOnly, publishToGlobal) res = [] - if doNotDisturb is not None: - if doNotDisturb: - data = {"alertOption": 2 } - - response = self.session.post( - url=f"{api}/x{self.comId}/s/chat/thread/{chatId}/member/{self.profile.userId}/alert", - json=data - ) - res.append(response.status_code) - - else: - data = {"alertOption": 1 } - - response = self.session.post( - url=f"{api}/x{self.comId}/s/chat/thread/{chatId}/member/{self.profile.userId}/alert", - json=data - ) - res.append(response.status_code) - - if pinChat is not None: - if pinChat: - response = self.session.post( - url=f"{api}/x{self.comId}/s/chat/thread/{chatId}/pin", - json=data - ) - res.append(response.status_code) - - else: - response = self.session.post( - url=f"{api}/x{self.comId}/s/chat/thread/{chatId}/unpin", - json=data - ) - res.append(response.status_code) - - if backgroundImage is not None: - data = {"media": [100, backgroundImage, None] } - - response = self.session.post( - url=f"{api}/x{self.comId}/s/chat/thread/{chatId}/member/{self.profile.userId}/background", - json=data - ) - res.append(response.status_code) + res.extend(self._set_do_not_disturb(chatId, doNotDisturb)) + res.extend(self._pin_chat(chatId, pinChat)) + res.extend(self._set_background_image(chatId, backgroundImage)) + res.extend(self._set_co_hosts(chatId, coHosts)) + res.extend(self._set_view_only(chatId, viewOnly)) + res.extend(self._set_can_invite(chatId, canInvite)) + res.extend(self._set_can_tip(chatId, canTip)) - if coHosts is not None: - data = {"uidList": coHosts } - - response = self.session.post( - url=f"{api}/x{self.comId}/s/chat/thread/{chatId}/co-host", - json=data - ) - res.append(response.status_code) - - if viewOnly is not None: - if viewOnly: - response = self.session.post( - url=f"{api}/x{self.comId}/s/chat/thread/{chatId}/view-only/enable" - ) - res.append(response.status_code) - - else: - response = self.session.post( - url=f"{api}/x{self.comId}/s/chat/thread/{chatId}/view-only/disable" - ) - res.append(response.status_code) - - if canInvite is not None: - if canInvite: - response = self.session.post( - url=f"{api}/x{self.comId}/s/chat/thread/{chatId}/members-can-invite/enable", - json=data - ) - res.append(response.status_code) - - else: - response = self.session.post( - url=f"{api}/x{self.comId}/s/chat/thread/{chatId}/members-can-invite/disable", - json=data - ) - res.append(response.status_code) - - if canTip is not None: - if canTip: - response = self.session.post( - url=f"{api}/x{self.comId}/s/chat/thread/{chatId}/tipping-perm-status/enable", - json=data - ) - res.append(response.status_code) - - else: - response = self.session.post( - url=f"{api}/x{self.comId}/s/chat/thread/{chatId}/tipping-perm-status/disable", - json=data - ) - res.append(response.status_code) - - response = self.session.post(f"{api}/x{self.comId}/s/chat/thread/{chatId}", json=data) + response = self.session.post(f"/x{self.comId}/s/chat/thread/{chatId}", json=data) res.append(response.status_code) return res + def _prepare_data(self, title, content, icon, keywords, announcement, pinAnnouncement, fansOnly, publishToGlobal): + data = {} + if title: data["title"] = title + if content: data["content"] = content + if icon: data["icon"] = icon + if keywords: data["keywords"] = keywords + extensions = {} + if announcement: extensions["announcement"] = announcement + if pinAnnouncement: extensions["pinAnnouncement"] = pinAnnouncement + if fansOnly: extensions["fansOnly"] = fansOnly + if extensions: data["extensions"] = extensions + if publishToGlobal is not None: + data["publishToGlobal"] = 0 if publishToGlobal else 1 + return data + + def _set_do_not_disturb(self, chatId, doNotDisturb): + if doNotDisturb is None: + return [] + alertOption = 2 if doNotDisturb else 1 + data = {"alertOption": alertOption} + response = self.session.post( + url=f"/x{self.comId}/s/chat/thread/{chatId}/member/{self.profile.userId}/alert", + json=data + ) + return [response.status_code] + + def _pin_chat(self, chatId, pinChat): + if pinChat is None: + return [] + url_suffix = "pin" if pinChat else "unpin" + response = self.session.post( + url=f"/x{self.comId}/s/chat/thread/{chatId}/{url_suffix}", + json={} + ) + return [response.status_code] + + def _set_background_image(self, chatId, backgroundImage): + if not backgroundImage: + return [] + data = {"media": [100, backgroundImage, None]} + response = self.session.post( + url=f"/x{self.comId}/s/chat/thread/{chatId}/member/{self.profile.userId}/background", + json=data + ) + return [response.status_code] + + def _set_co_hosts(self, chatId, coHosts): + if coHosts is None: + return [] + data = {"uidList": coHosts} + response = self.session.post( + url=f"/x{self.comId}/s/chat/thread/{chatId}/co-host", + json=data + ) + return [response.status_code] + + def _set_view_only(self, chatId, viewOnly): + if viewOnly is None: + return [] + url_suffix = "enable" if viewOnly else "disable" + response = self.session.post( + url=f"/x{self.comId}/s/chat/thread/{chatId}/view-only/{url_suffix}" + ) + return [response.status_code] + + def _set_can_invite(self, chatId, canInvite): + if canInvite is None: + return [] + url_suffix = "enable" if canInvite else "disable" + response = self.session.post( + url=f"/x{self.comId}/s/chat/thread/{chatId}/members-can-invite/{url_suffix}", + json={} + ) + return [response.status_code] + + def _set_can_tip(self, chatId, canTip): + if canTip is None: + return [] + url_suffix = "enable" if canTip else "disable" + response = self.session.post( + url=f"/x{self.comId}/s/chat/thread/{chatId}/tipping-perm-status/{url_suffix}", + json={} + ) + return [response.status_code] + def transfer_host(self, chatId: str, userIds: list): return self.session.post( - url=f"{api}/x{self.comId}/s/chat/thread/{chatId}/transfer-organizer", + url=f"/x{self.comId}/s/chat/thread/{chatId}/transfer-organizer", json={"uidList": userIds} ).status_code @@ -1014,7 +1002,7 @@ def accept_host(self, chatId: str, requestId: str): - **Fail** : :meth:`Exceptions ` """ return self.session.post( - url=f"{api}/x{self.comId}/s/chat/thread/{chatId}/transfer-organizer/{requestId}/accept" + url=f"/x{self.comId}/s/chat/thread/{chatId}/transfer-organizer/{requestId}/accept" ).status_code def accept_organizer(self, chatId: str, requestId: str): @@ -1048,7 +1036,7 @@ def kick(self, userId: str, chatId: str, allowRejoin: bool = True): params = {"allowRejoin": int(allowRejoin)} return self.session.delete( - url=f"{api}/x{self.comId}/s/chat/thread/{chatId}/member/{userId}", + url=f"/x{self.comId}/s/chat/thread/{chatId}/member/{userId}", params=params ).status_code @@ -1064,7 +1052,7 @@ def join_chat(self, chatId: str): - **Fail** : :meth:`Exceptions ` """ - response = self.session.post(f"{api}/x{self.comId}/s/chat/thread/{chatId}/member/{self.profile.userId}") + response = self.session.post(f"/x{self.comId}/s/chat/thread/{chatId}/member/{self.profile.userId}") return response.status_code def leave_chat(self, chatId: str): @@ -1079,7 +1067,7 @@ def leave_chat(self, chatId: str): - **Fail** : :meth:`Exceptions ` """ - response = self.session.delete(f"{api}/x{self.comId}/s/chat/thread/{chatId}/member/{self.profile.userId}") + response = self.session.delete(f"/x{self.comId}/s/chat/thread/{chatId}/member/{self.profile.userId}") return response.status_code def delete_chat(self, chatId: str): @@ -1094,8 +1082,7 @@ def delete_chat(self, chatId: str): - **Fail** : :meth:`Exceptions ` """ - response = self.session.delete(f"{api}/x{self.comId}/s/chat/thread/{chatId}") - return response.status_code + return self.session.delete(f"/x{self.comId}/s/chat/thread/{chatId}").status_code def subscribe(self, userId: str, autoRenew: str = False, transactionId: str = None): if transactionId is None: transactionId = str(uuid4()) @@ -1107,12 +1094,11 @@ def subscribe(self, userId: str, autoRenew: str = False, transactionId: str = No } } - response = self.session.post(f"{api}/x{self.comId}/s/influencer/{userId}/subscribe", json=data) + response = self.session.post(f"/x{self.comId}/s/influencer/{userId}/subscribe", json=data) return response.status_code def promotion(self, noticeId: str, type: str = "accept"): - response = self.session.post(f"{api}/x{self.comId}/s/notice/{noticeId}/{type}") - return response.status_code + return self.session.post(f"/x{self.comId}/s/notice/{noticeId}/{type}").status_code def play_quiz_raw(self, quizId: str, quizAnswerList: list, quizMode: int = 0): data = { @@ -1120,7 +1106,7 @@ def play_quiz_raw(self, quizId: str, quizAnswerList: list, quizMode: int = 0): "quizAnswerList": quizAnswerList } - response = self.session.post(f"{api}/x{self.comId}/s/blog/{quizId}/quiz/result", json=data) + response = self.session.post(f"/x{self.comId}/s/blog/{quizId}/quiz/result", json=data) return response.status_code def play_quiz(self, quizId: str, questionIdsList: list, answerIdsList: list, quizMode: int = 0): @@ -1139,7 +1125,7 @@ def play_quiz(self, quizId: str, questionIdsList: list, answerIdsList: list, qui "mode": quizMode, "quizAnswerList": quizAnswerList } - response = self.session.post(f"{api}/x{self.comId}/s/blog/{quizId}/quiz/result", json=data) + response = self.session.post(f"/x{self.comId}/s/blog/{quizId}/quiz/result", json=data) return response.status_code def vc_permission(self, chatId: str, permission: int): @@ -1150,16 +1136,16 @@ def vc_permission(self, chatId: str, permission: int): """ data = { "vvChatJoinType": permission } return self.session.post( - url=f"{api}/x{self.comId}/s/chat/thread/{chatId}/vvchat-permission", + url=f"/x{self.comId}/s/chat/thread/{chatId}/vvchat-permission", json=data ).status_code def get_vc_reputation_info(self, chatId: str): - response = self.session.get(f"{api}/x{self.comId}/s/chat/thread/{chatId}/avchat-reputation") + response = self.session.get(f"/x{self.comId}/s/chat/thread/{chatId}/avchat-reputation") return objects.VcReputation(response.json()).VcReputation def claim_vc_reputation(self, chatId: str): - response = self.session.post(f"{api}/x{self.comId}/s/chat/thread/{chatId}/avchat-reputation") + response = self.session.post(f"/x{self.comId}/s/chat/thread/{chatId}/avchat-reputation") return objects.VcReputation(response.json()).VcReputation def get_all_users(self, type: str = "recent", start: int = 0, size: int = 25): @@ -1168,15 +1154,15 @@ def get_all_users(self, type: str = "recent", start: int = 0, size: int = 25): if type not in types: raise exceptions.WrongType(type) - response = self.session.get(f"{api}/x{self.comId}/s/user-profile?type={type}&start={start}&size={size}") + response = self.session.get(f"/x{self.comId}/s/user-profile?type={type}&start={start}&size={size}") return objects.UserProfileCountList(response.json()).UserProfileCountList def get_online_users(self, start: int = 0, size: int = 25): - response = self.session.get(f"{api}/x{self.comId}/s/live-layer?topic=ndtopic:x{self.comId}:online-members&start={start}&size={size}") + response = self.session.get(f"/x{self.comId}/s/live-layer?topic=ndtopic:x{self.comId}:online-members&start={start}&size={size}") return objects.UserProfileCountList(response.json()).UserProfileCountList def get_online_favorite_users(self, start: int = 0, size: int = 25): - response = self.session.get(f"{api}/x{self.comId}/s/user-group/quick-access?type=online&start={start}&size={size}") + response = self.session.get(f"/x{self.comId}/s/user-group/quick-access?type=online&start={start}&size={size}") return objects.UserProfileCountList(response.json()).UserProfileCountList def get_user_info(self, userId: str): @@ -1191,7 +1177,7 @@ def get_user_info(self, userId: str): - **Fail** : :meth:`Exceptions ` """ - response = self.session.get(f"{api}/x{self.comId}/s/user-profile/{userId}") + response = self.session.get(f"/x{self.comId}/s/user-profile/{userId}") return objects.UserProfile(response.json()["userProfile"]).UserProfile def get_user_following(self, userId: str, start: int = 0, size: int = 25): @@ -1208,7 +1194,7 @@ def get_user_following(self, userId: str, start: int = 0, size: int = 25): - **Fail** : :meth:`Exceptions ` """ - response = self.session.get(f"{api}/x{self.comId}/s/user-profile/{userId}/joined?start={start}&size={size}") + response = self.session.get(f"/x{self.comId}/s/user-profile/{userId}/joined?start={start}&size={size}") return objects.UserProfileList(response.json()["userProfileList"]).UserProfileList def get_user_followers(self, userId: str, start: int = 0, size: int = 25): @@ -1225,27 +1211,27 @@ def get_user_followers(self, userId: str, start: int = 0, size: int = 25): - **Fail** : :meth:`Exceptions ` """ - response = self.session.get(f"{api}/x{self.comId}/s/user-profile/{userId}/member?start={start}&size={size}") + response = self.session.get(f"/x{self.comId}/s/user-profile/{userId}/member?start={start}&size={size}") return objects.UserProfileList(response.json()["userProfileList"]).UserProfileList def get_user_checkins(self, userId: str): - response = self.session.get(f"{api}/x{self.comId}/s/check-in/stats/{userId}?timezone={timezone // 1000}") + response = self.session.get(f"/x{self.comId}/s/check-in/stats/{userId}?timezone={timezone // 1000}") return objects.UserCheckIns(response.json()).UserCheckIns def get_user_blogs(self, userId: str, start: int = 0, size: int = 25): - response = self.session.get(f"{api}/x{self.comId}/s/blog?type=user&q={userId}&start={start}&size={size}") + response = self.session.get(f"/x{self.comId}/s/blog?type=user&q={userId}&start={start}&size={size}") return objects.BlogList(response.json()["blogList"]).BlogList def get_user_wikis(self, userId: str, start: int = 0, size: int = 25): - response = self.session.get(f"{api}/x{self.comId}/s/item?type=user-all&start={start}&size={size}&cv=1.2&uid={userId}") + response = self.session.get(f"/x{self.comId}/s/item?type=user-all&start={start}&size={size}&cv=1.2&uid={userId}") return objects.WikiList(response.json()["itemList"]).WikiList def get_user_achievements(self, userId: str): - response = self.session.get(f"{api}/x{self.comId}/s/user-profile/{userId}/achievements") + response = self.session.get(f"/x{self.comId}/s/user-profile/{userId}/achievements") return objects.UserAchievements(response.json()["achievements"]).UserAchievements def get_influencer_fans(self, userId: str, start: int = 0, size: int = 25): - response = self.session.get(f"{api}/x{self.comId}/s/influencer/{userId}/fans?start={start}&size={size}") + response = self.session.get(f"/x{self.comId}/s/influencer/{userId}/fans?start={start}&size={size}") return objects.InfluencerFans(response.json()).InfluencerFans def get_blocked_users(self, start: int = 0, size: int = 25): @@ -1261,7 +1247,7 @@ def get_blocked_users(self, start: int = 0, size: int = 25): - **Fail** : :meth:`Exceptions ` """ - response = self.session.get(f"{api}/x{self.comId}/s/block?start={start}&size={size}") + response = self.session.get(f"/x{self.comId}/s/block?start={start}&size={size}") return objects.UserProfileList(response.json()["userProfileList"]).UserProfileList def get_blocker_users(self, start: int = 0, size: int = 25): @@ -1278,15 +1264,15 @@ def get_blocker_users(self, start: int = 0, size: int = 25): - **Fail** : :meth:`Exceptions ` """ - response = self.session.get(f"{api}/x{self.comId}/s/block?start={start}&size={size}") + response = self.session.get(f"/x{self.comId}/s/block?start={start}&size={size}") return response.json()["blockerUidList"] def search_users(self, nickname: str, start: int = 0, size: int = 25): - response = self.session.get(f"{api}/x{self.comId}/s/user-profile?type=name&q={nickname}&start={start}&size={size}") + response = self.session.get(f"/x{self.comId}/s/user-profile?type=name&q={nickname}&start={start}&size={size}") return objects.UserProfileList(response.json()["userProfileList"]).UserProfileList def get_saved_blogs(self, start: int = 0, size: int = 25): - response = self.session.get(f"{api}/x{self.comId}/s/bookmark?start={start}&size={size}") + response = self.session.get(f"/x{self.comId}/s/bookmark?start={start}&size={size}") return objects.UserSavedBlogs(response.json()["bookmarkList"]).UserSavedBlogs def get_leaderboard_info(self, type: str, start: int = 0, size: int = 25): @@ -1304,36 +1290,35 @@ def get_leaderboard_info(self, type: str, start: int = 0, size: int = 25): raise exceptions.WrongType(type) ranking_type = ranking_types[type] - url = f"{api}/g/s-x{self.comId}/community/leaderboard?rankingType={ranking_type}&start={start}" + url = f"/g/s-x{self.comId}/community/leaderboard?rankingType={ranking_type}&start={start}" if ranking_type != 4: url += f"&size={size}" response = self.session.get(url) return objects.UserProfileList(response.json()["userProfileList"]).UserProfileList - def get_wiki_info(self, wikiId: str): - response = self.session.get(f"{api}/x{self.comId}/s/item/{wikiId}") + response = self.session.get(f"/x{self.comId}/s/item/{wikiId}") return objects.GetWikiInfo(response.json()).GetWikiInfo def get_recent_wiki_items(self, start: int = 0, size: int = 25): - response = self.session.get(f"{api}/x{self.comId}/s/item?type=catalog-all&start={start}&size={size}") + response = self.session.get(f"/x{self.comId}/s/item?type=catalog-all&start={start}&size={size}") return objects.WikiList(response.json()["itemList"]).WikiList def get_wiki_categories(self, start: int = 0, size: int = 25): - response = self.session.get(f"{api}/x{self.comId}/s/item-category?start={start}&size={size}") + response = self.session.get(f"/x{self.comId}/s/item-category?start={start}&size={size}") return objects.WikiCategoryList(response.json()["itemCategoryList"]).WikiCategoryList def get_wiki_category(self, categoryId: str, start: int = 0, size: int = 25): - response = self.session.get(f"{api}/x{self.comId}/s/item-category/{categoryId}?pagingType=t&start={start}&size={size}") + response = self.session.get(f"/x{self.comId}/s/item-category/{categoryId}?pagingType=t&start={start}&size={size}") return objects.WikiCategory(response.json()).WikiCategory def get_tipped_users(self, blogId: str = None, wikiId: str = None, quizId: str = None, fileId: str = None, chatId: str = None, start: int = 0, size: int = 25): object_types = { - 'blogId': {'id': blogId or quizId, 'url': f"{api}/x{self.comId}/s/blog/{blogId or quizId}/tipping/tipped-users-summary"}, - 'wikiId': {'id': wikiId, 'url': f"{api}/x{self.comId}/s/item/{wikiId}/tipping/tipped-users-summary"}, - 'chatId': {'id': chatId, 'url': f"{api}/x{self.comId}/s/chat/thread/{chatId}/tipping/tipped-users-summary"}, - 'fileId': {'id': fileId, 'url': f"{api}/x{self.comId}/s/shared-folder/files/{fileId}/tipping/tipped-users-summary"} + 'blogId': {'id': blogId or quizId, 'url': f"/x{self.comId}/s/blog/{blogId or quizId}/tipping/tipped-users-summary"}, + 'wikiId': {'id': wikiId, 'url': f"/x{self.comId}/s/item/{wikiId}/tipping/tipped-users-summary"}, + 'chatId': {'id': chatId, 'url': f"/x{self.comId}/s/chat/thread/{chatId}/tipping/tipped-users-summary"}, + 'fileId': {'id': fileId, 'url': f"/x{self.comId}/s/shared-folder/files/{fileId}/tipping/tipped-users-summary"} } for key, value in object_types.items(): @@ -1359,7 +1344,7 @@ def get_chat_threads(self, start: int = 0, size: int = 25): - **Fail** : :meth:`Exceptions ` """ - response = self.session.get(f"{api}/x{self.comId}/s/chat/thread?type=joined-me&start={start}&size={size}") + response = self.session.get(f"/x{self.comId}/s/chat/thread?type=joined-me&start={start}&size={size}") return objects.ThreadList(response.json()["threadList"]).ThreadList def get_public_chat_threads(self, type: str = "recommended", start: int = 0, size: int = 25): @@ -1375,7 +1360,7 @@ def get_public_chat_threads(self, type: str = "recommended", start: int = 0, siz - **Fail** : :meth:`Exceptions ` """ - response = self.session.get(f"{api}/x{self.comId}/s/chat/thread?type=public-all&filterType={type}&start={start}&size={size}") + response = self.session.get(f"/x{self.comId}/s/chat/thread?type=public-all&filterType={type}&start={start}&size={size}") return objects.ThreadList(response.json()["threadList"]).ThreadList def get_chat_thread(self, chatId: str): @@ -1390,7 +1375,7 @@ def get_chat_thread(self, chatId: str): - **Fail** : :meth:`Exceptions ` """ - response = self.session.get(f"{api}/x{self.comId}/s/chat/thread/{chatId}") + response = self.session.get(f"/x{self.comId}/s/chat/thread/{chatId}") return objects.Thread(response.json()["thread"]).Thread def get_chat_messages(self, chatId: str, size: int = 25, pageToken: str = None): @@ -1408,11 +1393,10 @@ def get_chat_messages(self, chatId: str, size: int = 25, pageToken: str = None): - **Fail** : :meth:`Exceptions ` """ - if pageToken: url = f"{api}/x{self.comId}/s/chat/thread/{chatId}/message?v=2&pagingType=t&pageToken={pageToken}&size={size}" - else: url = f"{api}/x{self.comId}/s/chat/thread/{chatId}/message?v=2&pagingType=t&size={size}" + if pageToken: url = f"/x{self.comId}/s/chat/thread/{chatId}/message?v=2&pagingType=t&pageToken={pageToken}&size={size}" + else: url = f"/x{self.comId}/s/chat/thread/{chatId}/message?v=2&pagingType=t&size={size}" - response = self.session.get(url) - return objects.GetMessages(response.json()).GetMessages + return objects.GetMessages(self.session.get(url).json()).GetMessages def get_message_info(self, chatId: str, messageId: str): """ @@ -1427,21 +1411,21 @@ def get_message_info(self, chatId: str, messageId: str): - **Fail** : :meth:`Exceptions ` """ - response = self.session.get(f"{api}/x{self.comId}/s/chat/thread/{chatId}/message/{messageId}") + response = self.session.get(f"/x{self.comId}/s/chat/thread/{chatId}/message/{messageId}") return objects.Message(response.json()["message"]).Message def get_blog_info(self, blogId: str = None, wikiId: str = None, quizId: str = None, fileId: str = None): if blogId or quizId: if quizId is not None: blogId = quizId - response = self.session.get(f"{api}/x{self.comId}/s/blog/{blogId}") + response = self.session.get(f"/x{self.comId}/s/blog/{blogId}") return objects.GetBlogInfo(response.json()).GetBlogInfo elif wikiId: - response = self.session.get(f"{api}/x{self.comId}/s/item/{wikiId}") + response = self.session.get(f"/x{self.comId}/s/item/{wikiId}") return objects.GetWikiInfo(response.json()).GetWikiInfo elif fileId: - response = self.session.get(f"{api}/x{self.comId}/s/shared-folder/files/{fileId}") + response = self.session.get(f"/x{self.comId}/s/shared-folder/files/{fileId}") return objects.SharedFolderFile(response.json()["file"]).SharedFolderFile else: raise exceptions.SpecifyType @@ -1453,9 +1437,9 @@ def get_blog_comments(self, blogId: str = None, wikiId: str = None, quizId: str sorting = "vote" if sorting == "top" else sorting object_types = { - 'blogId': {'id': blogId or quizId, 'url': f"{api}/x{self.comId}/s/blog/{blogId or quizId}/comment"}, - 'wikiId': {'id': wikiId, 'url': f"{api}/x{self.comId}/s/item/{wikiId}/comment"}, - 'fileId': {'id': fileId, 'url': f"{api}/x{self.comId}/s/shared-folder/files/{fileId}/comment"} + 'blogId': {'id': blogId or quizId, 'url': f"/x{self.comId}/s/blog/{blogId or quizId}/comment"}, + 'wikiId': {'id': wikiId, 'url': f"/x{self.comId}/s/item/{wikiId}/comment"}, + 'fileId': {'id': fileId, 'url': f"/x{self.comId}/s/shared-folder/files/{fileId}/comment"} } for key, value in object_types.items(): @@ -1469,15 +1453,15 @@ def get_blog_comments(self, blogId: str = None, wikiId: str = None, quizId: str def get_blog_categories(self, size: int = 25): - response = self.session.get(f"{api}/x{self.comId}/s/blog-category?size={size}") + response = self.session.get(f"/x{self.comId}/s/blog-category?size={size}") return objects.BlogCategoryList(response.json()["blogCategoryList"]).BlogCategoryList def get_blogs_by_category(self, categoryId: str,start: int = 0, size: int = 25): - response = self.session.get(f"{api}/x{self.comId}/s/blog-category/{categoryId}/blog-list?start={start}&size={size}") + response = self.session.get(f"/x{self.comId}/s/blog-category/{categoryId}/blog-list?start={start}&size={size}") return objects.BlogList(response.json()["blogList"]).BlogList def get_quiz_rankings(self, quizId: str, start: int = 0, size: int = 25): - response = self.session.get(f"{api}/x{self.comId}/s/blog/{quizId}/quiz/result?start={start}&size={size}") + response = self.session.get(f"/x{self.comId}/s/blog/{quizId}/quiz/result?start={start}&size={size}") return objects.QuizRankings(response.json()).QuizRankings def get_wall_comments(self, userId: str, sorting: str, start: int = 0, size: int = 25): @@ -1501,7 +1485,7 @@ def get_wall_comments(self, userId: str, sorting: str, start: int = 0, size: int elif sorting == "top": sorting = "vote" else: raise exceptions.WrongType(sorting) - response = self.session.get(f"{api}/x{self.comId}/s/user-profile/{userId}/comment?sort={sorting}&start={start}&size={size}") + response = self.session.get(f"/x{self.comId}/s/user-profile/{userId}/comment?sort={sorting}&start={start}&size={size}") return objects.CommentList(response.json()["commentList"]).CommentList def get_recent_blogs(self, pageToken: str = None, start: int = 0, size: int = 25): @@ -1513,7 +1497,7 @@ def get_recent_blogs(self, pageToken: str = None, start: int = 0, size: int = 25 if pageToken: params["pageToken"] = pageToken - response = self.session.get(f"{api}/x{self.comId}/s/feed/blog-all", params=params) + response = self.session.get(f"/x{self.comId}/s/feed/blog-all", params=params) return objects.RecentBlogs(response.json()).RecentBlogs def get_chat_users(self, chatId: str, start: int = 0, size: int = 25): @@ -1535,11 +1519,11 @@ def get_chat_users(self, chatId: str, start: int = 0, size: int = 25): "type": "default", "cv": "1.2" } - response = self.session.get(f"{api}/x{self.comId}/s/chat/thread/{chatId}/member", params=params) + response = self.session.get(f"/x{self.comId}/s/chat/thread/{chatId}/member", params=params) return objects.UserProfileList(response.json()["memberList"]).UserProfileList def get_notifications(self, start: int = 0, size: int = 25): - response = self.session.get(f"{api}/x{self.comId}/s/notification?pagingType=t&start={start}&size={size}") + response = self.session.get(f"/x{self.comId}/s/notification?pagingType=t&start={start}&size={size}") return objects.NotificationList(response.json()["notificationList"]).NotificationList def get_notices(self, start: int = 0, size: int = 25): @@ -1548,15 +1532,15 @@ def get_notices(self, start: int = 0, size: int = 25): :param size: Amount of Notices to Show :return: Notices List """ - response = self.session.get(f"{api}/x{self.comId}/s/notice?type=usersV2&status=1&start={start}&size={size}") + response = self.session.get(f"/x{self.comId}/s/notice?type=usersV2&status=1&start={start}&size={size}") return objects.NoticeList(response.json()["noticeList"]).NoticeList def get_sticker_pack_info(self, sticker_pack_id: str): - response = self.session.get(f"{api}/x{self.comId}/s/sticker-collection/{sticker_pack_id}?includeStickers=true") + response = self.session.get(f"/x{self.comId}/s/sticker-collection/{sticker_pack_id}?includeStickers=true") return objects.StickerCollection(response.json()["stickerCollection"]).StickerCollection def get_sticker_packs(self): - response = self.session.get(f"{api}/x{self.comId}/s/sticker-collection?includeStickers=false&type=my-active-collection") + response = self.session.get(f"/x{self.comId}/s/sticker-collection?includeStickers=false&type=my-active-collection") return objects.StickerCollection(response.json()["stickerCollection"]).StickerCollection def get_store_chat_bubbles(self, start: int = 0, size: int = 25): @@ -1565,9 +1549,8 @@ def get_store_chat_bubbles(self, start: int = 0, size: int = 25): "start": start, "size": size } - response = self.session.get(f"{api}/x{self.comId}/s/store/items", params=params) + response = self.session.get(f"/x{self.comId}/s/store/items", params=params) return objects.StoreChatBubble(response.json()).StoreChatBubble - # return response.text # TODO : Finish this def get_store_stickers(self, start: int = 0, size: int = 25): @@ -1576,31 +1559,25 @@ def get_store_stickers(self, start: int = 0, size: int = 25): "start": start, "size": size } - response = self.session.get(f"{api}/x{self.comId}/s/store/items", params=params) - return response.json() + + return self.session.get(f"/x{self.comId}/s/store/items", params=params).json() def get_community_stickers(self): - params = { - "type": "community-shared" - } response = self.session.get( - url=f"{api}/x{self.comId}/s/sticker-collection", - paams=params + url=f"/x{self.comId}/s/sticker-collection", + paams={ "type": "community-shared" } ) return objects.CommunityStickerCollection(response.json()).CommunityStickerCollection def get_sticker_collection(self, collectionId: str): - params = { - "includeStickers": True - } response = self.session.get( - url=f"{api}/x{self.comId}/s/sticker-collection/{collectionId}", - parmas=params + url=f"/x{self.comId}/s/sticker-collection/{collectionId}", + parmas={ "includeStickers": True } ) return objects.StickerCollection(response.json()["stickerCollection"]).StickerCollection def get_shared_folder_info(self): - response = self.session.get(f"{api}/x{self.comId}/s/shared-folder/stats") + response = self.session.get(f"/x{self.comId}/s/shared-folder/stats") return objects.GetSharedFolderInfo(response.json()["stats"]).GetSharedFolderInfo def get_shared_folder_files(self, type: str = "latest", start: int = 0, size: int = 25): @@ -1609,7 +1586,7 @@ def get_shared_folder_files(self, type: str = "latest", start: int = 0, size: in "start": start, "size": size } - response = self.session.get(f"{api}/x{self.comId}/s/shared-folder/files", params=params) + response = self.session.get(f"/x{self.comId}/s/shared-folder/files", params=params) return objects.SharedFolderFileList(response.json()["fileList"]).SharedFolderFileList # @@ -1617,14 +1594,14 @@ def get_shared_folder_files(self, type: str = "latest", start: int = 0, size: in # def moderation_history(self, userId: str = None, blogId: str = None, wikiId: str = None, quizId: str = None, fileId: str = None, size: int = 25): - types = {'userId': 0, 'blogId': 1, 'wikiId': 2, 'quizId': 1, 'fileId': 109} + types = {"userId": 0, "blogId": 1, "wikiId": 2, "quizId": 1, "fileId": 109} ids = (userId, blogId, wikiId, quizId, fileId) for id, type in zip(ids, types.values()): if id: - url = f"{api}/x{self.comId}/s/admin/operation?objectId={id}&objectType={type}&pagingType=t&size={size}" + url = f"/x{self.comId}/s/admin/operation?objectId={id}&objectType={type}&pagingType=t&size={size}" break else: - url = f"{api}/x{self.comId}/s/admin/operation?pagingType=t&size={size}" + url = f"/x{self.comId}/s/admin/operation?pagingType=t&size={size}" return objects.AdminLogList(self.session.get(url).json()["adminLogList"]).AdminLogList def feature(self, time: int, userId: str = None, chatId: str = None, blogId: str = None, wikiId: str = None): @@ -1640,7 +1617,7 @@ def feature(self, time: int, userId: str = None, chatId: str = None, blogId: str } } - url = f"{api}/x{self.comId}/s/" + url = f"/x{self.comId}/s/" if userId: url += f"user-profile/{userId}/admin" elif blogId: @@ -1649,7 +1626,7 @@ def feature(self, time: int, userId: str = None, chatId: str = None, blogId: str url += f"item/{wikiId}/admin" elif chatId: url += f"chat/thread/{chatId}/admin" - else: + else: raise exceptions.SpecifyType return self.session.post(url, json=data).json() @@ -1661,16 +1638,16 @@ def unfeature(self, userId: str = None, chatId: str = None, blogId: str = None, } if userId: - url = f"{api}/x{self.comId}/s/user-profile/{userId}/admin" + url = f"/x{self.comId}/s/user-profile/{userId}/admin" elif blogId: - url = f"{api}/x{self.comId}/s/blog/{blogId}/admin" + url = f"/x{self.comId}/s/blog/{blogId}/admin" elif wikiId: - url = f"{api}/x{self.comId}/s/item/{wikiId}/admin" + url = f"/x{self.comId}/s/item/{wikiId}/admin" elif chatId: - url = f"{api}/x{self.comId}/s/chat/thread/{chatId}/admin" + url = f"/x{self.comId}/s/chat/thread/{chatId}/admin" else: raise exceptions.SpecifyType @@ -1686,34 +1663,34 @@ def hide(self, userId: str = None, chatId: str = None, blogId: str = None, wikiI if userId: data["adminOpName"] = 18 - url = f"{api}/x{self.comId}/s/user-profile/{userId}/admin" + url = f"/x{self.comId}/s/user-profile/{userId}/admin" elif blogId: data["adminOpName"] = 110 data["adminOpValue"] = 9 - url = f"{api}/x{self.comId}/s/blog/{blogId}/admin" + url = f"/x{self.comId}/s/blog/{blogId}/admin" elif quizId: data["adminOpName"] = 110 data["adminOpValue"] = 9 - url = f"{api}/x{self.comId}/s/blog/{quizId}/admin" + url = f"/x{self.comId}/s/blog/{quizId}/admin" elif wikiId: data["adminOpName"] = 110 data["adminOpValue"] = 9 - url = f"{api}/x{self.comId}/s/item/{wikiId}/admin" + url = f"/x{self.comId}/s/item/{wikiId}/admin" elif chatId: data["adminOpName"] = 110 data["adminOpValue"] = 9 - url = f"{api}/x{self.comId}/s/chat/thread/{chatId}/admin" + url = f"/x{self.comId}/s/chat/thread/{chatId}/admin" elif fileId: data["adminOpName"] = 110 data["adminOpValue"] = 9 - url = f"{api}/x{self.comId}/s/shared-folder/files/{fileId}/admin" + url = f"/x{self.comId}/s/shared-folder/files/{fileId}/admin" else: raise exceptions.SpecifyType @@ -1728,37 +1705,37 @@ def unhide(self, userId: str = None, chatId: str = None, blogId: str = None, wik if userId: data["adminOpName"] = 19 - url = f"{api}/x{self.comId}/s/user-profile/{userId}/admin" + url = f"/x{self.comId}/s/user-profile/{userId}/admin" elif blogId: data["adminOpName"] = 110 data["adminOpValue"] = 0 - url = f"{api}/x{self.comId}/s/blog/{blogId}/admin" + url = f"/x{self.comId}/s/blog/{blogId}/admin" elif quizId: data["adminOpName"] = 110 data["adminOpValue"] = 0 - url = f"{api}/x{self.comId}/s/blog/{quizId}/admin" + url = f"/x{self.comId}/s/blog/{quizId}/admin" elif wikiId: data["adminOpName"] = 110 data["adminOpValue"] = 0 - url = f"{api}/x{self.comId}/s/item/{wikiId}/admin" + url = f"/x{self.comId}/s/item/{wikiId}/admin" elif chatId: data["adminOpName"] = 110 data["adminOpValue"] = 0 - url = f"{api}/x{self.comId}/s/chat/thread/{chatId}/admin" + url = f"/x{self.comId}/s/chat/thread/{chatId}/admin" elif fileId: data["adminOpName"] = 110 data["adminOpValue"] = 0 - url = f"{api}/x{self.comId}/s/shared-folder/files/{fileId}/admin" + url = f"/x{self.comId}/s/shared-folder/files/{fileId}/admin" else: raise exceptions.SpecifyType @@ -1773,8 +1750,7 @@ def edit_titles(self, userId: str, tlt: list): } } - response = self.session.post(f"{api}/x{self.comId}/s/user-profile/{userId}/admin", json=data) - return response.json() + return self.session.post(f"/x{self.comId}/s/user-profile/{userId}/admin", json=data).json() # TODO : List all warning texts def warn(self, userId: str, reason: str = None): @@ -1791,8 +1767,7 @@ def warn(self, userId: str, reason: str = None): "noticeType": 7 } - response = self.session.post(f"{api}/x{self.comId}/s/notice", json=data) - return response.json() + return self.session.post(f"/x{self.comId}/s/notice", json=data).json() # TODO : List all strike texts def strike(self, userId: str, time: int, title: str = None, reason: str = None): @@ -1814,8 +1789,7 @@ def strike(self, userId: str, time: int, title: str = None, reason: str = None): "noticeType": 4 } - response = self.session.post(f"{api}/x{self.comId}/s/notice", json=data) - return response.json() + return self.session.post(f"/x{self.comId}/s/notice", json=data).json() def ban(self, userId: str, reason: str, banType: int = None): data = { @@ -1825,8 +1799,7 @@ def ban(self, userId: str, reason: str, banType: int = None): } } - response = self.session.post(f"{api}/x{self.comId}/s/user-profile/{userId}/ban", json=data) - return response.json() + return self.session.post(f"/x{self.comId}/s/user-profile/{userId}/ban", json=data).json() def unban(self, userId: str, reason: str): data = { @@ -1835,37 +1808,36 @@ def unban(self, userId: str, reason: str): } } - response = self.session.post(f"{api}/x{self.comId}/s/user-profile/{userId}/unban", json=data) - return response.json() + return self.session.post(f"/x{self.comId}/s/user-profile/{userId}/unban", json=data).json() def reorder_featured_users(self, userIds: list): data = { "uidList": userIds } - response = self.session.post(f"{api}/x{self.comId}/s/user-profile/featured/reorder", json=data) + response = self.session.post(f"/x{self.comId}/s/user-profile/featured/reorder", json=data) return response.json() def get_hidden_blogs(self, start: int = 0, size: int = 25): - response = self.session.get(f"{api}/x{self.comId}/s/feed/blog-disabled?start={start}&size={size}") + response = self.session.get(f"/x{self.comId}/s/feed/blog-disabled?start={start}&size={size}") return objects.BlogList(response.json()["blogList"]).BlogList def get_featured_users(self, start: int = 0, size: int = 25): - response = self.session.get(f"{api}/x{self.comId}/s/user-profile?type=featured&start={start}&size={size}") + response = self.session.get(f"/x{self.comId}/s/user-profile?type=featured&start={start}&size={size}") return objects.UserProfileCountList(response.json()).UserProfileCountList def review_quiz_questions(self, quizId: str): - response = self.session.get(f"{api}/x{self.comId}/s/blog/{quizId}?action=review") + response = self.session.get(f"/x{self.comId}/s/blog/{quizId}?action=review") return objects.QuizQuestionList(response.json()["blog"]["quizQuestionList"]).QuizQuestionList def get_recent_quiz(self, start: int = 0, size: int = 25): - response = self.session.get(f"{api}/x{self.comId}/s/blog?type=quizzes-recent&start={start}&size={size}") + response = self.session.get(f"/x{self.comId}/s/blog?type=quizzes-recent&start={start}&size={size}") return objects.BlogList(response.json()["blogList"]).BlogList def get_trending_quiz(self, start: int = 0, size: int = 25): - response = self.session.get(f"{api}/x{self.comId}/s/feed/quiz-trending?start={start}&size={size}") + response = self.session.get(f"/x{self.comId}/s/feed/quiz-trending?start={start}&size={size}") return objects.BlogList(response.json()["blogList"]).BlogList def get_best_quiz(self, start: int = 0, size: int = 25): - response = self.session.get(f"{api}/x{self.comId}/s/feed/quiz-best-quizzes?start={start}&size={size}") + response = self.session.get(f"/x{self.comId}/s/feed/quiz-best-quizzes?start={start}&size={size}") return objects.BlogList(response.json()["blogList"]).BlogList # Provided by "spectrum#4691" @@ -1889,8 +1861,7 @@ def purchase(self, objectId: str, objectType: int, aminoPlus: bool = True, autoR data['paymentContext'] = {'discountStatus': int(aminoPlus), 'discountValue': 1, 'isAutoRenew': autoRenew} - response = self.session.post(f"{api}/x{self.comId}/s/store/purchase", json=data) - return response.status_code + return self.session.post(f"/x{self.comId}/s/store/purchase", json=data).status_code # Provided by "spectrum#4691" def apply_avatar_frame(self, avatarId: str, applyToAll: bool = True): @@ -1913,8 +1884,7 @@ def apply_avatar_frame(self, avatarId: str, applyToAll: bool = True): "applyToAll": int(applyToAll), } - response = self.session.post(f"{api}/x{self.comId}/s/avatar-frame/apply", json=data) - return response.status_code + return self.session.post(f"/x{self.comId}/s/avatar-frame/apply", json=data).status_code def invite_to_vc(self, chatId: str, userId: str): """ @@ -1932,7 +1902,7 @@ def invite_to_vc(self, chatId: str, userId: str): data = {"uid": userId} - response = self.session.post(f"{api}/x{self.comId}/s/chat/thread/{chatId}/vvchat-presenter/invite/", json=data) + response = self.session.post(f"/x{self.comId}/s/chat/thread/{chatId}/vvchat-presenter/invite/", json=data) return response.status_code def add_poll_option(self, blogId: str, question: str): @@ -1942,7 +1912,7 @@ def add_poll_option(self, blogId: str, question: str): "type": 0 } - response = self.session.post(f"{api}/x{self.comId}/s/blog/{blogId}/poll/option", json=data) + response = self.session.post(f"/x{self.comId}/s/blog/{blogId}/poll/option", json=data) return response.status_code def create_wiki_category(self, title: str, parentCategoryId: str, media: list = None): @@ -1953,14 +1923,11 @@ def create_wiki_category(self, title: str, parentCategoryId: str, media: list = "parentCategoryId": parentCategoryId, } - response = self.session.post(f"{api}/x{self.comId}/s/item-category", json=data) - return response.status_code + return self.session.post(f"/x{self.comId}/s/item-category", json=data).status_code def create_shared_folder(self,title: str): data = {"title": title} - - response = self.session.post(f"{api}/x{self.comId}/s/shared-folder/folders", json=data) - return response.status_code + return self.session.post(f"/x{self.comId}/s/shared-folder/folders", json=data).status_code def submit_to_wiki(self, wikiId: str, message: str): data = { @@ -1968,8 +1935,7 @@ def submit_to_wiki(self, wikiId: str, message: str): "itemId": wikiId } - response = self.session.post(f"{api}/x{self.comId}/s/knowledge-base-request", json=data) - return response.status_code + return self.session.post(f"/x{self.comId}/s/knowledge-base-request", json=data).status_code def accept_wiki_request(self, requestId: str, destinationCategoryIdList: list): data = { @@ -1977,19 +1943,19 @@ def accept_wiki_request(self, requestId: str, destinationCategoryIdList: list): "actionType": "create" } - response = self.session.post(f"{api}/x{self.comId}/s/knowledge-base-request/{requestId}/approve", json=data) + response = self.session.post(f"/x{self.comId}/s/knowledge-base-request/{requestId}/approve", json=data) return response.status_code def reject_wiki_request(self, requestId: str): - response = self.session.post(f"{api}/x{self.comId}/s/knowledge-base-request/{requestId}/reject", json={}) + response = self.session.post(f"/x{self.comId}/s/knowledge-base-request/{requestId}/reject", json={}) return response.status_code def get_wiki_submissions(self, start: int = 0, size: int = 25): - response = self.session.get(f"{api}/x{self.comId}/s/knowledge-base-request?type=all&start={start}&size={size}") + response = self.session.get(f"/x{self.comId}/s/knowledge-base-request?type=all&start={start}&size={size}") return objects.WikiRequestList(response.json()["knowledgeBaseRequestList"]).WikiRequestList def get_live_layer(self): - response = self.session.get(f"{api}/x{self.comId}/s/live-layer/homepage?v=2") + response = self.session.get(f"/x{self.comId}/s/live-layer/homepage?v=2") return objects.LiveLayer(response.json()["liveLayerList"]).LiveLayer def apply_bubble(self, bubbleId: str, chatId: str, applyToAll: bool = False): @@ -1999,5 +1965,5 @@ def apply_bubble(self, bubbleId: str, chatId: str, applyToAll: bool = False): "threadId": chatId, } - response = self.session.post(f"{api}/x{self.comId}/s/chat/thread/apply-bubble", json=data) + response = self.session.post(f"/x{self.comId}/s/chat/thread/apply-bubble", json=data) return response.status_code