Skip to content

Commit

Permalink
Merge branch 'beta' of https://github.com/CoreX-Developement/CoreX in…
Browse files Browse the repository at this point in the history
…to beta
  • Loading branch information
Tagliatellelol committed Jul 16, 2021
2 parents 95d15e7 + 8b62a9d commit a7ffc93
Show file tree
Hide file tree
Showing 17 changed files with 511 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CLIENT_ID=
CLIENT_SECRET=
PORT=3000
CALLBACK_URL=/login
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
json.sqlite
config.json
config.json
.env
5 changes: 5 additions & 0 deletions dashboard/backend/CheckAuth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = async (req, res, next) => {
if (req.isAuthenticated()) return next();
req.session.backURL = req.url;
res.redirect("/login");
}
11 changes: 11 additions & 0 deletions dashboard/public/css/custom.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
body {
background-color: #23272A;
}

h1, h2, h3, h4, h5, h6 {
font-family: "Montserrat" !important;
}

p, div {
font-family: "Karla" !important;
}
Binary file added dashboard/public/static/CoreX.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
75 changes: 75 additions & 0 deletions dashboard/routes/dashboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
const express = require('express');
const router = express.Router();
const moment = require("moment");
require("moment-duration-format");
const checkAuth = require('../backend/CheckAuth');
const db = require("quick.db")


router.get("/profile", checkAuth, async (req, res) => {

let userObj = req.client.users.cache.get(req.user.id);

let userSubscription = {
undefined: "None",
0: "None",
1: "Nitro Classic",
2: "Nitro Premium"
};

let status = {
"online": "#43b581",
"idle": "#faa61a",
"dnd": "#f04747",
"offline": "#747f8d"
};

let statusName = {
"online": "Online",
"idle": "Idle",
"dnd": "Do Not Disturb",
"offline": "Offline"
};

const flags = {
DISCORD_EMPLOYEE: 'Discord Employee ⚒',
DISCORD_PARTNER: 'Discord Partner ♾',
PARTNERED_SERVER_OWNER: 'Partnered Server Owner ♾',
BUGHUNTER_LEVEL_1: 'Bug Hunter (Level 1) 🐞',
BUGHUNTER_LEVEL_2: 'Bug Hunter (Level 2) 🐛',
HYPESQUAD_EVENTS: 'HypeSquad Events',
HOUSE_BRAVERY: 'House of Bravery',
HOUSE_BRILLIANCE: 'House of Brilliance',
HOUSE_BALANCE: 'House of Balance',
EARLY_SUPPORTER: 'Early Supporter',
TEAM_USER: 'Team User',
SYSTEM: 'System',
VERIFIED_BOT: 'Verified Bot',
EARLY_VERIFIED_BOT_DEVELOPER: 'Early Verified Bot Developer',
EARLY_VERIFIED_DEVELOPER: 'Early Verified Developer',
VERIFIED_DEVELOPER: 'Verified Bot Developer'
};

let userFlags;

try {
userFlags = userObj.flags.toArray();
} catch (e) {
userFlags = [];
}

res.render("dashboard/profile", {
tag: (req.user ? req.user.tag : "Login"),
bot: req.client,
userObj: userObj,
userFlags: userFlags.length ? userFlags.map(flag => flags[flag]).join(', ') : 'None',
status: status[userObj.presence.status],
statusName: statusName[userObj.presence.status],
moment: moment,
userSubscription: userSubscription[req.user.premium_type],
user: req.user || null,
message: db.fetch(`${req.user.id}_messages`) || '0'
});
});

module.exports = router;
59 changes: 59 additions & 0 deletions dashboard/routes/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const express = require("express");
const router = express.Router();
const { version } = require("discord.js");
const moment = require("moment");
require("moment-duration-format");
const passport = require("passport");
const db = require(`quick.db`)

let userSubscription = {
undefined: "None",
0: "None",
1: "Nitro Classic",
2: "Nitro Premium"
};

router.get("/", async(req, res) => {
res.render("index", {
tag: (req.user ? req.user.tag : "Login"),
bot: req.client,
user: req.user || null,
});
});

router.get("/stats", async(req, res) => {
res.render("stats", {
tag: (req.user ? req.user.tag : "Login"),
bot: req.client,
user: req.user || null,
uptime: moment.duration(req.client.uptime).format(" D [days], H [hours], m [minutes], s [seconds]"),
version: version,
messages: db.fetch(`messsges_all`)
});
});

router.get("/login", passport.authenticate("discord", { failureRedirect: "/" }), async function(req, res) {
if (!req.user.id || !req.user.guilds) {
res.redirect("/");
} else res.redirect("/");
});

router.get("/logout", async function(req, res) {
req.session.destroy(() => {
req.logout();
res.redirect("/");
});
});
router.get("/users/:userid", async(req, res) => {
const user2 = req.client.users.cache.get(req.params.userid)
res.render("users", {
user1: req.client.users.cache.get(req.params.userid),
tag: (req.user ? req.user.tag : "Login"),
bot: req.client,
user: req.user || null,
moment: moment,
message: db.fetch(`${user2.id}_messages`) || '0'
});
});

module.exports = router;
55 changes: 55 additions & 0 deletions dashboard/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const express = require("express");
const app = express();
const bodyparser = require("body-parser");
const session = require("express-session");
const path = require("path");
const ejs = require("ejs");
const passport = require("passport");
const { Strategy } = require("passport-discord");

module.exports.load = async (client) => {

app.use(bodyparser.json());
app.use(bodyparser.urlencoded({ extended: true }));
app.engine("html", ejs.renderFile);
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, "/views"));
app.use(express.static(path.join(__dirname, "/public")));
app.use(session({
secret: "BotDashboardExample101",
resave: false,
saveUninitialized: false
}));

