diff --git a/.gitignore b/.gitignore index 9a357a0..2276d0a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -node_modules -.github \ No newline at end of file +.github +node_modules \ No newline at end of file diff --git a/examples/top-gg.js b/examples/top-gg.js new file mode 100644 index 0000000..63c756f --- /dev/null +++ b/examples/top-gg.js @@ -0,0 +1,35 @@ +const discord = require("discord.js"); +const client = discord.Client(); + +const { WebhooksManager } = require("blwebhooks"); + +// Attatch The Client and Port to the module. +// The client is it attaching to the client, 80 is the port it will run on +const voteClient = new WebhooksManager(client, 80); +client.voteManager = voteClient; + +voteClient.extraProtection(true); + +voteClient.topggVoteHook("topgg", "LOADS_OF_RANDOMNESS", true); + +// This code will run after a new vote was received from Botrix +client.on("BTR-voted", async function (userID) { + console.log(`${userID} Voted!`); + + // Add role for 24 hours + const guildD = client.guilds.cache.get("721282458708082713"); + guildD.members + .fetch(userID) + .catch(() => null) + .then((member) => { + if (!member) return; + + member.roles.add("748340144897261660"); + + setTimeout( + () => member.roles.remove("748340144897261660").catch(console.error), + 1000 * 60 * 60 * 24 + ); + }) + .catch(() => {}); +}); diff --git a/package-lock.json b/package-lock.json index 7d660e2..417d6e3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "blwebhooks", - "version": "2.1.0", + "version": "2.1.4", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -341,12 +341,6 @@ "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=", "optional": true }, - "at-least-node": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/at-least-node/-/at-least-node-1.0.0.tgz", - "integrity": "sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==", - "dev": true - }, "aws-sign2": { "version": "0.7.0", "resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.7.0.tgz", @@ -549,12 +543,6 @@ "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" }, - "colors": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz", - "integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==", - "dev": true - }, "combined-stream": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", @@ -947,6 +935,11 @@ "integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=", "dev": true }, + "deepmerge": { + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-4.2.2.tgz", + "integrity": "sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg==" + }, "defaults": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/defaults/-/defaults-1.0.3.tgz", @@ -1559,18 +1552,6 @@ "null-check": "^1.0.0" } }, - "fs-extra": { - "version": "9.1.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.1.0.tgz", - "integrity": "sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ==", - "dev": true, - "requires": { - "at-least-node": "^1.0.0", - "graceful-fs": "^4.2.0", - "jsonfile": "^6.0.1", - "universalify": "^2.0.0" - } - }, "fs-minipass": { "version": "1.2.7", "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-1.2.7.tgz", @@ -2217,16 +2198,6 @@ "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=" }, - "jsonfile": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", - "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", - "dev": true, - "requires": { - "graceful-fs": "^4.1.6", - "universalify": "^2.0.0" - } - }, "jsonparse": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/jsonparse/-/jsonparse-1.3.1.tgz", @@ -2344,24 +2315,12 @@ } } }, - "lunr": { - "version": "2.3.9", - "resolved": "https://registry.npmjs.org/lunr/-/lunr-2.3.9.tgz", - "integrity": "sha512-zTU3DaZaF3Rt9rhN3uBMGQD3dD2/vFQqnvZCDv4dl5iOzq2IZQqTxu90r4E5J+nP70J3ilqVCrbho2eWaeW8Ow==", - "dev": true - }, "map-obj": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/map-obj/-/map-obj-4.1.0.tgz", "integrity": "sha512-glc9y00wgtwcDmp7GaE/0b0OnxpNJsVf3ael/An6Fe2Q51LLwN1er6sdomLRzz5h0+yMpiYLhWYF5R7HeqVd4g==", "dev": true }, - "marked": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/marked/-/marked-2.0.0.tgz", - "integrity": "sha512-NqRSh2+LlN2NInpqTQnS614Y/3NkVMFFU6sJlRFEpxJ/LHuK/qJECH7/fXZjk4VZstPW/Pevjil/VtSONsLc7Q==", - "dev": true - }, "media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", @@ -2857,26 +2816,6 @@ "wrappy": "1" } }, - "onigasm": { - "version": "2.2.5", - "resolved": "https://registry.npmjs.org/onigasm/-/onigasm-2.2.5.tgz", - "integrity": "sha512-F+th54mPc0l1lp1ZcFMyL/jTs2Tlq4SqIHKIXGZOR/VkHkF9A7Fr5rRr5+ZG/lWeRsyrClLYRq7s/yFQ/XhWCA==", - "dev": true, - "requires": { - "lru-cache": "^5.1.1" - }, - "dependencies": { - "lru-cache": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz", - "integrity": "sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w==", - "dev": true, - "requires": { - "yallist": "^3.0.2" - } - } - } - }, "optionator": { "version": "0.9.1", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.1.tgz", @@ -3484,16 +3423,6 @@ "rechoir": "^0.6.2" } }, - "shiki": { - "version": "0.9.2", - "resolved": "https://registry.npmjs.org/shiki/-/shiki-0.9.2.tgz", - "integrity": "sha512-BjUCxVbxMnvjs8jC4b+BQ808vwjJ9Q8NtLqPwXShZ307HdXiDFYP968ORSVfaTNNSWYDBYdMnVKJ0fYNsoZUBA==", - "dev": true, - "requires": { - "onigasm": "^2.2.5", - "vscode-textmate": "^5.2.0" - } - }, "sift": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/sift/-/sift-7.0.1.tgz", @@ -3978,36 +3907,6 @@ "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=", "dev": true }, - "typedoc": { - "version": "0.20.26", - "resolved": "https://registry.npmjs.org/typedoc/-/typedoc-0.20.26.tgz", - "integrity": "sha512-w532YfkrTnic5Vz71k67HNwF2KoCGS9leycA5pbRX4SUD6qGBbv6aD/xtYPF3ot2xE5FSjrxSOxfIvjA6MkMCA==", - "dev": true, - "requires": { - "colors": "^1.4.0", - "fs-extra": "^9.1.0", - "handlebars": "^4.7.6", - "lodash": "^4.17.20", - "lunr": "^2.3.9", - "marked": "^2.0.0", - "minimatch": "^3.0.0", - "progress": "^2.0.3", - "shelljs": "^0.8.4", - "shiki": "^0.9.2", - "typedoc-default-themes": "^0.12.7" - } - }, - "typedoc-default-themes": { - "version": "0.12.7", - "resolved": "https://registry.npmjs.org/typedoc-default-themes/-/typedoc-default-themes-0.12.7.tgz", - "integrity": "sha512-0XAuGEqID+gon1+fhi4LycOEFM+5Mvm2PjwaiVZNAzU7pn3G2DEpsoXnFOPlLDnHY6ZW0BY0nO7ur9fHOFkBLQ==", - "dev": true - }, - "typescript": { - "version": "4.1.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.1.5.tgz", - "integrity": "sha512-6OSu9PTIzmn9TCDiovULTnET6BgXtDYL4Gg4szY+cGsc3JP1dQL8qvE8kShTRx1NIw4Q9IBHlwODjkjWEtMUyA==" - }, "uglify-js": { "version": "3.12.8", "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.12.8.tgz", @@ -4015,12 +3914,6 @@ "dev": true, "optional": true }, - "universalify": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz", - "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==", - "dev": true - }, "unpipe": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", @@ -4082,12 +3975,6 @@ "extsprintf": "^1.2.0" } }, - "vscode-textmate": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/vscode-textmate/-/vscode-textmate-5.2.0.tgz", - "integrity": "sha512-Uw5ooOQxRASHgu6C7GVvUxisKXfSgW4oFlO+aa+PAkgmH89O3CXxEEzNRNtHSqtXFTl0nAC1uYj0GMSH27uwtQ==", - "dev": true - }, "which": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", diff --git a/package.json b/package.json index 045b8dc..3898801 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "body-parser": "^1.19.0", "chalk": "^4.1.0", "cookie-parser": "^1.4.5", + "deepmerge": "^4.2.2", "errorhandler": "^1.5.1", "events": "^3.2.0", "express": "^4.17.1", diff --git a/src/Client.js b/src/Client.js index a0a469c..b52cc91 100644 --- a/src/Client.js +++ b/src/Client.js @@ -6,394 +6,571 @@ const bodyParser = require("body-parser"); const slowDown = require("express-slow-down"); const rateLimit = require("express-rate-limit"); const chalk = require("chalk"); +const merge = require("deepmerge"); const { EventEmitter } = require("events"); const errorhandler = require("errorhandler"); const mongoose = require("mongoose"); const VotingModel = require("./Models/vote.js"); +const { defaultManager } = require("./Constants.js"); + const speedLimiter = slowDown({ - windowMs: 15 * 60 * 1000, - delayAfter: 250, - delayMs: 400 + windowMs: 15 * 60 * 1000, + delayAfter: 250, + delayMs: 400, }); const limiter = rateLimit({ - windowMs: 15 * 60 * 1000, - max: 250 + windowMs: 15 * 60 * 1000, + max: 250, }); /** * Webhook Manager */ class WebhooksManager extends EventEmitter { + /** + * @param {Discord.Client} client The Discord Client + * @param {Express.Port} Webserver port + */ + constructor(client, port, options) { + super(); + console.log(chalk.red("-----------------------")); + console.log( + "All Manager Options Updated Check Our Docs Now! https://github.com/MaximKing1/BLWebhooks#readme" + ); + console.log(chalk.red("----------------------")); + /** - * @param {Discord.Client} client The Discord Client - * @param {Express.Port} Webserver port + * The Discord Client + * @type {discord.Client} */ - constructor(client, port, options) { - super(); - console.log(chalk.red("-----------------------")); - console.log("All Manager Options Updated Check Our Docs Now! https://github.com/MaximKing1/BLWebhooks#readme"); - console.log(chalk.red("----------------------")); - - /** - * The Discord Client - * @type {discord.Client} - */ - this.client = client; - /** - * The Port - * @type {Express.Port} - */ - this.port = port; - /** - * The WebhooksManager Database - * @param {client.ready} - */ - this.database = options.database; - - if (!client) { - return console.log(chalk.red("[BLWEBHOOKS] The client is not defined")); - } - else if (!port) { - return console.log(chalk.red("[BLWEBHOOKS] The port is required!")); - } - else if (typeof port != "number") { - return console.log(chalk.red("[BLWEBHOOKS] The port is a number.")); - } - else if (client) { - console.log(chalk.green("[BLWEBHOOKS] The Client has connected to BLWebhooks")); - } - if (port) { - app.listen(port); - app.use(bodyParser.json()); - app.use(limiter); - app.use(speedLimiter); - app.use(cookieParser()); - console.log(chalk.green(`[BLWEBHOOKS] The Vote Webserver Has Started On Port ${port}.`)); - } - } + this.client = client; + /** + * The Port + * @type {Express.Port} + */ + this.port = port; + /** + * The manager options + * @type {WebhooksManagerOptions} + */ + this.options = merge(defaultManager, options); - async shardedClient(toggle) { - if (toggle == true) { - console.log(chalk.green("[BLWEBHOOKS] Sharding client has been enabled.")); - } - else if (toggle == false) { - console.log(chalk.red("[BLWEBHOOKS] Sharding client has been disabled.")); - } + if (!client) { + return console.log(chalk.red("[BLWEBHOOKS] The client is not defined")); + } else if (!port) { + return console.log(chalk.red("[BLWEBHOOKS] The port is required!")); + } else if (typeof port != "number") { + return console.log(chalk.red("[BLWEBHOOKS] The port is a number.")); + } else if (client) { + console.log( + chalk.green("[BLWEBHOOKS] The Client has connected to BLWebhooks") + ); } - - async setStroage(DB, string) { - if (DB == "mongo") { - console.log(chalk.yellow("[BLWEBHOOKS] Enabled mongoose database.")); - await mongoose.connect(string, { - useNewUrlParser: true, - useUnifiedTopology: true, - useFindAndModify: false, - useCreateIndex: true - }); - } - else if(DB == "sqlite") { - var sqlite3 = require("sqlite3").verbose(); - this.db = new sqlite3.Database("voteHooks.db", async (err) => { - if (err) { - console.error(chalk.red(err.message)); - } - console.log(chalk.yellow("[BLWEBHOOKS] Enabled SQLITE database.")); - console.log(chalk.yellow("[BLWEBHOOKS] Connected to the voteHooks.db database.")); - }); - } else if (DB == "mysql") { - console.log(chalk.yellow("[BLWEBHOOKS] Enabled MYSQL database.")); - } + if (port) { + app.listen(port); + app.use(bodyParser.json()); + app.use(limiter); + app.use(speedLimiter); + app.use(cookieParser()); + console.log( + chalk.green( + `[BLWEBHOOKS] The Vote Webserver Has Started On Port ${port}.` + ) + ); } + } - async setLogging(toggle) { - if (toggle == true) { - console.log(chalk.green("[BLWEBHOOKS] Advanced logging enabled.")); - return app.use(errorhandler()); - } - else if (toggle == false) { - console.log(chalk.red("[BLWEBHOOKS] Advance logging disabled")); - } + async shardedClient(toggle) { + if (toggle == true) { + console.log( + chalk.green("[BLWEBHOOKS] Sharding client has been enabled.") + ); + } else if (toggle == false) { + console.log(chalk.red("[BLWEBHOOKS] Sharding client has been disabled.")); } + } - async extraProtection(toggle) { - if (toggle == true) { - console.log(chalk.green("[BLWEBHOOKS] Extra protection enabled.")); - return app.use(helmet({ contentSecurityPolicy: false, permittedCrossDomainPolicies: false })); - } - else if (toggle == false) { - console.log(chalk.red("[BLWEBHOOKS] Extra protection disabled.")); + async setStroage(DB, string) { + if (DB == "mongo") { + console.log(chalk.yellow("[BLWEBHOOKS] Enabled mongoose database.")); + await mongoose.connect(string, { + useNewUrlParser: true, + useUnifiedTopology: true, + useFindAndModify: false, + useCreateIndex: true, + }); + } else if (DB == "sqlite") { + var sqlite3 = require("sqlite3").verbose(); + this.db = new sqlite3.Database("voteHooks.db", async (err) => { + if (err) { + console.error(chalk.red(err.message)); } + console.log(chalk.yellow("[BLWEBHOOKS] Enabled SQLITE database.")); + console.log( + chalk.yellow("[BLWEBHOOKS] Connected to the voteHooks.db database.") + ); + }); + } else if (DB == "mysql") { + console.log(chalk.yellow("[BLWEBHOOKS] Enabled MYSQL database.")); } + } - async proxyTrust(toggle) { - if (toggle == true) { - console.log(chalk.green("[BLWEBHOOKS] Proxy trust enabled.")); - return app.enable("trust proxy"); - } - else if (toggle == false) { - console.log(chalk.red("[BLWEBHOOKS] Proxy trust disabled.")); - } - } // Enable this if your behind a proxy, Heroku, Docker, Replit, etc - - async testVote(userID, botID) { - const type = "test"; - const List = "Test"; - console.log(userID + " Voted For " + botID); - this.client.emit("vote", userID, botID, List); - this.client.emit("topgg-voted", userID, botID, type); - this.client.emit("IBL-voted", userID, botID, type); + async setLogging(toggle) { + if (toggle == true) { + console.log(chalk.green("[BLWEBHOOKS] Advanced logging enabled.")); + return app.use(errorhandler()); + } else if (toggle == false) { + console.log(chalk.red("[BLWEBHOOKS] Advance logging disabled")); } - - async getServer(serverID) { - let server = this.client.guilds.cache.get(serverID); - return server; + } + + async extraProtection(toggle) { + if (toggle == true) { + console.log(chalk.green("[BLWEBHOOKS] Extra protection enabled.")); + return app.use( + helmet({ + contentSecurityPolicy: false, + permittedCrossDomainPolicies: false, + }) + ); + } else if (toggle == false) { + console.log(chalk.red("[BLWEBHOOKS] Extra protection disabled.")); } + } - async topggVoteHook(url, auth, toggle) { - if (toggle == false) { - return console.log(chalk.red("[BLWEBHOOKS] Top.gg vote hooks have been disabled.")); - } - else if (toggle == true) { - console.log(chalk.green("[BLWEBHOOKS] Top.gg vote hooks have been enabled.")); - } - const TopGG = require("@top-gg/sdk"); - const WH = new TopGG.Webhook(auth); - app.post(`/${url}`, WH.middleware(), async (req, res) => { - // Respond to invalid requests - res.setHeader("X-Powered-By", "BLWebhooks.js/Express"); - if (req.header("Authorization") != auth) - console.log("Failed Access - Top.gg Endpoint"); - console.log(req.vote); - // VotingModel.findOneAndUpdate({ userID : req.vote.user }, {$inc : {'totalVotes' : 1}}); - const userID = req.vote.user; - const botID = req.vote.bot; - const type = req.vote.type; - const List = "top.gg"; - this.client.emit("topgg-voted", userID, botID, type); - this.client.emit("vote", userID, botID, List); - setTimeout(() => this.client.emit("voteExpired", userID, botID, List), 1000 * 60 * 60 * 24); - - res.status(200).send(JSON.stringify({ error: false, message: "[BLWEBHOOKS] Received The Request!" })); - }); + async proxyTrust(toggle) { + if (toggle == true) { + console.log(chalk.green("[BLWEBHOOKS] Proxy trust enabled.")); + return app.enable("trust proxy"); + } else if (toggle == false) { + console.log(chalk.red("[BLWEBHOOKS] Proxy trust disabled.")); } - async IBLVoteHook(url, auth, toggle) { - if (toggle == false) { - return console.log(chalk.red("[BLWEBHOOKS] InfinityBotList vote hooks have been disabled.")); - } - else if (toggle == true) { - console.log(chalk.green("[BLWEBHOOKS] InfinityBotList vote hooks have been enabled.")); - } - app.post(`/${url}`, async (req, res) => { - // Respond to invalid requests - res.setHeader("X-Powered-By", "BLWebhooks.js/Express"); - if (req.header("Authorization") != auth) - console.log("Failed Access - InfinityBotList Endpoint"); - if (req.header("Authorization") != auth) - return res.status(403).send(JSON.stringify({ error: true, message: "[BLWEBHOOKS] You don't have access to use this endpoint. - InfinityBotList" })); - - // Use the data on whatever you want - console.log(req.body); - // VotingModel.findOneAndUpdate({ userID : req.vote.user }, {$inc : {'totalVotes' : 1}}); - const userID = req.body.userID; - const botID = req.body.botID; - const type = req.body.type; - const List = "InfinityBotList"; - this.client.emit("IBL-voted", userID, botID, type); - this.client.emit("vote", userID, botID, List); - setTimeout(() => this.client.emit("voteExpired", userID, botID, List), 1000 * 60 * 60 * 24); - - // Respond to IBL API - res.status(200).send(JSON.stringify({ error: false, message: "[BLWEBHOOKS] Received the request!" })); - }); + } // Enable this if your behind a proxy, Heroku, Docker, Replit, etc + + async testVote(userID, botID) { + const type = "test"; + const List = "Test"; + console.log(userID + " Voted For " + botID); + this.client.emit("vote", userID, botID, List); + this.client.emit("topgg-voted", userID, botID, type); + this.client.emit("IBL-voted", userID, botID, type); + } + + async getServer(serverID) { + let server = this.client.guilds.cache.get(serverID); + return server; + } + + async topggVoteHook(url, auth, toggle) { + if (toggle == false) { + return console.log( + chalk.red("[BLWEBHOOKS] Top.gg vote hooks have been disabled.") + ); + } else if (toggle == true) { + console.log( + chalk.green("[BLWEBHOOKS] Top.gg vote hooks have been enabled.") + ); } - async VoidBotsVoteHook(url, auth, toggle) { - if (toggle == false) { - return console.log(chalk.red("[BLWEBHOOKS] Void Bots vote hooks have been disabled.")); - } - else if (toggle == true) { - console.log(chalk.green("[BLWEBHOOKS] Void Bots vote hooks have been enabled.")); - } - app.post(`/${url}`, async (req, res) => { - // Respond to invalid requests - res.setHeader("X-Powered-By", "BLWebhooks.js/Express"); - if (req.header("Authorization") != auth) - console.log("Failed Access - VoidBots Endpoint"); - if (req.header("Authorization") != auth) - return res.status(403).send(JSON.stringify({ error: true, message: "[BLWEBHOOKS] You don't have access to this endpoint - VoidBots" })); - - // Use the data on whatever you want - console.log(req.body); - // VotingModel.findOneAndUpdate({ userID : req.vote.user }, {$inc : {'totalVotes' : 1}}); - const userID = req.body.user; - const botID = req.body.bot; - const List = "VoidBots"; - this.client.emit("VB-voted", userID, botID); - this.client.emit("vote", userID, botID, List); - setTimeout(() => this.client.emit("voteExpired", userID, botID, List), 1000 * 60 * 60 * 24); - - // Respond to VoidBots API - res.status(200).send(JSON.stringify({ error: false, message: "[BLWEBHOOKS] Received the request!" })); - }); + const TopGG = require("@top-gg/sdk"); + const WH = new TopGG.Webhook(auth); + app.post(`/${url}`, WH.middleware(), async (req, res) => { + // Respond to invalid requests + res.setHeader("X-Powered-By", "BLWebhooks.js/Express"); + if (req.header("Authorization") != auth) + console.log("Failed Access - Top.gg Endpoint"); + console.log(req.vote); + const userID = req.vote.user; + const botID = req.vote.bot; + const type = req.vote.type; + const List = "top.gg"; + this.client.emit("topgg-voted", userID, botID, type); + this.client.emit("vote", userID, botID, List); + setTimeout( + () => this.client.emit("voteExpired", userID, botID, List), + 1000 * 60 * 60 * 24 + ); + + res + .status(200) + .send( + JSON.stringify({ + error: false, + message: "[BLWEBHOOKS] Received The Request!", + }) + ); + }); + } + + async IBLVoteHook(url, auth, toggle) { + if (toggle == false) { + return console.log( + chalk.red("[BLWEBHOOKS] InfinityBotList vote hooks have been disabled.") + ); + } else if (toggle == true) { + console.log( + chalk.green( + "[BLWEBHOOKS] InfinityBotList vote hooks have been enabled." + ) + ); } - async DiscordLabsVoteHook(url, auth, toggle) { - if (toggle == false) { - return console.log(chalk.red("[BLWEBHOOKS] DiscordLabs vote hooks have been disabled.")); - } - else if (toggle == true) { - console.log(chalk.green("[BLWEBHOOKS] DiscordLabs Vote Hooks Enabled")); - } - app.post(`/${url}`, async (req, res) => { - // Respond to invalid requests - res.setHeader("X-Powered-By", "BLWebhooks.js/Express"); - if (req.header("Authorization") != auth) - console.log("Failed Access - DiscordLabs Endpoint"); - if (req.header("Authorization") != auth) - return res.status(403).send(JSON.stringify({ error: true, message: "[BLWEBHOOKS] You don't have access to use this endpoint - DiscordLabs" })); - - // Use the data on whatever you want - console.log(req.body); - // VotingModel.findOneAndUpdate({ userID : req.vote.user }, {$inc : {'totalVotes' : 1}}); - const userID = req.body.uid; - const botID = req.body.bid; - const wasTest = req.body.test; - const List = "DiscordLabs"; - this.client.emit("DL-voted", userID, botID, wasTest); - this.client.emit("vote", userID, botID, List); - setTimeout(() => this.client.emit("voteExpired", userID, botID, List), 1000 * 60 * 60 * 24); - - // Respond to DiscordLabs API - res.status(200).send(JSON.stringify({ error: false, message: "[BLWEBHOOKS] Received the request!" })); - }); + app.post(`/${url}`, async (req, res) => { + // Respond to invalid requests + res.setHeader("X-Powered-By", "BLWebhooks.js/Express"); + if (req.header("Authorization") != auth) + console.log("Failed Access - InfinityBotList Endpoint"); + if (req.header("Authorization") != auth) + return res + .status(403) + .send( + JSON.stringify({ + error: true, + message: + "[BLWEBHOOKS] You don't have access to use this endpoint. - InfinityBotList", + }) + ); + + // Use the data on whatever you want + console.log(req.body); + // VotingModel.findOneAndUpdate({ userID : req.vote.user }, {$inc : {'totalVotes' : 1}}); + const userID = req.body.userID; + const botID = req.body.botID; + const type = req.body.type; + const List = "InfinityBotList"; + this.client.emit("IBL-voted", userID, botID, type); + this.client.emit("vote", userID, botID, List); + setTimeout( + () => this.client.emit("voteExpired", userID, botID, List), + 1000 * 60 * 60 * 24 + ); + + // Respond to IBL API + res + .status(200) + .send( + JSON.stringify({ + error: false, + message: "[BLWEBHOOKS] Received the request!", + }) + ); + }); + } + + async VoidBotsVoteHook(url, auth, toggle) { + if (toggle == false) { + return console.log( + chalk.red("[BLWEBHOOKS] Void Bots vote hooks have been disabled.") + ); + } else if (toggle == true) { + console.log( + chalk.green("[BLWEBHOOKS] Void Bots vote hooks have been enabled.") + ); } - async BotrixVoteHook(url, auth, toggle) { - if (toggle == false) { - return console.log(chalk.red("[BLWEBHOOKS] Botrix vote hooks have been disabled.")); - } - else if (toggle == true) { - console.log(chalk.green("[BLWEBHOOKS] Botrix vote hooks have been enabled.")); - } - app.post(`/${url}`, async (req, res) => { - // Respond to invalid requests - res.setHeader("X-Powered-By", "BLWebhooks.js/Express"); - if (req.header("Authorization") != auth) - console.log("Failed Access - Botrix Endpoint"); - if (req.header("Authorization") != auth) - return res.status(403).send(JSON.stringify({ error: true, message: "[BLWEBHOOKS] You don't have access to use this endpoint. - Botrix" })); - - // Use the data on whatever you want - console.log(req.body); - // VotingModel.findOneAndUpdate({ userID : req.vote.user }, {$inc : {'totalVotes' : 1}}); - const userID = req.body.user; - const botID = null; - const List = "Botrix"; - this.client.emit("BTR-voted", userID); - this.client.emit("vote", userID, botID, List); - setTimeout(() => this.client.emit("voteExpired", userID, botID, List), 1000 * 60 * 60 * 24); - - // Respond to Botrix API - res.status(200).send(JSON.stringify({ error: false, message: "[BLWEBHOOKS] Received the request!" })); - }); + app.post(`/${url}`, async (req, res) => { + // Respond to invalid requests + res.setHeader("X-Powered-By", "BLWebhooks.js/Express"); + if (req.header("Authorization") != auth) + console.log("Failed Access - VoidBots Endpoint"); + if (req.header("Authorization") != auth) + return res + .status(403) + .send( + JSON.stringify({ + error: true, + message: + "[BLWEBHOOKS] You don't have access to this endpoint - VoidBots", + }) + ); + + // Use the data on whatever you want + console.log(req.body); + // VotingModel.findOneAndUpdate({ userID : req.vote.user }, {$inc : {'totalVotes' : 1}}); + const userID = req.body.user; + const botID = req.body.bot; + const List = "VoidBots"; + this.client.emit("VB-voted", userID, botID); + this.client.emit("vote", userID, botID, List); + setTimeout( + () => this.client.emit("voteExpired", userID, botID, List), + 1000 * 60 * 60 * 24 + ); + + // Respond to VoidBots API + res + .status(200) + .send( + JSON.stringify({ + error: false, + message: "[BLWEBHOOKS] Received the request!", + }) + ); + }); + } + + async DiscordLabsVoteHook(url, auth, toggle) { + if (toggle == false) { + return console.log( + chalk.red("[BLWEBHOOKS] DiscordLabs vote hooks have been disabled.") + ); + } else if (toggle == true) { + console.log(chalk.green("[BLWEBHOOKS] DiscordLabs Vote Hooks Enabled")); } - async BListVoteHook(url, auth, toggle) { - if (toggle == false) { - return console.log(chalk.red("[BLWEBHOOKS] BList vote hooks have been disabled.")); - } - else if (toggle == true) { - console.log(chalk.green("[BLWEBHOOKS] BList hote hooks have been enabled.")); - } - app.post(`/${url}`, async (req, res) => { - // Respond to invalid requests - res.setHeader("X-Powered-By", "BLWebhooks.js/Express"); - if (req.header("Authorization") != auth) - console.log("Failed Access - BList Endpoint"); - if (req.header("Authorization") != auth) - return res.status(403).send(JSON.stringify({ error: true, message: "[BLWEBHOOKS] You don't have access to use this endpoint - BList" })); - - // Use the data on whatever you want - console.log(req.body); - // VotingModel.findOneAndUpdate({ userID : req.vote.user }, {$inc : {'totalVotes' : 1}}); - const userID = req.body.user; - const botID = null; - const List = "BList"; - this.client.emit("BLT-voted", userID); - this.client.emit("vote", userID, botID, List); - setTimeout(() => this.client.emit("voteExpired", userID, botID, List), 1000 * 60 * 60 * 24); - - // Respond to BList API - res.status(200).send(JSON.stringify({ error: false, message: "[BLWEBHOOKS] Received the request!" })); - }); + app.post(`/${url}`, async (req, res) => { + // Respond to invalid requests + res.setHeader("X-Powered-By", "BLWebhooks.js/Express"); + if (req.header("Authorization") != auth) + console.log("Failed Access - DiscordLabs Endpoint"); + if (req.header("Authorization") != auth) + return res + .status(403) + .send( + JSON.stringify({ + error: true, + message: + "[BLWEBHOOKS] You don't have access to use this endpoint - DiscordLabs", + }) + ); + + // Use the data on whatever you want + console.log(req.body); + // VotingModel.findOneAndUpdate({ userID : req.vote.user }, {$inc : {'totalVotes' : 1}}); + const userID = req.body.uid; + const botID = req.body.bid; + const wasTest = req.body.test; + const List = "DiscordLabs"; + this.client.emit("DL-voted", userID, botID, wasTest); + this.client.emit("vote", userID, botID, List); + setTimeout( + () => this.client.emit("voteExpired", userID, botID, List), + 1000 * 60 * 60 * 24 + ); + + // Respond to DiscordLabs API + res + .status(200) + .send( + JSON.stringify({ + error: false, + message: "[BLWEBHOOKS] Received the request!", + }) + ); + }); + } + + async BotrixVoteHook(url, auth, toggle) { + if (toggle == false) { + return console.log( + chalk.red("[BLWEBHOOKS] Botrix vote hooks have been disabled.") + ); + } else if (toggle == true) { + console.log( + chalk.green("[BLWEBHOOKS] Botrix vote hooks have been enabled.") + ); } - async MYBVoteHook(url, auth, toggle) { - if (toggle == false) { - return console.log(chalk.red("[BLWEBHOOKS] BList vote hooks have been disabled.")); - } - else if (toggle == true) { - console.log(chalk.green("[BLWEBHOOKS] BList hote hooks have been enabled.")); - } - app.post(`/${url}`, async (req, res) => { - // Respond to invalid requests - res.setHeader("X-Powered-By", "BLWebhooks.js/Express"); - if (req.header("Authorization") != auth) - console.log("Failed Access - Mythicalbots Endpoint"); - if (req.header("Authorization") != auth) - return res.status(403).send(JSON.stringify({ error: true, message: "[BLWEBHOOKS] You don't have access to use this endpoint - Mythicalbots" })); - - // Use the data on whatever you want - console.log(req.body); - // VotingModel.findOneAndUpdate({ userID : req.vote.user }, {$inc : {'totalVotes' : 1}}); - const userID = req.body.user; - const botID = null; - const List = "MythicalBots"; - this.client.emit("MYB-voted", userID); - this.client.emit("vote", userID, botID, List); - setTimeout(() => this.client.emit("voteExpired", userID, botID, List), 1000 * 60 * 60 * 24); - - // Respond to Mythicalbots API - res.status(200).send(JSON.stringify({ error: false, message: "[BLWEBHOOKS] Received the request!" })); - }); + app.post(`/${url}`, async (req, res) => { + // Respond to invalid requests + res.setHeader("X-Powered-By", "BLWebhooks.js/Express"); + if (req.header("Authorization") != auth) + console.log("Failed Access - Botrix Endpoint"); + if (req.header("Authorization") != auth) + return res + .status(403) + .send( + JSON.stringify({ + error: true, + message: + "[BLWEBHOOKS] You don't have access to use this endpoint. - Botrix", + }) + ); + + // Use the data on whatever you want + console.log(req.body); + // VotingModel.findOneAndUpdate({ userID : req.vote.user }, {$inc : {'totalVotes' : 1}}); + const userID = req.body.user; + const botID = null; + const List = "Botrix"; + this.client.emit("BTR-voted", userID); + this.client.emit("vote", userID, botID, List); + setTimeout( + () => this.client.emit("voteExpired", userID, botID, List), + 1000 * 60 * 60 * 24 + ); + + // Respond to Botrix API + res + .status(200) + .send( + JSON.stringify({ + error: false, + message: "[BLWEBHOOKS] Received the request!", + }) + ); + }); + } + + async BListVoteHook(url, auth, toggle) { + if (toggle == false) { + return console.log( + chalk.red("[BLWEBHOOKS] BList vote hooks have been disabled.") + ); + } else if (toggle == true) { + console.log( + chalk.green("[BLWEBHOOKS] BList hote hooks have been enabled.") + ); } - async DBCVoteHook(url, auth, toggle) { - if (toggle == false) { - return console.log(chalk.red("[BLWEBHOOKS] DiscordBots.co vote hooks have been disabled.")); - } - else if (toggle == true) { - console.log(chalk.green("[BLWEBHOOKS] DiscordBots.co vote hooks have been enabled.")); - } - app.post(`/${url}`, async (req, res) => { - // Respond to invalid requests - res.setHeader("X-Powered-By", "BLWebhooks.js/Express"); - if (req.header("Authorization") != auth) - console.log("Failed Access - DiscordBots.co Endpoint"); - if (req.header("Authorization") != auth) - return res.status(403).send(JSON.stringify({ error: true, message: "[BLWEBHOOKS] You don't have access to use this endpoint - DiscordBots.co" })); - - // Use the data on whatever you want - console.log(req.body); - // VotingModel.findOneAndUpdate({ userID : req.vote.user }, {$inc : {'totalVotes' : 1}}); - const userID = req.body.userId; - const botID = null; - const List = "DiscordBots.co"; - this.client.emit("DBC-voted", userID); - this.client.emit("vote", userID, botID, List); - setTimeout(() => this.client.emit("voteExpired", userID, botID, List), 1000 * 60 * 60 * 24); - - // Respond to BList API - res.status(200).send(JSON.stringify({ error: false, message: "[BLWEBHOOKS] Received the request!" })); - }); + app.post(`/${url}`, async (req, res) => { + // Respond to invalid requests + res.setHeader("X-Powered-By", "BLWebhooks.js/Express"); + if (req.header("Authorization") != auth) + console.log("Failed Access - BList Endpoint"); + if (req.header("Authorization") != auth) + return res + .status(403) + .send( + JSON.stringify({ + error: true, + message: + "[BLWEBHOOKS] You don't have access to use this endpoint - BList", + }) + ); + + // Use the data on whatever you want + console.log(req.body); + // VotingModel.findOneAndUpdate({ userID : req.vote.user }, {$inc : {'totalVotes' : 1}}); + const userID = req.body.user; + const botID = null; + const List = "BList"; + this.client.emit("BLT-voted", userID); + this.client.emit("vote", userID, botID, List); + setTimeout( + () => this.client.emit("voteExpired", userID, botID, List), + 1000 * 60 * 60 * 24 + ); + + // Respond to BList API + res + .status(200) + .send( + JSON.stringify({ + error: false, + message: "[BLWEBHOOKS] Received the request!", + }) + ); + }); + } + + async MYBVoteHook(url, auth, toggle) { + if (toggle == false) { + return console.log( + chalk.red("[BLWEBHOOKS] BList vote hooks have been disabled.") + ); + } else if (toggle == true) { + console.log( + chalk.green("[BLWEBHOOKS] BList hote hooks have been enabled.") + ); } + app.post(`/${url}`, async (req, res) => { + // Respond to invalid requests + res.setHeader("X-Powered-By", "BLWebhooks.js/Express"); + if (req.header("Authorization") != auth) + console.log("Failed Access - Mythicalbots Endpoint"); + if (req.header("Authorization") != auth) + return res + .status(403) + .send( + JSON.stringify({ + error: true, + message: + "[BLWEBHOOKS] You don't have access to use this endpoint - Mythicalbots", + }) + ); + + // Use the data on whatever you want + console.log(req.body); + // VotingModel.findOneAndUpdate({ userID : req.vote.user }, {$inc : {'totalVotes' : 1}}); + const userID = req.body.user; + const botID = null; + const List = "MythicalBots"; + this.client.emit("MYB-voted", userID); + this.client.emit("vote", userID, botID, List); + setTimeout( + () => this.client.emit("voteExpired", userID, botID, List), + 1000 * 60 * 60 * 24 + ); + + // Respond to Mythicalbots API + res + .status(200) + .send( + JSON.stringify({ + error: false, + message: "[BLWEBHOOKS] Received the request!", + }) + ); + }); + } - async getVotes(userID, option) { - if(!option) return console.log("Please provide option - daily, weekly, monthly"); - if(option == "total") { - if(!userID) return console.log("Please provide userID"); - } else if(option == "daily") { - if(!userID) return console.log("Please provide userID"); - } else if(option == "weekly") { - if(!userID) return console.log("Please provide userID"); - } + async DBCVoteHook(url, auth, toggle) { + if (toggle == false) { + return console.log( + chalk.red("[BLWEBHOOKS] DiscordBots.co vote hooks have been disabled.") + ); + } else if (toggle == true) { + console.log( + chalk.green("[BLWEBHOOKS] DiscordBots.co vote hooks have been enabled.") + ); } + app.post(`/${url}`, async (req, res) => { + // Respond to invalid requests + res.setHeader("X-Powered-By", "BLWebhooks.js/Express"); + if (req.header("Authorization") != auth) + console.log("Failed Access - DiscordBots.co Endpoint"); + if (req.header("Authorization") != auth) + return res + .status(403) + .send( + JSON.stringify({ + error: true, + message: + "[BLWEBHOOKS] You don't have access to use this endpoint - DiscordBots.co", + }) + ); + // Use the data on whatever you want + console.log(req.body); + // VotingModel.findOneAndUpdate({ userID : req.vote.user }, {$inc : {'totalVotes' : 1}}); + const userID = req.body.userId; + const botID = null; + const List = "DiscordBots.co"; + this.client.emit("DBC-voted", userID); + this.client.emit("vote", userID, botID, List); + setTimeout( + () => this.client.emit("voteExpired", userID, botID, List), + 1000 * 60 * 60 * 24 + ); + + // Respond to BList API + res + .status(200) + .send( + JSON.stringify({ + error: false, + message: "[BLWEBHOOKS] Received the request!", + }) + ); + }); + } + + async getVotes(userID, option) { + if (!option) + return console.log("Please provide option - daily, weekly, monthly"); + if (option == "total") { + if (!userID) return console.log("Please provide userID"); + } else if (option == "daily") { + if (!userID) return console.log("Please provide userID"); + } else if (option == "weekly") { + if (!userID) return console.log("Please provide userID"); + } + } } module.exports.WebhooksManager = WebhooksManager; - diff --git a/src/Constants.js b/src/Constants.js index e69de29..8a7a28a 100644 --- a/src/Constants.js +++ b/src/Constants.js @@ -0,0 +1,9 @@ +exports.defaultManager = { + database: "mongoose", // mongoose or sqlite + extraLogging: true, + extra: { + extraProtection: true, + proxyTrust: false, + shardedClient: false, + }, +}; diff --git a/typings/index.d.ts b/typings/index.d.ts new file mode 100644 index 0000000..e69de29