Added discord notifier...

This commit is contained in:
BurnyLlama 2022-05-27 14:48:43 +02:00
parent d23154d596
commit ae3c53ac6f
4 changed files with 31 additions and 2 deletions

View File

@ -10,4 +10,4 @@ log("Starting up notifiers...")
const enabledNotifiers = Object.keys(settings.notifiers).filter(notifier => settings.notifiers[notifier].enabled) const enabledNotifiers = Object.keys(settings.notifiers).filter(notifier => settings.notifiers[notifier].enabled)
const notifiers = await Promise.all(enabledNotifiers.map(notifier => getNotifier(notifier))) const notifiers = await Promise.all(enabledNotifiers.map(notifier => getNotifier(notifier)))
console.dir(notifiers) notifiers.forEach(notifier => notifier("Started up 'maintenance-bot'..."))

View File

@ -0,0 +1,28 @@
import { Client, Intents } from "discord.js"
import settings from "../../libs/settings.js"
import getLogger from "../../libs/logger.js"
const log = getLogger("Discord", settings.notifiers.discord.color)
export async function start() {
log("Starting Discord notifier...")
const client = new Client({ intents: [ Intents.FLAGS.DIRECT_MESSAGES ]})
async function sendMessage(msg) {
const receivers = await Promise.all(settings.notifiers.discord.receivers.map(id => client.users.fetch(id)))
log("Sending messages to:", receivers.map(e => e.tag))
receivers.forEach(async receiver => {
await receiver.createDM()
await receiver.send(msg)
})
}
client.once("ready", () => {
log(`Logged in as ${client.user.username}`)
})
await client.login(settings.notifiers.discord["api-token"])
return sendMessage
}

View File

@ -19,6 +19,7 @@ export async function start() {
async function sendMessage(msg) { async function sendMessage(msg) {
const receivers = settings.notifiers.xmpp.receivers const receivers = settings.notifiers.xmpp.receivers
log("Sending messages to:", receivers)
const stanzas = receivers.map( const stanzas = receivers.map(
address => xml( address => xml(
"message", "message",
@ -36,7 +37,6 @@ export async function start() {
xmpp.on("online", address => { xmpp.on("online", address => {
log(`Logged in as ${address.toString()}`) log(`Logged in as ${address.toString()}`)
sendMessage("Started up 'maintenance-bot'...")
}) })
await xmpp.start().catch(console.error) await xmpp.start().catch(console.error)

View File

@ -17,6 +17,7 @@
"@xmpp/client": "^0.13.1", "@xmpp/client": "^0.13.1",
"@xmpp/debug": "^0.13.0", "@xmpp/debug": "^0.13.0",
"colors": "^1.4.0", "colors": "^1.4.0",
"discord.js": "^13.7.0",
"yaml": "^2.1.0" "yaml": "^2.1.0"
} }
} }