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

Commit

Permalink
Finish 1PG
Browse files Browse the repository at this point in the history
  • Loading branch information
ADAMJR committed Feb 18, 2021
1 parent 9bbbc7c commit 5e29c26
Show file tree
Hide file tree
Showing 5 changed files with 267 additions and 1 deletion.
39 changes: 39 additions & 0 deletions commands/profile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const Command = require('./command');
const users = require('../data/users');
const canvacord = require('canvacord');
const economy = require('../modules/economy');

module.exports = class extends Command {
name = 'profile';

async execute(msg, userMention) {
const userId = userMention
?.replace('<@!', '')
.replace('>', '') ?? msg.author.id;
const user = msg.guild.members.cache.get(userId)?.user;
if (!user)
throw new TypeError('Member not found');
const savedUser = await users.get(userId);
const rank = await economy.getRank(userId, msg.guild.id);

const buffer = await new canvacord.Rank()
.setAvatar(user.displayAvatarURL({ format: 'png' }))
.setRank(rank, '# ', true)
.setLevel(0, ' ', false)
.setCurrentXP(savedUser.coins)
.setRequiredXP(1_000_000)
.setProgressBar('#C5B358', 'COLOR', false)
.setProgressBarTrack('#000000')
.setBackground('IMAGE', 'https://cdn.pixabay.com/photo/2019/04/30/10/47/background-4168284_960_720.jpg')
.setUsername(user.username)
.setDiscriminator(user.discriminator)
.build();

await msg.channel.send({
files: [{
attachment: buffer,
name: 'profile.png',
}]
});
}
}
2 changes: 1 addition & 1 deletion dashboard/routes/root-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ router.get('/leaderboard/:id', async (req, res) => {
return res.render('errors/404');

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

res.render('dashboard/leaderboard', { guild, savedUsers });
Expand Down
7 changes: 7 additions & 0 deletions modules/economy.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@ module.exports = new class {
inCooldown(userId) {
return this.cooldowns.includes(userId);
}

async getRank(userId, guildId) {
const savedUsers = await users.getInGuild(guildId);
return savedUsers
.sort((a, b) => (a.coins < b.coins) ? 1 : 0)
.findIndex(u => u.id === userId) + 1;
}
}
219 changes: 219 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"dependencies": {
"@2pg/music": "^1.1.6",
"body-parser": "^1.19.0",
"canvacord": "^5.0.8",
"cookies": "^0.8.0",
"disco-oauth": "^4.2.7",
"discord.js": "^12.2.0",
Expand Down

0 comments on commit 5e29c26

Please sign in to comment.