1
0
mirror of https://api.glitch.com/git/presence-button synced 2024-12-05 02:17:29 +00:00

👦 Checkpoint

./server.js:933874/24574
This commit is contained in:
Glitch (hello-express) 2019-11-04 23:08:36 +00:00
parent 5b893c58a2
commit dafc13e090

View File

@ -75,20 +75,36 @@ const listener = app.listen(process.env.PORT, function() {
console.log("Your app is listening on port " + listener.address().port); console.log("Your app is listening on port " + listener.address().port);
}); });
request request.post(
.post({ {
url: url:
"https://" + "https://" +
process.env.MATRIXUSERNAME.substring( process.env.MATRIXUSERNAME.substring(
process.env.MATRIXUSERNAME.indexOf(":") + 1 process.env.MATRIXUSERNAME.indexOf(":") + 1
) + ) +
"/_matrix/client/r0/login", "/_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: { headers: {
"Content-Type": "application/json" "Content-Type": "application/json"
} }
}) },
.on("response", function(response) { function(error, response, body) {
console.log(body);
const token = JSON.parse(body)["access_token"];
const loop = () => { const loop = () => {
console.log("loop", lastClosed); console.log("loop", lastClosed);
if (lastSeen < new Date() - 2 * 60 * 1000 && lastClosed < lastSeen) { if (lastSeen < new Date() - 2 * 60 * 1000 && lastClosed < lastSeen) {
@ -108,7 +124,8 @@ request
setTimeout(loop, 10 * 1000); setTimeout(loop, 10 * 1000);
}; };
setTimeout(loop, 1 * 1000); // give some time for presence button to show up (1 min) setTimeout(loop, 1 * 1000); // give some time for presence button to show up (1 min)
}); }
);
if (process.env.PROJECT_DOMAIN != "") { if (process.env.PROJECT_DOMAIN != "") {
process.on("SIGTERM", function() { process.on("SIGTERM", function() {