summaryrefslogtreecommitdiff
path: root/includes/external
diff options
context:
space:
mode:
authorRaindropsSys <contact@minteck.org>2023-04-27 13:32:25 +0200
committerRaindropsSys <contact@minteck.org>2023-04-27 13:32:25 +0200
commit59b56c2283c12c8a82144a836faee4f12b15e5c1 (patch)
tree1d6930b8799f37b2023231d0db253b8a980807d8 /includes/external
parent633c92eae865e957121e08de634aeee11a8b3992 (diff)
downloadpluralconnect-59b56c2283c12c8a82144a836faee4f12b15e5c1.tar.gz
pluralconnect-59b56c2283c12c8a82144a836faee4f12b15e5c1.tar.bz2
pluralconnect-59b56c2283c12c8a82144a836faee4f12b15e5c1.zip
Updated 5 files and deleted 2 files (automated)
Diffstat (limited to 'includes/external')
-rw-r--r--includes/external/jobs/index.js26
-rw-r--r--includes/external/matrix/index.js40
2 files changed, 53 insertions, 13 deletions
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
}, {