forked from batraster1/0l-validator-health
-
Notifications
You must be signed in to change notification settings - Fork 0
/
discordNotifier.js
43 lines (38 loc) · 1.63 KB
/
discordNotifier.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
const { Webhook, MessageBuilder } = require('discord-webhook-node');
const WEBHOOK_NAME = "ValidatorHealth"
const DEFAULT_WEBHOOK = "https://discord.com/api/webhooks/927400770557575279/F2alVR5ZqVTCir-31SCRVcPbEOKuHlKulqRyvem-MuZwCO9xxM8IhvazmO8pXISS6Mzs"
const TEST_WEBHOOK = "https://discord.com/api/webhooks/927400691201372170/bY_U-pUMESzl0MHJ3fXisVU1gbYYrvZI1cwiAGL9yMuObKzsoevGYbv8gAZ5D8KoeSsm"
function sendToWebhooks(validator, fields, color){
if(validator.webhookUrls && validator.webhookUrls.length >0){
const embed = new MessageBuilder().setColor(color)
let footer = `IP: ${validator.ipAddress}`
if(validator.address){
footer += `\nAddress: ${validator.address}`
}
for(let webhookUrl of validator.webhookUrls){
if(webhookUrl === "DEFAULT"){
webhookUrl = DEFAULT_WEBHOOK
}
if(webhookUrl == "TEST"){
webhookUrl = TEST_WEBHOOK
}
if(fields && fields.length > 0){
for(const field of fields){
embed.addField(field.key, field.value)
}
}
let description = ""
if(validator.discordIds && validator.discordIds.length > 0){
for(const discordId of validator.discordIds){
description += `<@${discordId}> `
}
}
embed.setDescription(description)
embed.setFooter(footer)
const hook = new Webhook(webhookUrl)
hook.setUsername(WEBHOOK_NAME)
hook.send(embed)
}
}
}
module.exports = {sendToWebhooks}