From 59b56c2283c12c8a82144a836faee4f12b15e5c1 Mon Sep 17 00:00:00 2001 From: RaindropsSys Date: Thu, 27 Apr 2023 13:32:25 +0200 Subject: Updated 5 files and deleted 2 files (automated) --- includes/external/jobs/index.js | 26 +++-- includes/external/matrix/index.js | 40 ++++++- includes/fragments/metadata.inc | 228 ++++++++++++++++++++++++++++++++++---- includes/util/functions.inc | 6 +- 4 files changed, 260 insertions(+), 40 deletions(-) (limited to 'includes') diff --git a/includes/external/jobs/index.js b/includes/external/jobs/index.js index 39b7de5..0f44cc9 100644 --- a/includes/external/jobs/index.js +++ b/includes/external/jobs/index.js @@ -1,13 +1,21 @@ const fs = require('fs'); const child_process = require('child_process'); -let jobs = require('../../data/jobs.json'); +let jobsList = []; +let jobs = []; let history = require('../../data/history.json'); +fs.writeFileSync("../../data/running.json", "null"); + setInterval(() => { - if (JSON.stringify(JSON.parse(fs.readFileSync("../../data/jobs.json").toString())) !== JSON.stringify(jobs)) { + if (JSON.stringify(fs.readdirSync("../../data/jobs")) !== JSON.stringify(jobsList)) { console.log("Updating the jobs list..."); - jobs = JSON.parse(fs.readFileSync("../../data/jobs.json").toString()); + jobs = fs.readdirSync("../../data/jobs").map((i) => { + let obj = JSON.parse(fs.readFileSync("../../data/jobs/" + i).toString()); + obj["_id"] = i; + return obj; + }); + jobsList = fs.readdirSync("../../data/jobs"); } }, 1000); @@ -20,11 +28,13 @@ setTimeout(() => { console.log("\nRunning jobs:"); for (let job of jobs) { - console.log(" " + job.name); + console.log(" " + job.name + " [" + job._id + "]"); let output; let start; let end; + fs.writeFileSync("../../data/running.json", JSON.stringify(job._id)); + try { start = new Date(); output = child_process.execFileSync("php", [job.name + ".php", JSON.stringify(job.options)], { cwd: "../../jobs" }); @@ -37,8 +47,7 @@ setTimeout(() => { description = "," + name + "=" + JSON.stringify(job.options[name]); } - jobs.splice(jobs.indexOf(job), 1); - fs.writeFileSync("../../data/jobs.json", JSON.stringify(jobs)); + fs.unlinkSync("../../data/jobs/" + job._id); history.unshift({ completed: true, @@ -58,6 +67,7 @@ setTimeout(() => { history = history.slice(0, 200); fs.writeFileSync("../../data/history.json", JSON.stringify(history)); + fs.writeFileSync("../../data/running.json", "null"); } catch (e) { end = start ? new Date() : null; console.log(" Failed to process job"); @@ -70,8 +80,7 @@ setTimeout(() => { description = "," + name + "=" + JSON.stringify(job.options[name]); } - jobs.splice(jobs.indexOf(job), 1); - fs.writeFileSync("../../data/jobs.json", JSON.stringify(jobs)); + fs.unlinkSync("../../data/jobs/" + job._id); history.unshift({ completed: false, @@ -91,6 +100,7 @@ setTimeout(() => { history = history.slice(0, 200); fs.writeFileSync("../../data/history.json", JSON.stringify(history)); + fs.writeFileSync("../../data/running.json", "null"); } } diff --git a/includes/external/matrix/index.js b/includes/external/matrix/index.js index 5149005..1bfb8d4 100644 --- a/includes/external/matrix/index.js +++ b/includes/external/matrix/index.js @@ -1,5 +1,6 @@ const user = process.argv[2]; const info = require('../../app.json')['matrix'][user]; +const fs = require('fs'); if (typeof info !== "object") throw new Error("Unable to find info"); @@ -7,6 +8,7 @@ const token = info.token; const sdk = require("matrix-js-sdk"); const axios = require("axios"); +const child_process = require("child_process"); const client = sdk.createClient({ baseUrl: "https://chat.equestria.dev", accessToken: token, @@ -24,13 +26,16 @@ client.once("sync", async function (state, prevState, res) { console.log(fronters.members.length + " member(s) at front"); let name = system.name; - let avatar = system.avatar_url; + let avatar1 = system.avatar_url; + let avatar2 = null; - if (fronters.members.length === 1) { + if (fronters.members.length === 1 || (fronters.members.length === 2 && (fronters.members[0].name === "scootaloo" && fronters.members[1].name === "rainbowdash"))) { name = fronters.members[0].display_name ?? fronters.members[0].name; - avatar = fronters.members[0].avatar_url ?? avatar; - } else if (fronters.members.length >= 2) { + avatar1 = fronters.members[0].avatar_url ?? avatar1; + } else if (fronters.members.length >= 2 && !(fronters.members[0].name === "scootaloo" && fronters.members[1].name === "rainbowdash")) { name = (fronters.members[0].display_name ?? fronters.members[0].name) + " and " + (fronters.members[1].display_name ?? fronters.members[1].name); + avatar1 = fronters.members[0].avatar_url ?? avatar1; + avatar2 = fronters.members[1].avatar_url ?? avatar2; } await client.setDeviceDetails(info.device, { @@ -52,7 +57,32 @@ client.once("sync", async function (state, prevState, res) { }); console.log("Uploading avatar"); - let res = await client.uploadContent((await axios.get(avatar, {responseType: "arraybuffer"})).data); + let pfp; + + if (avatar2) { + let img1 = (await axios.get(avatar1, {responseType: "arraybuffer"})).data; + let img2 = (await axios.get(avatar2, {responseType: "arraybuffer"})).data; + + fs.writeFileSync("/tmp/chm-" + user + "-1", img1); + fs.writeFileSync("/tmp/chm-" + user + "-2", img2); + + child_process.execSync("convert /tmp/chm-" + user + "-1 -gravity center -crop 50%x100% /tmp/chm-" + user + "-1.webp"); + child_process.execSync("convert /tmp/chm-" + user + "-2 -gravity center -crop 50%x100% /tmp/chm-" + user + "-2.webp"); + child_process.execSync("montage -mode concatenate -tile x1 /tmp/chm-" + user + "-1.webp /tmp/chm-" + user + "-2.webp /tmp/chm-" + user + ".webp"); + + pfp = fs.readFileSync("/tmp/chm-" + user + ".webp"); + + fs.unlinkSync("/tmp/chm-" + user + "-1"); + fs.unlinkSync("/tmp/chm-" + user + "-2"); + fs.unlinkSync("/tmp/chm-" + user + "-1.webp"); + fs.unlinkSync("/tmp/chm-" + user + "-2.webp"); + fs.unlinkSync("/tmp/chm-" + user + ".webp"); + } else { + pfp = (await axios.get(avatar1, {responseType: "arraybuffer"})).data; + } + + let res = await client.uploadContent(pfp); + await axios.put("https://chat.equestria.dev/_matrix/client/r0/profile/%40" + user + "%3Aequestria.dev/avatar_url", { avatar_url: res.content_uri }, { diff --git a/includes/fragments/metadata.inc b/includes/fragments/metadata.inc index 0d2187c..719abbc 100644 --- a/includes/fragments/metadata.inc +++ b/includes/fragments/metadata.inc @@ -6,9 +6,51 @@ if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/" . $member ?> + +
-
-

">

+
+

">

@@ -94,28 +136,166 @@ if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/" . $member

Relationships

- -

- Sexfriends (full IDs, comma-separated)
- "> -

- -

- Marefriends (full IDs, comma-separated)
- "> -

-

- Sisters (full IDs, comma-separated)
- "> -

-

- Caretakers (full IDs, comma-separated)
- "> -

-

- Friends (full IDs, comma-separated)
- "> -

+ + + + + + +

+
+ "> + + + + +

+
diff --git a/includes/util/functions.inc b/includes/util/functions.inc index 79a47c6..fe97980 100644 --- a/includes/util/functions.inc +++ b/includes/util/functions.inc @@ -3,17 +3,17 @@ require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/score.inc"; require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/bitset.inc"; require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/homepage.inc"; +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/random.inc"; if (!function_exists("createJob")) { function createJob($title, $options) { - $jobs = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/jobs.json"), true); - $jobs[] = [ + $job = [ "name" => $title, "options" => $options, "date" => date('c') ]; - file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/jobs.json", json_encode($jobs)); + file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/jobs/" . round(microtime(true) * 1000) . "-" . random() . ".json", json_encode($job)); } } -- cgit