Update README

Added: PNG-logo, shields.io badges
Removed: PHPSESSID guide (moved to Wiki), Reference sheet (moved to Wiki)

Wording and some syntax changes
This commit is contained in:
Victor Westerlund 2020-11-22 21:35:16 +01:00 committed by GitHub
parent a8db13cbf6
commit 2cae57b3e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,32 +1,38 @@
# labylib ![Labylib](https://storage.googleapis.com/public.victorwesterlund.com/github/VictorWesterlund/labylib/labylib.png)
### Cosmetics API for Labymod
Set and update Labymod cosmetics programmatically. ### Cosmetics API for Labymod
![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/VictorWesterlund/labylib?include_prereleases)
![GitHub last commit](https://img.shields.io/github/last-commit/VictorWesterlund/labylib)
![Maintenance](https://img.shields.io/maintenance/yes/2021)
Modify LabyMod cosmetics programmatically with Python.
|![VicW](https://crafatar.com/renders/body/53c40674-f0a2-4f95-9ce1-479bdd1d8b67?scale=2) | Created by VicW | |![VicW](https://crafatar.com/renders/body/53c40674-f0a2-4f95-9ce1-479bdd1d8b67?scale=2) | Created by VicW |
|--|--| |--|--|
_labylib or Victor Westerlund is in no way sponsored by or affiliated with LabyMod or LabyMedia GmbH._<br>
_This program is offered as-is and might stop working at any time_
## Installation ## Installation
1. Download and install [Python 3.x.x](https://www.python.org/downloads/) for your computer's architecture 1. Download and install [Python 3](https://www.python.org/downloads/) for your architecture.
2. Clone this repo to your machine, or [download a zip](/VictorWesterlund/labylib/archive/master.zip) if you don't speak git 2. Clone this repo to your machine, or [download a zip](/VictorWesterlund/labylib/archive/master.zip)
```bash ```bash
$ git clone https://github.com/VictorWesterlund/labylib/ $ git clone https://github.com/VictorWesterlund/labylib/
$ gh repo clone VictorWesterlund/labylib $ gh repo clone VictorWesterlund/labylib
``` ```
3. Extract/copy the `labylib` folder into your project (or make it a dependancy)
## Quickstart ## Quickstart
_**NOTE:**_ _labylib relies on a supplied `PHPSESSID`-cookie from 'labymod.net' to execute its requests. Follow this [this step-by-step guide](#find-your-phpsessid-cookie) to find your `PHPSESSID`_ **1. Import a cosmetics module from `labylib/<cosmetic>`.**
**1. Start by importing a module from `labylib/<cosmetic>`. All [supported cosmetics](#supported-cosmetics) are self-contained modules.** [A list of all modules and classes can be found here](https://github.com/VictorWesterlund/labylib/wiki/Module-reference-sheet)
```python ```python
from labylib import Cape from labylib import Cape
``` ```
**2. Initialize the `Texture()` class.** **2. Initialize a module class.**
All modules take a required `PHPSESSID` as their first argument. The second argument varies depending on the cosmetic. All labylib classes take a `PHPSESSID` as their first argument.
_Example with `Cape` where a file-path is expected:_ _Example with `Cape` where a file-path is expected as a second argument:_
```python ```python
texture = Cape.Texture("<String PHPSESSID>","<String PATH_TO_PNG>") # labylib = Cape.Texture("772nnas663jkc8ahbb2","/home/VicW/coolCape-2.png") texture = Cape.Texture("<String PHPSESSID>","<String PATH_TO_PNG>") # labylib = Cape.Texture("772nnas663jkc8ahbb2","/home/VicW/coolCape-2.png")
``` ```
@ -35,18 +41,18 @@ texture = Cape.Texture("<String PHPSESSID>","<String PATH_TO_PNG>") # labylib =
```python ```python
texture.update() texture.update()
``` ```
Normal Python "Built-in"-exceptions are rasied for missing texture files (`FileNotFoundError`) etc. If a request was sucuessfully sent to the Labymod endpoint, but it returned something falsey (not `OK`). A custom-defined `RequestError` exception will be raised. It contains the message received from the endpoint server. Python's [Built-in-exceptions](https://docs.python.org/3/library/exceptions.html#exception-hierarchy) are rasied as needed for missing texture files (`FileNotFoundError`) etc. If a request was sucuessfully sent to the Labymod endpoint, but it returned something falsey (not `OK`). A custom-defined `RequestError` exception will be raised; containing the response received from the endpoint.
```python ```python
try: try:
texture.update() texture.update()
except RequestError as error: except RequestError as error:
print("Caugh RequestError exception:" + error) print("Caugh RequestError exception:" + error)
# "Caugh RequestError exception: Session expired" # "Caugh RequestError exception: Session expired."
``` ```
## Advanced usage ## Advanced usage
### HTTP POST Headers ### HTTP POST Headers
Request header and cookie dictionaries can be accessed and modified pre-submission by referencing `this.headers` and `this.cookies` respectivly. Request headers and cookies can be accessed and modified pre-submission by applying standard list modifications on the followin objects: `self.headers` and `self.cookies`
```python ```python
texture = Cape.Texture("<String PHPSESSID>","<String PATH_TO_PNG>") texture = Cape.Texture("<String PHPSESSID>","<String PATH_TO_PNG>")
@ -56,50 +62,14 @@ texture.cookies["Foo"] = "Bar"
labylib.update() labylib.update()
``` ```
### HTTP POST Body ### HTTP POST Body
Binary form-data can be added by calling `self.appendBinaryFormData(name,payload)`. Attach `Content-Type`-less form data by supplying a 'name' and 'payload'. Setting 'name' to "file" allows you to upload a `image/png` as BLOB. "payload" excpects a file-path in this case Binary form-data can be appended by calling `self.appendBinaryFormData(name,payload)`.
```python ```python
texture = Cape.Texture("<String PHPSESSID>","<String PATH_TO_PNG>") texture = Cape.Texture("<String PHPSESSID>","<String PATH_TO_PNG>")
texture.appendBinaryFormData(b"foo",b"bar") texture.appendBinaryFormData(b"foo",b"bar")
texture.appendBinaryFormData(b"file","/home/VicW/home/VicW/coolCape-2.png") # Note that 'payload' is a String in this case (as opposed to Binary) texture.appendBinaryFormData(b"file","/home/VicW/home/VicW/coolCape-2.png") # Note that 'payload' is a String in this case (as opposed to Binary)
``` ```
Special form-data types ('names'):
# Additional information: |name|Description
## Find your `PHPSESSID`-cookie
Instructions for your browser:
* [Chrome](#chrome)
* [Firefox](#firefox)
* [Safari](#safari)
### Chrome
1. Open [labymod.net](https://www.labymod.net/) and log in with your Labymod account
2. Press <kbd>F12</kbd> on your keyboard (or <kbd>Ctrl</kbd>+<kbd>⇧ Shift</kbd>+<kbd>I</kbd>) to open DevTools
4. Click on the `Application` tab.
5. Expand `Cookies` under the `Storage` cateogry in the sidebar and select `https://www.labymod.net/`
6. Type `PHPSESSID` into the search box called 'Filter'
7. Copy `Value`(PHPSESSID) from the filtered table. If nothing comes up; try navigating to another page on labymod.net
8. Close DevTools
### Firefox
1. Open [labymod.net](https://www.labymod.net/) and log in with your Labymod account
2. Press <kbd>F12</kbd> on your keyboard (or Right-click the page and select "Inspect Element") to open Developer Tools
4. Click on the `Storage` tab.
5. `Cookies` should already be expanded and selected, but if it isn't; expand it and select `https://www.labymod.net`
6. Using the search bar called 'Filter items', type: `PHPSESSID`
7. Copy `Value`(PHPSESSID) from the filtered table. If nothing comes up; try navigating to another page on labymod.net
8. Close Developer Tools
### Safari
1. Open [labymod.net](https://www.labymod.net/) and log in with your Labymod account
2. Right-click the page and select "Inspect Element" (or <kbd>⌥ Option</kbd>+<kbd>⌘ Command</kbd>+<kbd>I</kbd>) to open Web Inspector
4. Click on the `Storage` tab.
5. Expand `Cookies` in the sidebar and select `labymod.net`
6. Find `PHPSESSID` in the table under the 'Name' column
7. Copy `Value`(PHPSESSID) from the filtered table. If nothing comes up; try navigating to another page on labymod.net
8. Close Web Inspector
### Supported cosmetics
| Labymod cosmetic | labylib module name |
|--|--| |--|--|
| Cloak | Cape | |`'file'`| Submit cosmetic texture file as BLOB by passing `payload` a binary-encoded PNG.<br>_`self.bOpen()` can be used to 'open()' a file as binary string._