Skip to content

Commit

Permalink
Fix guild issue with dashboard
Browse files Browse the repository at this point in the history
Closes #31
  • Loading branch information
Venk authored and Venk committed Nov 29, 2020
1 parent 0c3a7da commit d5c4031
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 48 deletions.
4 changes: 2 additions & 2 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ const config = {
// Dashboard settings
"dashboardEnabled": false, // Off by default
"port": port,
"clientId": process.env.clientId,
"clientSecret": process.env.clientId,
"clientId": process.env.CLIENT_ID,
"clientSecret": process.env.CLIENT_SECRET,
"scopes": ["identify", "guilds"],
"redirectUri": "http://" + ip.address() + ":" + port + "/authorize/callback",

Expand Down
1 change: 1 addition & 0 deletions modules/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const initWeb = (client) => {
app.use("/me", require("../routes/me"));
app.use("/servers", require("../routes/servers"));
app.use("/status", require("../routes/status"));
app.use("/command", require("../routes/command"));
app.get("/commands", (req, res) => {
if (!req.session.user || req.session.guild) res.redirect("/");

Expand Down
9 changes: 9 additions & 0 deletions routes/command.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const router = require('express').Router();
const client = require('../bot.js')

router.get('/', (req, res) => {
if (!req.session.user) { res.redirect('/'); return }
res.render('command', { pageTitle: 'Command - Tsuyo', user: req.session.user || null, djsclient: client });
});

module.exports = router;
18 changes: 9 additions & 9 deletions routes/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@ const router = require('express').Router()
const client = require('../bot.js')

router.get('/', async (req, res) => {
//if (!req.session.user) return res.redirect('/')
//if (!req.session.guilds) return res.redirect('/')
//if (!client.guilds.has(req.query.id)) return res.redirect('/')
//if (!client.guilds.get(req.query.id).members.has(req.session.user.id)) return res.redirect('/')
if (!req.session.user) return res.redirect('/')
if (!req.session.guilds) return res.redirect('/')
if (!client.guilds.cache.has(req.query.id)) return res.redirect('/')
if (!client.guilds.cache.get(req.query.id).members.cache.has(req.session.user.id)) return res.redirect('/')

res.render('server/members', { user: req.session.user, guild: req.query.id, djsclient: client })
})

router.get('/config', async (req, res) => {
if (!req.session.user) return res.redirect('/')
//if (!req.session.guilds) return res.redirect('/')
if (!client.guilds.has(req.query.id)) return res.redirect('/')
if (!client.guilds.cache.has(req.query.id)) return res.redirect('/')

if (client.guilds.get(req.query.id).members.get(req.session.user.id).hasPermission('ADMINISTRATOR')) return res.redirect('/guild/config?id=' + req.query.id)
if (client.guilds.cache.get(req.query.id).members.cache.get(req.session.user.id).hasPermission('ADMINISTRATOR')) return res.redirect('/server/config?id=' + req.query.id)

res.render('server/config', { user: req.session.user, guild: req.query.id, djsclient: client })
})

router.post('/config', async (req, res) => {
if (!req.session.user) return res.redirect('/')
if (!req.session.guilds) return res.redirect('/')
if (!client.guilds.has(req.query.id)) return res.redirect('/')
if (!client.guilds.get(req.query.id).members.has(req.session.user.id)) return res.redirect('/')
if (!client.guilds.cache.has(req.query.id)) return res.redirect('/')
if (!client.guilds.cache.get(req.query.id).members.cache.has(req.session.user.id)) return res.redirect('/')

if (!client.guilds.get(req.query.id).members.get(req.session.user.id).hasPermission('MANAGE_SERVER')) return console.log("nope")
if (!client.guilds.cache.get(req.query.id).members.cache.get(req.session.user.id).hasPermission('MANAGE_SERVER')) return console.log("nope")

client.settings.set(req.query.id, req.body)
res.render('server/config', { user: req.session.user, guild: req.query.id, djsclient: client })
Expand Down
21 changes: 7 additions & 14 deletions routes/status.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const router = require('express').Router()
const client = require('../bot.js')
const djsclient = require('../bot.js')
const moment = require('moment')
require('moment-duration-format')

Expand All @@ -8,23 +8,16 @@ router.get('/', async (req, res) => {
if (!req.session.guilds) return res.redirect('/')

require('pidusage')(process.pid, (err, stats) => {
const duration = moment.duration(client.uptime).format(' D [days], H [hrs], m [mins], s [secs]')
const duration = moment.duration(djsclient.uptime).format(' D [days], H [hrs], m [mins], s [secs]')
res.render('status', {
user: req.session.user,
stats: {
ram: `${(process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2)}MB`,
uptime: `${duration}`,
users: `${client.users.size}`,
servers: `${client.guilds.size.toLocaleString()}`,
channels: `${client.channels.size.toLocaleString()}`,
status: `${client.user.presence.status}`,
game: `${client.user.presence.game}`,
discord1js: `v${require('discord.js').version}`,
cpu_usage: `${Math.round(stats.cpu)}%`,
node1js: `${process.version}`,
startup_time: `${client.startuptime}ms`,
voice_connections: `${client.voiceConnections.size}`,
dependencies: `${Object.keys(require('../../package').dependencies).length}`
users: `${djsclient.users.cache.size}`,
servers: `${djsclient.guilds.cache.size.toLocaleString()}`,
channels: `${djsclient.channels.cache.size.toLocaleString()}`,
status: `${djsclient.user.presence.status}`,
game: `${djsclient.user.presence.game}`,
}
})
})
Expand Down
6 changes: 3 additions & 3 deletions views/command.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<%- include('partials/header.ejs') %>
<body>
<%- include('partials/navbar.ejs') %>

<center>
<% let cmd = djsclient.commands.cache.get(command); %>
<% let cmd = djsclient.commands.get(command); %>
<h2><%= cmd.help.name %></h2>
<p>
<%= cmd.help.description %>
Expand All @@ -24,4 +24,4 @@
</p>
</center>
</body>
</html>
</html>
10 changes: 5 additions & 5 deletions views/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
</head>
<body>
<%- include('./partials/navbar.ejs') %>

<div class="cover">
<div class="text">
<img class="logo" src="https://cdn.discordapp.com/avatars/492871769485475840/8df7979a4d09f68c3154fad60391ec9f.png" oncontextmenu="return false;" draggable="false" oncopy="return false;" oncut="return false;">
<img class="logo" src="https://cdn.discordapp.com/avatars/492871769485475840/29ea7a72135ebde63f8cebd5f82ef42b.png?size=256" oncontextmenu="return false;" draggable="false" oncopy="return false;" oncut="return false;">
<h1>Tsuyo - A community-built Discord bot.</h1>
<p>Equipped with many features, this bot is easy to set up and optimizes your Discord experience.</p>
<div class="buttons">
Expand All @@ -20,13 +20,13 @@
</div>
</div>
</div>

<div class="features">
<h1 style="padding-top: 125px; text-align: center">Features</h1>
<table style="width:100%">
<tr>
<td><h2>Welcome</h2><p>Greet members with a custom welcome message.</p></td>
<td><h2>Fully Configurable</h2><p>Configure the bot to perform to your Discord's needs.</p></td>
<td><h2>Fully Configurable</h2><p>Configure the bot to perform to your Discord's needs.</p></td>
<td><h2>Logging</h2><p>Choose actions you would like to monitor.</p></td>
</tr>
<tr>
Expand All @@ -43,4 +43,4 @@
<footer>
<%- include('./partials/footer.ejs') %>
</footer>
</html>
</html>
20 changes: 10 additions & 10 deletions views/money.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<%- include('partials/header.ejs') %>
<body>
<%- include('partials/navbar.ejs') %>

<div>
<%
djsclient.money.ensure(user.id, {
money: 0,
stone: 250
});
djsclient.items.ensure(user.id, {});
const sellStone = () => {
let sts;
Expand All @@ -22,27 +22,27 @@
djsclient.money.set(user.id, money + Math.floor(stone), 'money');
};
%>

<button onclick="<%= sellStone() %>" style="margin-top: 10px;margin-left: 21px;padding: 20px;color: #FFFFFF;background-color: #23272A;border: none;">Sell All Stone</button>
<center>
<h2>
Money
</h2>
<% let money = djsclient.money.cache.get(user.id, 'money') %>
<% let stone = djsclient.money.cache.get(user.id, 'stone') %>

<% let money = djsclient.money.get(user.id, 'money') %>
<% let stone = djsclient.money.get(user.id, 'stone') %>

<p>You have<wbr> $<%= money %><br>
and <%= stone %><wbr> stone!</p>

<h2>
Items
</h2>

<% for (let i = 0;i < Object.keys(djsclient.items.cache.get(user.id)).length; i++) { %>
<p><%= i + 1 %>. <%= Object.keys(djsclient.items.cache.get(user.id))[i] %></p>
<% } %>
</center>
</div>
</body>
</html>
</html>
13 changes: 8 additions & 5 deletions views/servers.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
<%- include('partials/navbar.ejs') %>
<div class="page-content">
<div class="servers">
<h1 class="title">Servers you can manage:</h1>
<% guilds.forEach((guild) => { %>
<% if (!djsclient.guilds.has(guild.id)) { %>
<h1 class="title">Servers you can manage: </h1>
<% djsclient.guilds.cache.forEach((guild) => { %>
<% if (!guild.member(user.id)) return %>
<% const member = guild.members.cache.find(p => p.id === user.id) %>
<% if (!member.hasPermission('ADMINISTRATOR')) return %>
<% if (!djsclient.guilds.cache.has(guild.id)) { %>
<a id="invite-btn" target="_blank" href="https://discordapp.com/oauth2/authorize?client_id=492871769485475840&scope=bot&permissions=1506142455&guild_id=<%= guild.id %>">Invite to server
</a>
<% if (guild.icon) { %>
<div class="toolelem">
<div class="text"><span class="tooltext"><%= guild.name %></span></div>
Expand Down Expand Up @@ -42,4 +45,4 @@
</div>
</div>
</body>
</html>
</html>

0 comments on commit d5c4031

Please sign in to comment.