-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotifier.js
31 lines (28 loc) · 1012 Bytes
/
notifier.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
const notifier = require('node-notifier');
const fetch = require('node-fetch');
const strings = require('./strings.json');
const config = require('./config.json');
console.log(strings.READY);
/**
* getHQStatus() pings the HQ Trivia API every x seconds.
* (x being defined in config.json)
* This allows it to determine if an HQ Trivia show is active.
*/
function getHQStatus() {
setTimeout(() => {
fetch(`https://api-quiz.hype.space/shows/now?type=${config.type}`).then((response) => response.json()).then((json) => {
if (json.active == true) {
console.log(strings.LIVE);
notifier.notify({
title: strings.NOTIFIER_TITLE,
message: strings.NOTIFIER_MESSAGE,
icon: './assets/HQ.png',
}, () => process.exit(0));
} else {
console.log(strings.NOT_LIVE);
}
});
getHQStatus();
}, config.interval * 1000);
}
getHQStatus();