summaryrefslogtreecommitdiff
path: root/includes/external/matrix/index.js
diff options
context:
space:
mode:
authorRaindropsSys <contact@minteck.org>2023-04-24 14:03:36 +0200
committerRaindropsSys <contact@minteck.org>2023-04-24 14:03:36 +0200
commit633c92eae865e957121e08de634aeee11a8b3992 (patch)
tree09d881bee1dae0b6eee49db1dfaf0f500240606c /includes/external/matrix/index.js
parentc4657e4509733699c0f26a3c900bab47e915d5a0 (diff)
downloadpluralconnect-633c92eae865e957121e08de634aeee11a8b3992.tar.gz
pluralconnect-633c92eae865e957121e08de634aeee11a8b3992.tar.bz2
pluralconnect-633c92eae865e957121e08de634aeee11a8b3992.zip
Updated 18 files, added 1692 files and deleted includes/system/compare.inc (automated)
Diffstat (limited to 'includes/external/matrix/index.js')
-rw-r--r--includes/external/matrix/index.js78
1 files changed, 78 insertions, 0 deletions
diff --git a/includes/external/matrix/index.js b/includes/external/matrix/index.js
new file mode 100644
index 0000000..5149005
--- /dev/null
+++ b/includes/external/matrix/index.js
@@ -0,0 +1,78 @@
+const user = process.argv[2];
+const info = require('../../app.json')['matrix'][user];
+
+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 client = sdk.createClient({
+ baseUrl: "https://chat.equestria.dev",
+ accessToken: token,
+ userId: "@" + user + ":equestria.dev"
+});
+
+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");
+
+ console.log(system.name);
+ console.log(fronters.members.length + " member(s) at front");
+
+ let name = system.name;
+ let avatar = system.avatar_url;
+
+ if (fronters.members.length === 1) {
+ name = fronters.members[0].display_name ?? fronters.members[0].name;
+ avatar = fronters.members[0].avatar_url ?? avatar;
+ } else if (fronters.members.length >= 2) {
+ name = (fronters.members[0].display_name ?? fronters.members[0].name) + " and " + (fronters.members[1].display_name ?? fronters.members[1].name);
+ }
+
+ 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
+ }
+ });
+
+ console.log("Uploading avatar");
+ let res = await client.uploadContent((await axios.get(avatar, {responseType: "arraybuffer"})).data);
+ 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
+ }
+ });
+
+ process.exit(0);
+ } else {
+ console.log(state);
+ process.exit(1);
+ }
+});
+
+(async () => {
+ await client.startClient({ initialSyncLimit: 0 });
+})(); \ No newline at end of file