-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension.js
86 lines (80 loc) · 2.22 KB
/
extension.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
'use strict';
const request = require('request');
const querystring = require('querystring');
module.exports = function (nodecg) {
if (!nodecg.bundleConfig) {
throw new Error('cfg/lfg-omega13.json not found, this config file is required!');
}
nodecg.listenFor('help', (message, cb) => {
if (nodecg.bundleConfig.pushover && nodecg.bundleConfig.pushover.enabled) {
request.post({
url: 'https://api.pushover.net/1/messages.json',
body: querystring.stringify({
token: nodecg.bundleConfig.appToken,
user: nodecg.bundleConfig.deliveryToken,
title: `${nodecg.config.host} requires assistance`,
message: message || 'No message provided.',
priority: nodecg.bundleConfig.priority || 2,
retry: nodecg.bundleConfig.retry || 30,
expire: nodecg.bundleConfig.expire || 3600
})
}, (err, res, body) => {
if (err) {
nodecg.log.error(err.stack);
cb(false);
return;
}
let json;
try {
json = JSON.parse(body);
} catch (e) {
nodecg.log.error('Could not parse response to JSON:', e.stack);
cb(false);
return;
}
/* eslint-disable no-lonely-if */
if (json.status === 1) {
cb(true);
} else {
if (json.errors) {
const resErrString = json.errors.join('. ');
nodecg.log.error(resErrString);
cb(false);
} else {
nodecg.log.error('Unknown error:', json);
cb(false);
}
}
/* eslint-enable no-lonely-if */
});
}
if (nodecg.bundleConfig.slack && nodecg.bundleConfig.slack.enabled) {
request.post({
headers: {'content-type': 'application/json'},
url: nodecg.bundleConfig.slack.url,
body: JSON.stringify({
username: nodecg.bundleConfig.slack.user,
channel: nodecg.bundleConfig.slack.destination,
attachments: [{
fallback: `${nodecg.config.host} requires assistance! ${message}`,
color: 'danger',
title: `Help requested by ${nodecg.config.host}`,
text: message || 'No message provided.'
}]
})
}, (err, res, body) => {
if (err) {
nodecg.log.error(err.stack);
cb(false);
return;
}
if (body === 'ok') {
cb(true);
} else {
nodecg.log.error('Unknown error:', body);
cb(false);
}
});
}
});
};