forked from DeviaVir/zenbot
/
notify.js
39 lines (35 loc) · 1.05 KB
/
notify.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
module.exports = function notifier (conf) {
var active_notifiers = []
var interactive_notifiers = []
for (var notifier in conf.notifiers) {
if (conf.notifiers[notifier].on) {
var notif = require(`../extensions/notifiers/${notifier}`)(conf.notifiers[notifier])
notif.notifier_name = notifier
active_notifiers.push(notif)
if (conf.notifiers[notifier].interactive) {
interactive_notifiers.push(notif)
}
}
}
return {
pushMessage: function (title, message) {
if (conf.debug) {
console.log(`${title}: ${message}`)
}
active_notifiers.forEach((notifier) => {
if (conf.debug) {
console.log(`Sending push message via ${notifier.notifier_name}`)
}
notifier.pushMessage(title, message)
})
},
onMessage: function (callback) {
interactive_notifiers.forEach((notifier) => {
if (conf.debug) {
console.log(`Receiving message from ${notifier.notifier_name}`)
}
notifier.onMessage(callback)
})
}
}
}