From 64202e769969817ce29fe970903ffd3feb9f16e4 Mon Sep 17 00:00:00 2001 From: Victor Westerlund Date: Sun, 22 Nov 2020 20:29:52 +0100 Subject: [PATCH] Draft: Visibility Work in progress; Change visibility of cosmetics with 'Visibility()' Currently not working. Getting HTTP Conflict response from endpoint. Needs further investigation --- .gitignore | 3 ++- labylib/Cape.py | 65 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 264daca..b1687e0 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -*__pycache__ \ No newline at end of file +*__pycache__ +dev* \ No newline at end of file diff --git a/labylib/Cape.py b/labylib/Cape.py index fcac83d..e731760 100644 --- a/labylib/Cape.py +++ b/labylib/Cape.py @@ -92,6 +92,71 @@ class Texture: data = self.body ) + # Raise exception if request fails + # Use [3:5] to clean up junk chars from reponse body + if(str(request.text)[3:5] != "OK"): + raise RequestError(str(request.text)) + +class Visibility: + + endpoint = "https://www.labymod.net/api/change" + + def __init__(self,cookie,value): + self.validate(cookie,value) + + self.cookies = dict(PHPSESSID = cookie) + + self.headers = { + "accept": "*/*", + "accept-encoding": "gzip, deflate, br", + "accept-language": "en-US,en;q=0.9,sv;q=0.8", + "cache-control": "no-cache", + "dnt": "1", + "user-agent": "Mozilla/5.0 (Windows NT 5.1; rv:33.0) Gecko/20100101 Firefox/33.0", + "origin": "https://www.labymod.net", + "pragma": "no-cache", + "referer": "https://www.labymod.net/dashboard", + "sec-fetch-dest": "empty", + "sec-fetch-mode": "cors", + "sec-fetch-site": "same-origin", + "x-requested-with": "XMLHttpRequest", + "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8" + } + + self.body = "" + + # Payload + self.addEncodedFormData("type","switch") + self.addEncodedFormData("value",value) + self.addEncodedFormData("item",459595) + self.addEncodedFormData("site","control") + + # ----------------------------------- + + def validate(self,cookie,file): + return True + + # Add URLEncoded form data (x-www-form-urlencoded) + def addEncodedFormData(self,key,value): + body = "&" + + # Remove '&' delimiter for first item + if(self.body == ""): + body = "" + + body += f"{key}={value}" + + self.body += body + + # ----------------------------------- + + def update(self): + request = requests.post(Texture.endpoint, + headers = self.headers, + cookies = self.cookies, + data = self.body + ) + # Raise exception if request fails # Use [3:5] to clean up junk chars from reponse body if(str(request.text)[3:5] != "OK"):