diff --git a/.gitignore b/.gitignore index a4fb9af..7651ea5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -config.json +.env node_modules/ \ No newline at end of file diff --git a/README.md b/README.md index e8c29f8..f96ee06 100644 --- a/README.md +++ b/README.md @@ -1,28 +1,16 @@ -# 1PG -1PG Course - https://udemy.com/course/create-the-best-discord-bot/?referralCode=5CB95A4D9309B1F54560 +# 1PG - Heroku +This is the Heroku branch that uses a `.env` file instead of a `config.json`. -Create a Discord Bot Dashboard Series - https://www.youtube.com/watch?v=tpIQM90o_pY&list=PLGfT2ttRbfizUIO1YEITWaquqBsNqHv7v&index=1 +[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/theADAMJR/1PG/tree/heroku) -## Setup +You could also use this branch to deploy, if you prefer `.env` to `config.json`, however it is only used for the video. -Make a file `config.json`: -```json -{ - "bot": { - "id": "", - "secret": "", - "token": "" - }, - "dashboardURL": "http://localhost:3000", - "mongoURI": "mongodb://localhost/1PG-Demo" -} +## `.env` +```js +BOT_ID="" +BOT_SECRET="" +BOT_TOKEN="" +DASHBOARD_URL="http://localhost:3000" +MONGO_URI="mongodb://localhost/1PG-Demo" +PORT=3000 ``` - -### Make sure `config.json` is in `.gitignore`. -This will help secure your bot token, and make sure your bot does not get hacked. - -## Set Redirect URIs -+ http://localhost:3000/auth -+ http://localhost:3000/auth-guild - -In the **[Developer Portal](https://discord.com/developers)** -> **Your Application** -> **OAuth2** diff --git a/app.json b/app.json new file mode 100644 index 0000000..5cd5ddc --- /dev/null +++ b/app.json @@ -0,0 +1,41 @@ +{ + "name": "6PG - Discord Bot Maker", + "description": "Host a bot without code, with one simple step.", + "keywords": [ + "bot maker", + "discord bot maker", + "6pg" + ], + "repository": "https://github.com/theADAMJR/6PG", + "env": { + "BOT_ID": { + "description": "Client ID from https://discord.com/developers.", + "value": "" + }, + "BOT_SECRET": { + "description": "Client Secret from https://discord.com/developers.", + "value": "" + }, + "BOT_TOKEN": { + "description": "Bot Token from https://discord.com/developers.", + "value": "" + }, + "DASHBOARD_URL": { + "description": "The Website URL [https://.herokuapp.com]", + "value": "https://.herokuapp.com" + }, + "MONGO_URI": { + "description": "The MongoDB URI to your database [i.e. from MongoDB Atlas].", + "value": "mongodb+srv://:@/6PG?retryWrites=true&w=majority" + }, + "PORT": { + "description": "Port for Heroku to use (default: 3000).", + "value": "3000" + } + }, + "buildpacks": [ + { + "url": "heroku/nodejs" + } + ] +} \ No newline at end of file diff --git a/bot.js b/bot.js index 1ccef4c..23cd4b9 100644 --- a/bot.js +++ b/bot.js @@ -1,12 +1,14 @@ +const { config } = require('dotenv'); +config(); + const { Client } = require('discord.js'); const mongoose = require('mongoose'); -const config = require('./config.json'); const bot = new Client(); -bot.login(config.bot.token); +bot.login(process.env.BOT_TOKEN); -mongoose.connect(config.mongoURI, +mongoose.connect(process.env.MONGO_URI, { useNewUrlParser: true, useUnifiedTopology: true }, (error) => error ? console.log('Failed to connect to database') diff --git a/dashboard/modules/auth-client.js b/dashboard/modules/auth-client.js index f90273b..59568fd 100644 --- a/dashboard/modules/auth-client.js +++ b/dashboard/modules/auth-client.js @@ -1,8 +1,7 @@ const OAuthClient = require('disco-oauth'); -const config = require('../../config.json'); -const client = new OAuthClient(config.bot.id, config.bot.secret); -client.setRedirect(`${config.dashboardURL}/auth`); +const client = new OAuthClient(process.env.BOT_ID, process.env.BOT_SECRET); +client.setRedirect(`${process.env.DASHBOARD_URL}/auth`); client.setScopes('identify', 'guilds'); module.exports = client; \ No newline at end of file diff --git a/dashboard/modules/rate-limiter.js b/dashboard/modules/rate-limiter.js index 8b1bf05..a7fa871 100644 --- a/dashboard/modules/rate-limiter.js +++ b/dashboard/modules/rate-limiter.js @@ -1,10 +1,9 @@ const rateLimit = require('express-rate-limit'); const RateLimitStore = require('rate-limit-mongo'); -const config = require('../../config.json'); module.exports = rateLimit({ max: 300, message: 'You are being rate limited.', - store: new RateLimitStore({ uri: config.mongoURI }), + store: new RateLimitStore({ uri: process.env.MONGO_URI }), windowMs: 60 * 1000 }); diff --git a/dashboard/routes/auth-routes.js b/dashboard/routes/auth-routes.js index a797b18..39c346c 100644 --- a/dashboard/routes/auth-routes.js +++ b/dashboard/routes/auth-routes.js @@ -1,4 +1,3 @@ -const config = require('../../config.json'); const express = require('express'); const authClient = require('../modules/auth-client'); const sessions = require('../modules/sessions'); @@ -6,10 +5,10 @@ const sessions = require('../modules/sessions'); const router = express.Router(); router.get('/invite', (req, res) => - res.redirect(`https://discord.com/api/oauth2/authorize?client_id=${config.bot.id}&redirect_uri=${config.dashboardURL}/auth-guild&response_type=code&scope=bot`)); + res.redirect(`https://discord.com/api/oauth2/authorize?client_id=${process.env.BOT_ID}&redirect_uri=${process.env.DASHBOARD_URL}/auth-guild&response_type=code&scope=bot`)); router.get('/login', (req, res) => - res.redirect(`https://discord.com/api/oauth2/authorize?client_id=${config.bot.id}&redirect_uri=${config.dashboardURL}/auth&response_type=code&scope=identify guilds&prompt=none`)); + res.redirect(`https://discord.com/api/oauth2/authorize?client_id=${process.env.BOT_ID}&redirect_uri=${process.env.DASHBOARD_URL}/auth&response_type=code&scope=identify guilds&prompt=none`)); router.get('/auth-guild', async (req, res) => { try { diff --git a/dashboard/views/dashboard/index.pug b/dashboard/views/dashboard/index.pug index 1dafc3c..5eabdb0 100644 --- a/dashboard/views/dashboard/index.pug +++ b/dashboard/views/dashboard/index.pug @@ -26,4 +26,4 @@ html(lang='en') .container.jumbotron.text-center.bg-transparent h1.display-3 Dashboard hr - p.lead Manage your servers with the 1PG dashboard. \ No newline at end of file + p.lead Manage your servers with the SignBot dashboard. diff --git a/package-lock.json b/package-lock.json index 657ac4a..76cb708 100644 --- a/package-lock.json +++ b/package-lock.json @@ -90,9 +90,9 @@ } }, "bl": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/bl/-/bl-2.2.0.tgz", - "integrity": "sha512-wbgvOpqopSr7uq6fJrLH8EsvYMJf9gzfo2jCsL2eTy75qXPukA4pCgHamOQkZtY5vmfVtjB+P3LNlMHW5CEZXA==", + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/bl/-/bl-2.2.1.tgz", + "integrity": "sha512-6Pesp1w0DEX1N550i/uGV/TqucVL4AM/pgThFSN/Qq9si1/DF9aIHs1BxD8V/QU0HoeHO6cQRTAuYnLPKq1e4g==", "requires": { "readable-stream": "^2.3.5", "safe-buffer": "^5.1.1" @@ -295,6 +295,11 @@ "resolved": "https://registry.npmjs.org/doctypes/-/doctypes-1.1.0.tgz", "integrity": "sha1-6oCxBqh1OHdOijpKWv4pPeSJ4Kk=" }, + "dotenv": { + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.2.0.tgz", + "integrity": "sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw==" + }, "ecdsa-sig-formatter": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz", @@ -722,9 +727,9 @@ "integrity": "sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw==" }, "node-fetch": { - "version": "2.6.0", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz", - "integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==" + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", + "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==" }, "object-assign": { "version": "4.1.1", diff --git a/package.json b/package.json index ae5edff..007c7c9 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,9 @@ "version": "1.0.0", "description": "", "main": "bot.js", + "engines": { + "node": "14.x" + }, "scripts": { "start": "node bot.js", "test": "echo \"Error: no test specified\" && exit 1" @@ -15,6 +18,7 @@ "cookies": "^0.8.0", "disco-oauth": "^4.2.7", "discord.js": "^12.2.0", + "dotenv": "^8.2.0", "express": "^4.17.1", "express-rate-limit": "^5.1.3", "method-override": "^3.0.0",