Initial tests semi-working
This commit is contained in:
parent
4049a2264d
commit
903bb9b4c0
64
src/DjsHandlers.js
Normal file
64
src/DjsHandlers.js
Normal file
@ -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]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
22
src/Handlers.js
Normal file
22
src/Handlers.js
Normal file
@ -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();
|
||||||
|
}
|
||||||
|
}
|
16
src/config.json
Normal file
16
src/config.json
Normal file
@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
52
src/index.js
Normal file
52
src/index.js
Normal file
@ -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}`);
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user