summaryrefslogtreecommitdiff
path: root/includes/external/matrix/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'includes/external/matrix/index.js')
-rw-r--r--includes/external/matrix/index.js135
1 files changed, 0 insertions, 135 deletions
diff --git a/includes/external/matrix/index.js b/includes/external/matrix/index.js
deleted file mode 100644
index 8a2d8ec..0000000
--- a/includes/external/matrix/index.js
+++ /dev/null
@@ -1,135 +0,0 @@
-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");
-
-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,
- userId: "@" + user + ":equestria.dev"
-});
-
-function sleep(ms) {
- return new Promise((res, rej) => {
- setTimeout(res, ms);
- });
-}
-
-client.once("sync", async function (state, prevState, res) {
- if (state === "PREPARED") {
- 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;
- }
-
- await client.setDeviceDetails(info.device, {
- display_name: "Cold Haze PluralKit integration"
- });
-
- console.log("Setting display name " + name);
- await axios.put("https://chat.equestria.dev/_matrix/client/r0/profile/%40" + user + "%3Aequestria.dev/displayname", {
- displayname: name
- }, {
- headers: {
- Authorization: "Bearer " + token
- }
- });
- await axios.get("https://chat.equestria.dev/_matrix/client/r0/profile/%40" + user + "%3Aequestria.dev", {
- headers: {
- Authorization: "Bearer " + token
- }
- });
-
- await sleep(2000);
-
- console.log("Uploading avatar");
- 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;
- }
-
- 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
- }, {
- headers: {
- Authorization: "Bearer " + token
- }
- });
- await axios.get("https://chat.equestria.dev/_matrix/client/r0/profile/%40" + user + "%3Aequestria.dev", {
- headers: {
- Authorization: "Bearer " + token
- }
- });
-
- /*if (user === "raindrops" && name === "Hazy Stardawn") {
- await sleep(2000);
- let res2 = await client.uploadContent(fs.readFileSync("../../../assets/uploads/hazy.png"));
-
- await axios.put("https://chat.equestria.dev/_matrix/client/r0/rooms/" + encodeURIComponent(require('../../app.json')['matrix']['room']) + "/state/m.room.member/%40raindrops%3Aequestria.dev", {
- avatar_url: res2.content_uri,
- displayname: "Hazel Stardawn",
- membership: "join"
- }, {
- headers: {
- Authorization: "Bearer " + token
- }
- });
- }*/
-
- process.exit(0);
- } else {
- console.log(state);
- process.exit(1);
- }
-});
-
-(async () => {
- await client.startClient({ initialSyncLimit: 0 });
-})(); \ No newline at end of file