diff --git a/src/DjsHandlers.js b/src/DjsHandlers.js new file mode 100644 index 0000000..363322e --- /dev/null +++ b/src/DjsHandlers.js @@ -0,0 +1,64 @@ +// ############################################################# +// Module Imports +// ############################################################# +const { EmbedBuilder, WebhookClient } = require('discord.js'); +const config = require('./config.json'); +const dotenv = require('dotenv').config(); + +// ############################################################# +// Variables +// ############################################################# +const whInfo = { + "topgg": { + id: process.env.TOPGG_WH_ID, + token: process.env.TOPGG_WH_TOKEN + }, + "uptimeKuma": { + id: process.env.UPTIMEKUMA_WH_ID, + token: process.env.UPTIMEKUMA_WH_TOKEN + }, + "testing": { + id: process.env.TESTING_WH_ID, + token: process.env.TESTING_WH_TOKEN + } +} + +module.exports = { + testing() { + // Create a new WebhookClient + const webhookClient = new WebhookClient({ id: whInfo.testing.id, token: whInfo.testing.token }); + + // Create a new EmbedBuilder + const embed = new EmbedBuilder() + .setTitle('Webhook Test') + .setDescription('This is a test of the WebhookClient') + .setTimestamp(); + + // Send the Embed + webhookClient.send({ + content: 'This is a test of the WebhookClient', + username: config.discord.testing.username, + avatarURL: config.discord.testing.avatarURL, + embeds: [embed] + }); + }, + topgg(body) { + console.log(body); + // Create a new WebhookClient + const webhookClient = new WebhookClient({ id: whInfo.topgg.id, token: whInfo.topgg.token }); + + // Create a new EmbedBuilder + const embed = new EmbedBuilder() + .setTitle('Top.gg Vote') + .setDescription(`User ID: ${body.user}`) + .setTimestamp(); + + // Send the Embed + webhookClient.send({ + content: 'A user has voted for the bot on top.gg', + username: config.discord.topgg.username, + avatarURL: config.discord.topgg.avatarURL, + embeds: [embed] + }); + } +} \ No newline at end of file diff --git a/src/Handlers.js b/src/Handlers.js new file mode 100644 index 0000000..f38eac4 --- /dev/null +++ b/src/Handlers.js @@ -0,0 +1,22 @@ +const djs = require('./DjsHandlers.js'); + +module.exports = { + generic(req, res) { + // Handle generic webhook payload here + console.log('Received generic webhook payload:', req.body); + res.sendStatus(200); + djs.testing(); + }, + topgg(req, res) { + // Handle top.gg vote webhook payload here + console.log('Received top.gg vote webhook payload:', req.body); + res.sendStatus(200); + djs.topggVote(); + }, + uptimeKuma(req, res) { + // Handle Uptime Kuma webhook payload here + console.log('Received Uptime Kuma webhook payload:', req.body); + res.sendStatus(200); + djs.uptimeKumaAlert(); + } +} \ No newline at end of file diff --git a/src/config.json b/src/config.json new file mode 100644 index 0000000..700bc3e --- /dev/null +++ b/src/config.json @@ -0,0 +1,16 @@ +{ + "discord": { + "testing": { + "username": "testing", + "avatarUrl": "https://assets.vfsh.dev/shednod.png" + }, + "topgg": { + "username": "topgg", + "avatarUrl": "https://assets.vfsh.dev/shednod.png" + }, + "uptimeKuma": { + "username": "uptimeKuma", + "avatarUrl": "https://assets.vfsh.dev/shednod.png" + } + } +} \ No newline at end of file diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..8566ff1 --- /dev/null +++ b/src/index.js @@ -0,0 +1,52 @@ +// ############################################################# +// Module Imports +// ############################################################# +const express = require('express'); +const dotenv = require('dotenv'); +const handlers = require('./Handlers.js'); + +// ############################################################# +// Variables +// ############################################################# +const port = 3000; +const locations = { + "topgg": "/hooks/vote", + "uptimeKuma": "/hooks/uptime" +}; + +// ############################################################# +// Setup +// ############################################################# +dotenv.config(); +const app = express(); + +app.use(express.json()); + +// ############################################################# +// Webhook Listeners +// ############################################################# + +// Genertic Webhook +app.post('/webhook', handlers.generic); + +// Top.gg Votes +app.post(locations.topgg, handlers.topgg); + +// Uptime Kuma Alerts +app.post(locations.uptimeKuma, handlers.uptimeKuma); + +// Genertic Webhook +app.get('/webhook', handlers.generic); + +// Top.gg Votes +app.get(locations.topgg, handlers.topgg); + +// Uptime Kuma Alerts +app.get(locations.uptimeKuma, handlers.uptimeKuma); + +// ############################################################# +// Function Calls / Start Listening +// ############################################################# +app.listen(port, () => { + console.log(`Webhook server is running on port ${port}`); +}); \ No newline at end of file