From 7e9d5bbafabdc4ab9eacecaf2a3b0b12791678b0 Mon Sep 17 00:00:00 2001 From: Lexi Sother Date: Tue, 2 Mar 2021 15:57:58 +0000 Subject: [PATCH] Added Discord webhook --- src/index.js | 3 +++ src/webhook.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 src/webhook.js diff --git a/src/index.js b/src/index.js index f52f400..24c9075 100644 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,6 @@ import ModuleRepos from './modules/index.js'; import AutoTag from './autoTag.js'; +import WebhookSend from './webhook.js'; import Parcel from 'parcel-bundler'; import axios from 'axios'; @@ -206,3 +207,5 @@ for (const parentRepo of ModuleRepos) { writeFileSync(`${distDir}/modules.json`, JSON.stringify(oldTotalModulesJson)); copyFileSync(`${__dirname.replace('/src', '')}/_headers`, `${distDir}/_headers`); + +WebhookSend(); diff --git a/src/webhook.js b/src/webhook.js new file mode 100644 index 0000000..c627b75 --- /dev/null +++ b/src/webhook.js @@ -0,0 +1,44 @@ +import * as https from 'https'; + +export default () => { + const data = JSON.stringify({ + username: 'NovaStore', + embeds: [ + { + title: 'Module Store Updated', + url: 'https://goose.lexisother.tk/nova.json', + timestamp: new Date(), + author: { + name: 'Nova Module Store', + icon_url: 'https://goosemod.com/img/logo.jpg', + }, + }, + ], + }); + + const options = { + hostname: 'discord.com', + path: `/api/webhooks/816327784121106452/${process.env.HOOKTOKEN}`, + port: 443, + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'Content-Length': data.length, + }, + }; + + const req = https.request(options, (res) => { + console.log(`Status code: ${res.statusCode}`); + + res.on('data', (d) => { + process.stdout.write(d); + }); + }); + + req.on('error', (err) => { + console.error(err); + }); + + req.write(data); + req.end(); +};