From dafc13e090c2895f4098c87bea75bdd52bf38f52 Mon Sep 17 00:00:00 2001 From: "Glitch (hello-express)" Date: Mon, 4 Nov 2019 23:08:36 +0000 Subject: [PATCH] =?UTF-8?q?=E2=AD=90=EF=B8=8F=F0=9F=91=A6=20Checkpoint=20.?= =?UTF-8?q?/server.js:933874/24574?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.js | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/server.js b/server.js index 9b48985..d0266f2 100644 --- a/server.js +++ b/server.js @@ -75,20 +75,36 @@ const listener = app.listen(process.env.PORT, function() { console.log("Your app is listening on port " + listener.address().port); }); -request - .post({ +request.post( + { url: "https://" + process.env.MATRIXUSERNAME.substring( process.env.MATRIXUSERNAME.indexOf(":") + 1 ) + "/_matrix/client/r0/login", - body: JSON.stringify({ type: "m.login.password", user: }), + body: JSON.stringify({ + type: "m.login.password", + user: process.env.MATRIXUSERNAME.substring( + 0, + process.env.MATRIXUSERNAME.indexOf(":") + ), + password: process.env.MATRIXPASSWORD, + identifier: { + type: "m.id.user", + user: process.env.MATRIXUSERNAME.substring( + 0, + process.env.MATRIXUSERNAME.indexOf(":") + ) + } + }), headers: { "Content-Type": "application/json" } - }) - .on("response", function(response) { + }, + function(error, response, body) { + console.log(body); + const token = JSON.parse(body)["access_token"]; const loop = () => { console.log("loop", lastClosed); if (lastSeen < new Date() - 2 * 60 * 1000 && lastClosed < lastSeen) { @@ -108,7 +124,8 @@ request setTimeout(loop, 10 * 1000); }; setTimeout(loop, 1 * 1000); // give some time for presence button to show up (1 min) - }); + } +); if (process.env.PROJECT_DOMAIN != "") { process.on("SIGTERM", function() {