implement discord

This commit is contained in:
LouisLam
2021-07-10 11:38:00 +08:00
parent ff4259380e
commit 44bcd78f9a
4 changed files with 110 additions and 6 deletions

View File

@@ -2,6 +2,7 @@ const axios = require("axios");
const {R} = require("redbean-node");
const FormData = require('form-data');
const nodemailer = require("nodemailer");
const Discord = require('discord.js');
class Notification {
static async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
@@ -51,6 +52,10 @@ class Notification {
} else if (notification.type === "smtp") {
return await Notification.smtp(notification, msg)
} else if (notification.type === "discord") {
return await Notification.discord(notification, msg)
} else {
throw new Error("Notification type is not supported")
}
@@ -114,6 +119,19 @@ class Notification {
return true;
}
static async discord(notification, msg) {
const client = new Discord.Client();
await client.login(notification.discordToken)
console.log(notification.discordChannelID)
const channel = await client.channels.fetch(notification.discordChannelID);
await channel.send(msg);
client.destroy()
return true;
}
}
module.exports = {