Skip to content

Commit

Permalink
improved code readability
Browse files Browse the repository at this point in the history
  • Loading branch information
AugustLigh committed Apr 12, 2024
1 parent 077a462 commit 77f7ce0
Show file tree
Hide file tree
Showing 7 changed files with 469 additions and 167 deletions.
7 changes: 4 additions & 3 deletions AminoLightPy/acm.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,9 @@ def get_community_stats(self):
- **Fail** : :meth:`Exceptions <AminoLightPy.lib.util.exceptions>`
"""
response = self.session.get(f"{api}/x{self.comId}/s/community/stats")
if response.status_code != 200: return exceptions.CheckException(response.text)
else: return objects.CommunityStats(response.json()["communityStats"]).CommunityStats
if response.status_code != 200:
return exceptions.CheckException(response.text)
return objects.CommunityStats(response.json()["communityStats"]).CommunityStats

def get_community_user_stats(self, type: str, start: int = 0, size: int = 25):
"""
Expand Down Expand Up @@ -294,7 +295,7 @@ def change_guidelines(self, message: str):
- **Fail** : :meth:`Exceptions <AminoLightPy.lib.util.exceptions>`
"""
data = { "content": message }

response = self.session.post(f"{api}/x{self.comId}/s/community/guideline", json=data)
return response.status_code

Expand Down
81 changes: 63 additions & 18 deletions AminoLightPy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#@dorthegra/IDörthe#8835 thanks for support!

class Client(Callbacks, SocketHandler, SocketRequests):
"Module for work with global"
def __init__(self, proxies: dict = None, socketDebugging = False, socket_enabled = True):
self.api = api
self.authenticated = False
Expand Down Expand Up @@ -282,9 +283,6 @@ def logout(self):
})

self.profile.session = None
#TODO
# if self.socket_enabled:
# self.close()

return response.status_code

Expand Down Expand Up @@ -994,7 +992,11 @@ def check_values(self, *args):
"Check params in send_message metod."
return any(arg is None for arg in args)

def send_message(self, chatId: str, message: str = None, messageType: int = 0, file: BinaryIO = None, fileType: str = None, replyTo: str = None, mentionUserIds: list = None, stickerId: str = None, embedId: str = None, embedType: int = None, embedLink: str = None, embedTitle: str = None, embedContent: str = None, embedImage: BinaryIO = None):
def send_message(self, chatId: str, message: str = None, messageType: int = 0,
file: BinaryIO = None, fileType: str = None, replyTo: str = None,
mentionUserIds: list = None, stickerId: str = None, embedId: str = None,
embedType: int = None, embedLink: str = None, embedTitle: str = None,
embedContent: str = None, embedImage: BinaryIO = None):
"""
Send a Message to a Chat.
Expand Down Expand Up @@ -1112,7 +1114,12 @@ def mark_as_read(self, chatId: str, messageId: str):
response = self.session.post(f"{api}/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, title: str = None, icon: str = None, backgroundImage: str = None, content: str = None, announcement: str = None, coHosts: list = None, keywords: list = None, pinAnnouncement: bool = None, publishToGlobal: bool = None, canTip: bool = None, viewOnly: bool = None, canInvite: bool = None, fansOnly: bool = None):
def edit_chat(self, chatId: str, doNotDisturb: bool = None, pinChat: bool = None,
title: str = None, icon: str = None, backgroundImage: str = None,
content: str = None, announcement: str = None, coHosts: list = None,
keywords: list = None, pinAnnouncement: bool = None, publishToGlobal: bool = None,
canTip: bool = None, viewOnly: bool = None, canInvite: bool = None,
fansOnly: bool = None):
"""
Send a Message to a Chat.
Expand Down Expand Up @@ -1165,50 +1172,88 @@ def edit_chat(self, chatId: str, doNotDisturb: bool = None, pinChat: bool = None
if doNotDisturb is not None:
if doNotDisturb:
data = {"alertOption": 2}
response = self.session.post(f"{api}/g/s/chat/thread/{chatId}/member/{self.profile.userId}/alert", json=data)
response = self.session.post(
url=f"{api}/g/s/chat/thread/{chatId}/member/{self.profile.userId}/alert",
json=data
)
res.append(response.status_code)
if not doNotDisturb:
data = {"alertOption": 1}
response = self.session.post(f"{api}/g/s/chat/thread/{chatId}/member/{self.profile.userId}/alert", json=data)
response = self.session.post(
url=f"{api}/g/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(f"{api}/g/s/chat/thread/{chatId}/pin", json=data)
response = self.session.post(
url=f"{api}/g/s/chat/thread/{chatId}/pin",
json=data
)
res.append(response.status_code)
if not pinChat:
response = self.session.post(f"{api}/g/s/chat/thread/{chatId}/unpin", json=data)
response = self.session.post(
url=f"{api}/g/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(f"{api}/g/s/chat/thread/{chatId}/member/{self.profile.userId}/background", json=data)
response = self.session.post(
url=f"{api}/g/s/chat/thread/{chatId}/member/{self.profile.userId}/background",
json=data
)
res.append(response.status_code)
if coHosts is not None:
data = {"uidList": coHosts}
response = self.session.post(f"{api}/g/s/chat/thread/{chatId}/co-host", json=data)
response = self.session.post(
url=f"{api}/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(f"{api}/g/s/chat/thread/{chatId}/view-only/enable")
response = self.session.post(
url=f"{api}/g/s/chat/thread/{chatId}/view-only/enable"
)
res.append(response.status_code)

if not viewOnly:
response = self.session.post(f"{api}/g/s/chat/thread/{chatId}/view-only/disable")
response = self.session.post(
url=f"{api}/g/s/chat/thread/{chatId}/view-only/disable"
)
res.append(response.status_code)
if canInvite is not None:
if canInvite:
response = self.session.post(f"{api}/g/s/chat/thread/{chatId}/members-can-invite/enable", json=data)
response = self.session.post(
url=f"{api}/g/s/chat/thread/{chatId}/members-can-invite/enable",
json=data
)
res.append(response.status_code)
if not canInvite:
response = self.session.post(f"{api}/g/s/chat/thread/{chatId}/members-can-invite/disable", json=data)
response = self.session.post(
url=f"{api}/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(f"{api}/g/s/chat/thread/{chatId}/tipping-perm-status/enable", json=data)
response = self.session.post(
url=f"{api}/g/s/chat/thread/{chatId}/tipping-perm-status/enable",
json=data
)
res.append(response.status_code)
if not canTip:
response = self.session.post(f"{api}/g/s/chat/thread/{chatId}/tipping-perm-status/disable", json=data)
response = self.session.post(
url=f"{api}/g/s/chat/thread/{chatId}/tipping-perm-status/disable",
json=data
)
res.append(response.status_code)
response = self.session.post(f"{api}/g/s/chat/thread/{chatId}", json=data)

response = self.session.post(
url=f"{api}/g/s/chat/thread/{chatId}",
json=data
)
res.append(response.status_code)

return res
Expand Down
6 changes: 3 additions & 3 deletions AminoLightPy/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from json import dumps
from hashlib import sha1
from typing import BinaryIO
from requests import Session
from collections import OrderedDict
from requests import Session

from .lib.util.exceptions import SpecifyType
from .lib.util import signature, gen_deviceId
Expand Down Expand Up @@ -80,7 +80,6 @@ def upload_media(self, file: BinaryIO, fileType: str) -> str:
t = "image/gif"
else: raise SpecifyType(fileType)


custom_headers = self.session.headers
custom_headers["Content-Type"] = t

Expand All @@ -95,4 +94,5 @@ def upload_media(self, file: BinaryIO, fileType: str) -> str:
if len(cache) >= 32:
cache.popitem(last=False)

return cache[file_hash]
return cache[file_hash]

Loading

0 comments on commit 77f7ce0

Please sign in to comment.