Compare commits

...

3 Commits

Author SHA1 Message Date
903bb9b4c0 Initial tests semi-working 2024-09-22 13:47:11 -04:00
4049a2264d Maintenance 2024-09-22 13:46:52 -04:00
503d2029ff Add a setup script and docker-compose 2024-09-22 13:46:29 -04:00
11 changed files with 1359 additions and 0 deletions

17
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}\\src\\index.js"
}
]
}

30
.vscode/snips.code-snippets vendored Normal file
View File

@ -0,0 +1,30 @@
{
// Place your custom-scripts workspace snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
// Placeholders with the same ids are connected.
// Example:
// "Print to console": {
// "scope": "javascript,typescript",
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
"Banner Comment": {
"scope": "javascript,typescript",
"description": "Banner Comment",
"prefix": "///",
"body": [
"// #############################################################",
"// $1",
"// #############################################################",
"$2"
]
}
}

8
Dockerfile Normal file
View File

@ -0,0 +1,8 @@
FROM node:20
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json ./
RUN npm install
COPY . .
CMD ["/bin/sh", "-c", "node src/index.js 2>&1 > /logs/$(date +%Y-%m-%d_%H-%M-%S).txt"]

22
docker-compose.yml Normal file
View File

@ -0,0 +1,22 @@
version: '3.8'
networks:
proxnet:
external: true
services:
proxy:
image: 'v0idf1sh/hookshot'
container_name: hookshot
restart: unless-stopped
networks:
- proxnet
environment:
- TOPGG_WH_ID: "id"
- TOPGG_WH_TOKEN: "token"
- UPTIMEKUMA_WH_ID: "id"
- UPTIMEKUMA_WH_TOKEN: "token"
- TESTING_WH_ID: "id"
- TESTING_WH_TOKEN: "token"
volumes:
- ./logs:/logs # Log files

1085
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

24
package.json Normal file
View File

@ -0,0 +1,24 @@
{
"name": "hookshot",
"version": "1.0.0",
"description": "Quick and sloppy intermediary webhook server. Designed to relay messages to Discord from other webhook triggers.",
"main": "src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://git.vfsh.dev/voidf1sh/hookshot"
},
"keywords": [
"webhook",
"discord"
],
"author": "Skylar Grant",
"license": "MIT",
"dependencies": {
"discord.js": "^14.16.2",
"dotenv": "^16.4.5",
"express": "^4.21.0"
}
}

19
setup.sh Normal file
View File

@ -0,0 +1,19 @@
#!/bin/bash
# Check for root
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
# Create directories if they don't exist
mkdir -p /srv/docker/hookshot/logs
# Copy the docker-compose.yml file
cp docker-compose.yml /srv/docker/hookshot/docker-compose.yml
# Open the docker-compose.yml file for editing
nano /srv/docker/hookshot/docker-compose.yml
# Start the containers
docker-compose -f /srv/docker/hookshot/docker-compose.yml up -d

64
src/DjsHandlers.js Normal file
View 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
View 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
View 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
View 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}`);
});