-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
39 lines (29 loc) · 1.02 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const request = require('request');
const sound = require("sound-play");
const chalk = require("chalk");
const success = chalk.green;
const time = chalk.magenta;
const fail = chalk.red;
// URL to refresh
const url = 'http://darkanddarker.com/';
// Function to make a request to the URL and check for JSON data
async function refreshAndCheck() {
let date = new Date();
request(url, (error, response, body) => {
if (!error && response.statusCode == 200) {
try {
const data = JSON.parse(body);
// Play notification
console.log(time('[' + date.toLocaleTimeString() + ']'), success('Dark and Darker Early Access is probably online!'));
sound.play('C://sound.mp3');
} catch (e) {
console.error(e);
}
} else {
console.log(time('[' + date.toLocaleTimeString() + ']'), fail("Dark and Darker Early Access is still offline."));
}
});
};
// Refresh in milliseconds (5 minutes).
refreshAndCheck();
setInterval(refreshAndCheck, 300000);