diff options
author | RaindropsSys <contact@minteck.org> | 2023-04-27 13:32:25 +0200 |
---|---|---|
committer | RaindropsSys <contact@minteck.org> | 2023-04-27 13:32:25 +0200 |
commit | 59b56c2283c12c8a82144a836faee4f12b15e5c1 (patch) | |
tree | 1d6930b8799f37b2023231d0db253b8a980807d8 /includes/external/matrix | |
parent | 633c92eae865e957121e08de634aeee11a8b3992 (diff) | |
download | pluralconnect-59b56c2283c12c8a82144a836faee4f12b15e5c1.tar.gz pluralconnect-59b56c2283c12c8a82144a836faee4f12b15e5c1.tar.bz2 pluralconnect-59b56c2283c12c8a82144a836faee4f12b15e5c1.zip |
Updated 5 files and deleted 2 files (automated)
Diffstat (limited to 'includes/external/matrix')
-rw-r--r-- | includes/external/matrix/index.js | 40 |
1 files changed, 35 insertions, 5 deletions
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 }, { |