Skip to content
This repository has been archived by the owner on May 7, 2024. It is now read-only.

Patch 1 #9

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
config.json
.env

node_modules/
36 changes: 12 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -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": "<bot_id>",
"secret": "<client_secret>",
"token": "<bot_token>"
},
"dashboardURL": "http://localhost:3000",
"mongoURI": "mongodb://localhost/1PG-Demo"
}
## `.env`
```js
BOT_ID="<bot_id>"
BOT_SECRET="<bot_secret>"
BOT_TOKEN="<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**
41 changes: 41 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -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://<heroku_app_name>.herokuapp.com]",
"value": "https://<heroku_app_name>.herokuapp.com"
},
"MONGO_URI": {
"description": "The MongoDB URI to your database [i.e. from MongoDB Atlas].",
"value": "mongodb+srv://<username>:<password>@<hostname>/6PG?retryWrites=true&w=majority"
},
"PORT": {
"description": "Port for Heroku to use (default: 3000).",
"value": "3000"
}
},
"buildpacks": [
{
"url": "heroku/nodejs"
}
]
}
8 changes: 5 additions & 3 deletions bot.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
5 changes: 2 additions & 3 deletions dashboard/modules/auth-client.js
Original file line number Diff line number Diff line change
@@ -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;
3 changes: 1 addition & 2 deletions dashboard/modules/rate-limiter.js
Original file line number Diff line number Diff line change
@@ -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
});
5 changes: 2 additions & 3 deletions dashboard/routes/auth-routes.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
const config = require('../../config.json');
const express = require('express');
const authClient = require('../modules/auth-client');
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 {
Expand Down
2 changes: 1 addition & 1 deletion dashboard/views/dashboard/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -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.
p.lead Manage your servers with the SignBot dashboard.
17 changes: 11 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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",
Expand Down