app.use(async function(req, res, next) {
req.client = client;
next();
});

app.use(passport.initialize());
app.use(passport.session());

passport.serializeUser((user, done) => {
done(null, user);
});
passport.deserializeUser((obj, done) => {
done(null, obj);
});
passport.use(new Strategy({
clientID: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
callbackURL: process.env.CALLBACK_URL,
scope: [ "identify", "guilds" ],
}, function (accessToken, refreshToken, profile, done) {
process.nextTick(function() {
return done(null, profile);
});
}))

app.use("/", require("./routes/index"));
app.use("/dashboard", require("./routes/dashboard"));

app.listen(process.env.PORT, (err) => {
console.log(`Webserver now online on port ${process.env.PORT}`);
});
}
70 changes: 70 additions & 0 deletions dashboard/views/dashboard/profile.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<%- include("../partials/header") %>

<title>Your Profile » <%= bot.user.username %> Dashboard</title>

<style>
.statusColor {
color: <%= status %>;
}
</style> <!-- Please ignore the Syntax Error here. If there is a fix for this, please send a PR. -->

<div class="text-center text-light" style="padding-top: 65px; padding-bottom: 20px;">
<div class="p-5 text-center" style="padding-top: 110px; background-color: #3B465E;">
<img class="img-fluid rounded-circle" src="https://cdn.discordapp.com/avatars/<%= user.id %>/<%= user.avatar %>" width="128px" height="auto">
<br>
<br>
<h1 class="mb-3"><%= user.username %>#<%= user.discriminator %> <i class="fas fa-circle statusColor fa-xs"></i></h1>
</div>
</div>

<div class="container">
<table class="table text-light">
<thead class="thead text-center text-light mdb-color lighten-1 lighten-1">
<tr>
<th style="font-size: 20px;" scope="col">Type</th>
<th style="font-size: 20px;" scope="col">Data</th>
</tr>
</thead>
<tbody>
<tr class="text-center">
<td style="font-size: 20px;"><i class="fas fa-users"></i> ID</td>
<td style="font-size: 20px;"><%= user.id %></td>
</tr>
<tr class="text-center">
<td style="font-size: 20px;"><i class="fas fa-hashtag"></i> Discriminator</td>
<td style="font-size: 20px;">#<%= user.discriminator %></td>
</tr>
<tr class="text-center">
<td style="font-size: 20px;"><i class="fas fa-flag"></i> Flags</td>
<td style="font-size: 20px;"><%= userFlags %></td>
</tr>
<tr class="text-center">
<td style="font-size: 20px;"><i class="fas fa-calendar"></i> Created</td>
<td style="font-size: 20px;"><%= moment(userObj.createdAt).format("LLLL") %></td>
</tr>
<tr class="text-center">
<td style="font-size: 20px;"><i class="fab fa-discord"></i> Status</td>
<td style="font-size: 20px;"><i class="fas fa-circle statusColor fa-xs"></i> <%= statusName %></td>
</tr>
<tr class="text-center">
<td style="font-size: 20px;"><i class="fas fa-gamepad"></i> Game</td>
<td style="font-size: 20px;"><%= userObj.presence.game ? userObj.presence.game.name : 'Not Playing/Streaming' %></td>
</tr>
<tr class="text-center">
<td style="font-size: 20px;"><i class="fab fa-discord"></i> Subscription</td>
<td style="font-size: 20px;"><%= userSubscription %></td>
</tr>
<tr class="text-center">
<td style="font-size: 20px;"><i class="fas fa-shield-alt"></i> MFA</td>
<td style="font-size: 20px;"><%= user.mfa_enabled ? "Yes" : "No" %></td>
</tr>
<tr class="text-center">
<td style="font-size: 20px;"><i class="fas fa-comment-alt"></i> Messages Count</td>
<td style="font-size: 20px;"><%= message %></td>
</tr>
</tbody>
</table>
</div>


<%- include("../partials/footer") %>
26 changes: 26 additions & 0 deletions dashboard/views/index.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<%- include("partials/header") %>

<title>Home » <%= bot.user.username %> Dashboard</title>

<div class="container text-center text-light" style="padding-top: 110px; padding-bottom: 20px;">
<% if (user) { %>
<img class="rounded-circle" src="https://cdn.discordapp.com/avatars/<%= user.id %>/<%= user.avatar %>" width="128px" height="auto">
<br>
<br>
<h1>Hello, <%= user.username %>!</h1>
<p>Where do you like to go?</p>
<div class="btn-group btn-group-lg" role="group" aria-label="Basic example">
<a href="/dashboard/profile" type="button" class="btn btn-success"><i class="fas fa-id-card"></i> My Profile</a>
<a href="/logout" type="button" class="btn btn-danger"><i class="fas fa-sign-out-alt"></i> Log Out</a>
</div>
<% } else { %>
<img class="rounded-circle" src="<%= bot.user.displayAvatarURL({dynamic: true, size: 128}) %>" width="128px" height="auto">
<br>
<br>
<h1><%= bot.user.username %></h1>
<p>Click below to login.</p>
<a href="/login" type="button" class="btn btn-light"><i class="fab fa-discord"></i> Login with Discord</a>
<% } %>
</div>
<!-- if you would like to add a footer, use: include("partials/footer") like the header one at the top of the code. -->
10 changes: 10 additions & 0 deletions dashboard/views/partials/footer.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<footer class="text-light text-center text-lg-left" style="background-color: #7289da;">
<div class="footer-copyright text-light text-center p-3" style="background-color: rgba(0, 0, 0, 0.2);">
Copyright © <a class="link-white" href="#"><%= bot.user.username %></a> - All Rights Reserved.
</div>
</footer>


</body>

</html>
Loading

0 comments on commit a7ffc93

Please sign in to comment.