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

Commit

Permalink
Economy #3 - Leaderboard Route
Browse files Browse the repository at this point in the history
  • Loading branch information
ADAMJR committed Feb 16, 2021
1 parent 63094c7 commit 3388094
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
16 changes: 15 additions & 1 deletion dashboard/routes/root-routes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const express = require('express');
const { commands } = require('../../handlers/command-handler');
const bot = require('../../bot');
const users = require('../../data/users');

const router = express.Router();

Expand All @@ -17,4 +19,16 @@ router.get('/commands', (req, res) => res.render('commands', {
commandsString: JSON.stringify(Array.from(commands.values()))
}));

module.exports = router;
router.get('/leaderboard/:id', async (req, res) => {
const guild = bot.guilds.cache.get(req.params.id);
if (!guild)
return res.render('errors/404');

const savedUsers = (await users.getInGuild(req.params.id))
.sort((a, b) => (a.coins > b.coins) ? 1 : -1)
.slice(0, 100);

res.render('dashboard/leaderboard', { guild, savedUsers });
});

module.exports = router;
1 change: 1 addition & 0 deletions dashboard/views/dashboard/show.pug
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ html(lang='en')

.category Other
a#auditLog.cursor-pointer #[i.fas.fa-book.pr-1.text-muted] Audit Log
a.cursor-pointer(href='/leaderboard/' + guild.id) #[i.fas.fa-trophy.pr-1.text-muted] Leaderboard

include ../includes/navbar.pug

Expand Down
2 changes: 2 additions & 0 deletions handlers/events/message-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ module.exports = class extends Event {
on = 'message';

async invoke(msg) {
if (!msg.guild || msg.author.bot) return;

const command = await handleCommand(msg);
if (command)
return await logs.add(msg.guild.id, 'commands');
Expand Down
5 changes: 3 additions & 2 deletions modules/economy.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ module.exports = new class {

async handleMessage(msg) {
if (this.inCooldown(msg.author.id)) return;
this.handleCooldown(msg.author.id);

const minLength = 5;
if (msg.content.length < minLength) return;

const savedUser = await users.get(msg.author.id);
savedUser.coins += 5;
await savedUser.save();
await savedUser.save();

this.handleCooldown(msg.author.id);
}

handleCooldown(userId) {
Expand Down

0 comments on commit 3388094

Please sign in to comment.