mirror of
https://codeberg.org/vlw/labylib.git
synced 2025-09-13 17:43:41 +02:00
Merge pull request #6 from VictorWesterlund/feature/cosmetics
Feature/cosmetics
This commit is contained in:
commit
324e26a1f3
4 changed files with 286 additions and 15 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1 +1,2 @@
|
||||||
*__pycache__
|
*__pycache__
|
||||||
|
dev*
|
|
@ -1 +0,0 @@
|
||||||
from labylib.labylib import Cape
|
|
171
labylib/Cape.py
171
labylib/Cape.py
|
@ -2,15 +2,11 @@ import requests
|
||||||
import hashlib
|
import hashlib
|
||||||
import time
|
import time
|
||||||
|
|
||||||
class RequestError(Exception): pass
|
|
||||||
|
|
||||||
class Texture:
|
class Texture:
|
||||||
|
|
||||||
endpoint = "https://www.labymod.net/page/php/cape.php"
|
endpoint = "https://www.labymod.net/page/php/cape.php"
|
||||||
|
|
||||||
def __init__(self,cookie,img):
|
def __init__(self,cookie):
|
||||||
self.validate(cookie,img)
|
|
||||||
|
|
||||||
self.body = b"" # Initialize request body
|
self.body = b"" # Initialize request body
|
||||||
self.cookies = dict(PHPSESSID = cookie)
|
self.cookies = dict(PHPSESSID = cookie)
|
||||||
self.boundary = self.boundary()
|
self.boundary = self.boundary()
|
||||||
|
@ -33,13 +29,9 @@ class Texture:
|
||||||
}
|
}
|
||||||
|
|
||||||
self.appendBinaryFormData(b"cosmetic",b"cape")
|
self.appendBinaryFormData(b"cosmetic",b"cape")
|
||||||
self.appendBinaryFormData(b"file",self.bOpen(img))
|
|
||||||
|
|
||||||
# -----------------------------------
|
# -----------------------------------
|
||||||
|
|
||||||
def validate(self,cookie,file):
|
|
||||||
return True
|
|
||||||
|
|
||||||
# Generate boundary header from MD5-hash of current time
|
# Generate boundary header from MD5-hash of current time
|
||||||
def boundary(self):
|
def boundary(self):
|
||||||
seed = str(time.time())
|
seed = str(time.time())
|
||||||
|
@ -83,7 +75,9 @@ class Texture:
|
||||||
|
|
||||||
# -----------------------------------
|
# -----------------------------------
|
||||||
|
|
||||||
def update(self):
|
def update(self,img):
|
||||||
|
self.appendBinaryFormData(b"file",self.bOpen(img))
|
||||||
|
|
||||||
self.closeBinaryFormData() # Add final boundary header
|
self.closeBinaryFormData() # Add final boundary header
|
||||||
|
|
||||||
request = requests.post(Texture.endpoint,
|
request = requests.post(Texture.endpoint,
|
||||||
|
@ -93,6 +87,157 @@ class Texture:
|
||||||
)
|
)
|
||||||
|
|
||||||
# Raise exception if request fails
|
# Raise exception if request fails
|
||||||
# Use [3:5] to clean up junk chars from reponse body
|
request.raise_for_status()
|
||||||
if(str(request.text)[3:5] != "OK"):
|
|
||||||
raise RequestError(str(request.text))
|
class Template:
|
||||||
|
|
||||||
|
endpoint = "https://www.labymod.net/page/php/setCapeTpl.php"
|
||||||
|
templates = {
|
||||||
|
"labymod": "10_LABYMOD.png",
|
||||||
|
"minecon2011": "30_MINECON2011.png",
|
||||||
|
"minecon2012": "30_MINECON2012.png",
|
||||||
|
"minecon2013": "30_MINECON2013.png",
|
||||||
|
"minecon2015": "30_MINECON2015.png",
|
||||||
|
"minecon2016": "30_MINECON2016.png",
|
||||||
|
"minecon2019": "30_MINECON2019.png",
|
||||||
|
"prismarine": "30_PRISMARINE.png",
|
||||||
|
"christmas2010": "40_CHRISTMAS2010.png",
|
||||||
|
"cobalt": "40_COBALT.png",
|
||||||
|
"julianclark": "40_JULIANCLARK.png",
|
||||||
|
"mapmaker": "40_MAPMAKER.png",
|
||||||
|
"mojira": "40_MOJIRA.png",
|
||||||
|
"mrmessiah": "40_MRMESSIAH.png",
|
||||||
|
"newyear": "40_NEWYEAR.png",
|
||||||
|
"scrolls": "40_SCROLLS.png",
|
||||||
|
"translator": "40_TRANSLATOR.png",
|
||||||
|
"turtle": "40_TURTLE.png",
|
||||||
|
"winner": "40_WINNER.png"
|
||||||
|
}
|
||||||
|
|
||||||
|
def __init__(self,cookie):
|
||||||
|
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("cosmetic","cape")
|
||||||
|
|
||||||
|
# -----------------------------------
|
||||||
|
|
||||||
|
# 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,value):
|
||||||
|
value = value.lower()
|
||||||
|
|
||||||
|
if(value not in Template.templates):
|
||||||
|
raise ValueError(f"'{value}' is not a valid template.")
|
||||||
|
|
||||||
|
texture = Template.templates[value]
|
||||||
|
|
||||||
|
self.addEncodedFormData("cape",texture)
|
||||||
|
|
||||||
|
request = requests.post(Template.endpoint,
|
||||||
|
headers = self.headers,
|
||||||
|
cookies = self.cookies,
|
||||||
|
data = self.body
|
||||||
|
)
|
||||||
|
|
||||||
|
# Raise exception if request fails
|
||||||
|
request.raise_for_status()
|
||||||
|
|
||||||
|
class Visibility:
|
||||||
|
|
||||||
|
endpoint = "https://www.labymod.net/api/change"
|
||||||
|
|
||||||
|
def __init__(self,cookie):
|
||||||
|
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("item",459595)
|
||||||
|
self.addEncodedFormData("site","control")
|
||||||
|
|
||||||
|
# -----------------------------------
|
||||||
|
|
||||||
|
# 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,value):
|
||||||
|
# Interpret strings
|
||||||
|
if(type(value) != int):
|
||||||
|
if(value == "show"):
|
||||||
|
value = 1
|
||||||
|
elif(value == "hide"):
|
||||||
|
value = 0
|
||||||
|
else:
|
||||||
|
raise ValueError(f"'{value}' is not a valid visibility state.")
|
||||||
|
|
||||||
|
self.addEncodedFormData("value",value)
|
||||||
|
|
||||||
|
request = requests.post(Visibility.endpoint,
|
||||||
|
headers = self.headers,
|
||||||
|
cookies = self.cookies,
|
||||||
|
data = self.body
|
||||||
|
)
|
||||||
|
|
||||||
|
# Raise exception if request fails
|
||||||
|
request.raise_for_status()
|
126
labylib/Hat.py
Normal file
126
labylib/Hat.py
Normal file
|
@ -0,0 +1,126 @@
|
||||||
|
import requests
|
||||||
|
|
||||||
|
class Texture:
|
||||||
|
|
||||||
|
endpoint = "https://www.labymod.net/api/change"
|
||||||
|
|
||||||
|
def __init__(self,cookie):
|
||||||
|
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","country")
|
||||||
|
self.addEncodedFormData("item",459594)
|
||||||
|
self.addEncodedFormData("site","control")
|
||||||
|
|
||||||
|
# -----------------------------------
|
||||||
|
|
||||||
|
# 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,value):
|
||||||
|
self.addEncodedFormData("value",value)
|
||||||
|
|
||||||
|
request = requests.post(Texture.endpoint,
|
||||||
|
headers = self.headers,
|
||||||
|
cookies = self.cookies,
|
||||||
|
data = self.body
|
||||||
|
)
|
||||||
|
|
||||||
|
# Raise exception if request fails
|
||||||
|
request.raise_for_status()
|
||||||
|
|
||||||
|
class Visibility:
|
||||||
|
|
||||||
|
endpoint = "https://www.labymod.net/api/change"
|
||||||
|
|
||||||
|
def __init__(self,cookie):
|
||||||
|
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("item",459594)
|
||||||
|
self.addEncodedFormData("site","control")
|
||||||
|
|
||||||
|
# -----------------------------------
|
||||||
|
|
||||||
|
# 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,value):
|
||||||
|
# Interpret strings
|
||||||
|
if(type(value) != int):
|
||||||
|
if(value == "show"):
|
||||||
|
value = 1
|
||||||
|
else:
|
||||||
|
value = 0
|
||||||
|
|
||||||
|
self.addEncodedFormData("value",value)
|
||||||
|
|
||||||
|
request = requests.post(Visibility.endpoint,
|
||||||
|
headers = self.headers,
|
||||||
|
cookies = self.cookies,
|
||||||
|
data = self.body
|
||||||
|
)
|
||||||
|
|
||||||
|
# Raise exception if request fails
|
||||||
|
request.raise_for_status()
|
Loading…
Add table
Reference in a new issue