const user = process.argv[2]; const number = require('../../app.json')['signal'][user]; const fs = require('fs'); if (typeof number !== "string") throw new Error("Unable to find info"); const axios = require("axios"); const child_process = require("child_process"); (async () => { console.log("Ready"); let system = require('../../data/' + (user === "raindrops" ? "gdapd" : (user === "cloudburst" ? "ynmuc" : "other")) + "/general.json"); let fronters = require('../../data/' + (user === "raindrops" ? "gdapd" : (user === "cloudburst" ? "ynmuc" : "other")) + "/fronters.json"); let members = require('../../data/' + (user === "raindrops" ? "gdapd" : (user === "cloudburst" ? "ynmuc" : "other")) + "/members.json"); console.log(system.name); console.log(fronters.members.length + " member(s) at front"); let name = system.name; let avatar1 = system.avatar_url; let avatar2 = null; let fronter1 = null; let fronter2 = null; 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; 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; } 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 -resize 512x512 -crop 50%x100% /tmp/chm-" + user + "-1.webp"); child_process.execSync("convert /tmp/chm-" + user + "-2 -gravity center -resize 512x512 -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; } fs.writeFileSync("/tmp/chm-" + user + "-pfp-final", pfp); child_process.execFileSync("signal-cli", [ "-a", number, "updateProfile", "--given-name", name, "--family-name", "", "--avatar", "/tmp/chm-" + user + "-pfp-final" ]); child_process.execFileSync("signal-cli", [ "-a", number, "updateAccount", "--device-name", "Ponycule to Signal integration (v" + new Date().toISOString().split("T")[0].replaceAll("-", ".") + ")" ]); child_process.execFileSync("signal-cli", [ "-a", number, "sendSyncRequest" ]); fs.unlinkSync("/tmp/chm-" + user + "-pfp-final"); })();