Full Bot
This is a more advanced example, showing the power of this library.
import { PixelPlace, World, Auth, EDrawingMode } from 'pixelplacejs'
import fs from 'fs';
//Help functions to load session data from a cache, and also save it to a cache.
function loadCache() {
if (!fs.existsSync("./cache.json"))
throw new Error("No cache.json found. Please create one");
return JSON.parse(fs.readFileSync("./cache.json").toString("utf-8"))
}
function loadAuths(): Auth[] {
let cache = loadCache();
let auths: Auth[] = [];
for (let data of cache) {
let { authId, authToken, authKey } = data;
if (authId && authToken && authKey) {
auths.push(new Auth(null, data));
} else {
console.warn(data, "Is invalid session data.");
}
}
return auths;
}
function saveNewTokens(auths: Auth[]) {
let cache: Array<any> = [];
for (let auth of auths) {
cache.push(auth.getSessionData());
}
fs.writeFileSync("./cache.json", JSON.stringify(cache));
}
//Variables
let protectId: number = 0;
let x = 1286;
let y = 1824;
//Load and create class instances
let accounts = loadAuths();
let world = new World(7, accounts[0]);
let pixelplace = new PixelPlace(accounts, world, 7);
async function main() {
//Initilize
await world.Init();
await pixelplace.Init();
//Save new rotated tokens for the next run
saveNewTokens(accounts);
//Render functions return a `protectId` if protect is enabled
protectId = await pixelplace.render.drawImage(, , , , );
setTimeout(() => {
//After 25 seconds, we stop protecting the image.
pixelplace.removeProtection(protectId);
}, 25000);
}
main();
Last updated
Was this helpful?