Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

Commit

Permalink
Nearly all finished?
Browse files Browse the repository at this point in the history
  • Loading branch information
PoneyClairDeLune committed Mar 28, 2023
1 parent 5f6e597 commit 5730f8d
Show file tree
Hide file tree
Showing 10 changed files with 223 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.swp
.pnp.*
14514.json
deno.lock
package-lock.json
yarn.lock
Expand Down
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,29 @@ Powered by ESBuild and Deno. Developed by [Lightingale Community and all contrib

## Running
### Steps
> **Warning**: BSD and PonyOS are not supported. Feel free to contribute to improve compatibility.
> **Warning**: Only Deno supports proxies. Node.js does not respect proxy settings.
> **Warning**: BSD, iOS and PonyOS are not supported. Feel free to contribute to improve compatibility.
> **Warning**: It's considered a bad idea to run the bot on your main. Spin up disposable alts for bots is recommended.
#### Linux, Android, Mac OS
* Make sure that Bash, cURL and unzip are installed on your system.
* Install the helper script with `bash <(curl -Ls https://sh.ltgc.cc/sh/palette)`. Takes at most 20 seconds to finish on a relatively acceptable Internet connection.
* Try `bash <(curl -Ls https://github.com/ltgcgo/painted-palette/raw/main/src/bash/install.sh)` if the above command does not work.
* ~~If you're on iOS with iSH, run with `wget https://github.com/ltgcgo/painted-palette/raw/main/src/bash/ish.sh -O - | sh` instead.~~ Node.js on iOS is broken.
* How would you like to run it?
* If you just need it to manage a single account, run `./palette-bot paint <yourRedditUsername> <yourRedditPassword>` directly.
* If you have enabled 2FA, the OTP field is also available. Try running `./palette-bot paint <yourRedditUsername> <yourRedditPassword> <otp>`.
* If you need it to manage multiple, run `./palette-bot batch`. You can specify a port for it to listen on, but it'd be on `14514` by default.
* If you don't know much about commands, just use your favourite browser and click on that URL it shows. Then you can do everything there.
* If you need it to manage multiple, or just want a nice GUI, run `./palette-bot batch`. You can specify a port for it to listen on, but it'd be on `14514` by default.
* If you don't know much about commands, just use your favourite browser and click on that URL it shows. You can do everything there.
* If you prefer CLI, use `./palette-bot ctl`. Set the custom port number as the `PORT` environment variable if you have that defined. Help is available with `./palette-bot help ctl`.
* What if you want to have more than 5 accounts going, or just want to hide your IP to Reddit?
* If you don't know much about commands, replace `./palette-bot` in the examples above with `./palette-proxy`. It will do everything for you automatically, just do not manage more than 30 accounts this way. This will considered as a "standalone proxy" by the program.
* Or if you want to use Tor IPs instead of relatively cleaner IPs, replace `./palette-bot` with `./palette-tor`. Same as above, only this time you can manage as much as you want. Beware that accounts managed this way may be flagged as bots earlier.
* If you want to specify an **HTTP** proxy for it to connect, set both the `HTTP_PROXY` and `HTTPS_PROXY` environment variables before running. This will considered as a "system proxy" by the program. If you want to manage more than 30 accounts, go this route for the rest of your accounts.
* Start your auto-guided painting adventure!

Only **Deno** supports proxies.

If upgrades are required, the script should able to download a new version automatically, and restart by itself to load the newer version.
If upgrades are required, the script should able to download a new version automatically, and restart by itself to load the newer version. It can pretty much manage everything all by itself, unless something drastic happens.

#### Windows
* Download the comfort bundle (`deno_windows.zip`) from GitHub Releases.
Expand Down
4 changes: 2 additions & 2 deletions dist/web.js.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/core/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const dim2Prop = [0, 1];

let BuildInfo = {
name: "Painted Palette",
ver: "0.0.9"
ver: "0.0.10"
};

let dim3Dist = function (a, b) {
Expand Down
105 changes: 93 additions & 12 deletions src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {FetchContext} from "./fetchContext.js";
import {RedditAuth} from "./redditAuth.js";
import {Monalisa} from "./monalisa.js";
import {Analytics} from "./analytics.js";
import {PaintGuide} from "./paintGuide.js";
import webUiBody from "../web/index.htm";
import webUiCss from "../web/index.css";
import picoCss from "../../libs/picocss/pico.css";
Expand All @@ -20,9 +21,11 @@ import {pako} from "../../libs/pako/bridge.min.js";
self.pako = pako;
import {UPNG} from "../../libs/upng/upng.min.js";

let utf8Decode = new TextDecoder(), utf8Encode = new TextEncoder();

const svc = {
cnc: "",
tpl: "https://github.com/ltgcgo/painted-palette/raw/main/conf/service/pointer.json"
tpl: "https://github.com/ltgcgo/painted-palette/raw/main/conf/service/rdnsptr.json"
};

let logoutEverywhere = async function (browserContext, redditAuth) {
Expand Down Expand Up @@ -200,7 +203,12 @@ let main = async function (args) {
};
let paintAnalytics = new Analytics('https://analytics.place.equestria.dev');
// If the painter starts
let botSensitivity = 1, botMagazine = 2, botPlaced = 0;
let conf = {
sensitivity: 1,
magazine: 5,
users: {}
};
let botPlaced = 0;
switch (args[0]) {
case "help": {
// Show help
Expand Down Expand Up @@ -314,10 +322,28 @@ let main = async function (args) {
},
templateThread = setInterval(templateRefresher, 30000);
templateRefresher();
let confFile = parseInt(acct) || 14514;
let managedUsers = {};
let confFile = `${parseInt(acct) || 14514}.json`;
let managedClients = [];
console.info(`Reading configuration data from "${confFile}.json".`);
let socketStreams = [];
let announceStream = function (json) {
let serialized = JSON.stringify(json);
socketStreams.forEach((e) => {
e.send(serialized);
});
};
console.info(`Reading configuration data from "${confFile}".`);
try {
conf = JSON.parse(utf8Decode.decode(await WingBlade.readFile(confFile)));
} catch (err) {
console.info(`File read error: ${err}`);
console.info(`If you are running this for the first time, you can safely ignore the error above.`);
};
let fileSaver = async function () {
console.info(`Saving configuration file...`);
await WingBlade.writeFile(confFile, utf8Encode.encode(JSON.stringify(conf)));
},
fileSaveThread = setInterval(fileSaver, 30000);
fileSaver();
let ipInfo = new IPInfo();
ipInfo.start();
WingBlade.serve(async function (request) {
Expand All @@ -327,12 +353,16 @@ let main = async function (args) {
let notFound = new Response("Not Found", {
status: 404
});
let success = new Response("OK", {
status: 200
});
let url = new URL(request.url);
switch (request.method.toLowerCase()) {
case "get": {
switch (url.pathname) {
case "/":
case "/index.htm": {
console.info(`Web UI is opened. Welcome aboard, soldier!`);
return new Response(webUiBody, {
"headers": {
"Content-Type": "text/html"
Expand Down Expand Up @@ -380,9 +410,9 @@ let main = async function (args) {
proxy: WingBlade.getEnv("HTTPS_PROXY") ? (WingBlade.getEnv("PROXY_PORT") ? (WingBlade.getEnv("LONGER_START") || "Standalone") : "System") : "No Proxy",
uptime: Date.now() - runSince,
bot: {
sen: botSensitivity,
pow: getPower(paintGuide, botSensitivity),
mag: botMagazine,
sen: conf.sensitivity,
pow: getPower(paintGuide, conf.sensitivity),
mag: conf.magazine,
px: botPlaced
},
art: {
Expand All @@ -403,28 +433,68 @@ let main = async function (args) {
};
let {socket, response} = WingBlade.upgradeWebSocket(request);
socket.addEventListener("open", () => {
socket.send("Hi Luna!");
console.info(`Web UI subscribed to realtime events.`);
socket.send(JSON.stringify({"event": "init"}));
socket.addEventListener("close", () => {
console.info(`Web UI disconnected from realtime events.`);
socketStreams.splice(socketStreams.indexOf(socket), 1);
});
socketStreams.push(socket);
});
socket.addEventListener("close", () => {
console.info("WS closed.");
});
return response;
break;
};
case "/user": {
// Get users
return new Response(JSON.stringify(conf.users));;
break;
};
default: {
return notFound;
};
};
break;
};
case "post": {
switch (url.pathname) {
case "/user": {
// Get a user
// Add a user
let json = await request.json();
if (conf.users[json.acct]) {
announceStream({"event": "error", "data": `Account "${json.acct}" already exists.`});
return new Response("Already existed.", {
status: 400
});
} else {
conf.users[json.acct] = json;
announceStream({"event": "user", "data": json.acct});
return success;
};
break;
};
default: {
return notFound;
};
};
break;
};
case "post": {
case "put": {
switch (url.pathname) {
case "/user": {
// Add a user
// Get a user
let json = await request.text();
if (conf.users[json]) {
return new Response(JSON.stringify(conf.users[json]));
} else {
announceStream({"event": "error", "data": `Account "${json}" doesn't exist.`});
return new Response("Doesn't exist.", {
status: 400
});
};
return success;
break;
};
default: {
Expand All @@ -437,6 +507,17 @@ let main = async function (args) {
switch (url.pathname) {
case "/user": {
// Remove a user
let json = await request.text();
if (conf.users[json]) {
delete conf.users[json];
announceStream({"event": "userdel", "data": json});
return success;
} else {
announceStream({"event": "error", "data": `Account "${json}" doesn't exist.`});
return new Response("Doesn't exist.", {
status: 400
});
};
break;
};
default: {
Expand Down
11 changes: 11 additions & 0 deletions src/core/paintGuide.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"use strict";
import {FetchContext} from "./fetchContext.js";

let PaintGuide = class {
#fc = new FetchContext("https://www.equestria.dev");
async updateTemplate() {};
};

export {
PaintGuide
};
3 changes: 3 additions & 0 deletions src/deno/wingblade.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ let WingBlade = {
randomInt: (cap) => {
return Math.floor(Math.random() * cap);
},
readFile: async function (path, opt) {
return await Deno.readFile(path, opt);
},
serve: (handler, opt = {}) => {
if (!opt?.onListen) {
opt.onListen = function ({port, hostname}) {
Expand Down
3 changes: 3 additions & 0 deletions src/node/wingblade.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ let WingBlade = {
randomInt: (cap) => {
return Math.floor(Math.random() * cap);
},
readFile: async function (path, opt) {
return new Uint8Array((await fs.promises.readFile(path, opt)).buffer);
},
serve: (handler, opt = {}) => {
let port = opt.port || 8000;
let hostname = opt.hostname || "127.0.0.1";
Expand Down
Loading

0 comments on commit 5730f8d

Please sign in to comment.