34 lines
1.4 KiB
JavaScript
34 lines
1.4 KiB
JavaScript
const Revolt = require('revolt.js');
|
|
const { client, logger, config } = require('..');
|
|
const { levels, levelups } = require('../util/levels');
|
|
const getUser = require('../util/get_user');
|
|
|
|
module.exports.meta = {
|
|
name: 'rank',
|
|
aliases: [ 'level', 'xp' ],
|
|
description: 'See your level and XP.'
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param { Revolt.Message } message
|
|
* @param { string[] } args
|
|
*/
|
|
module.exports.run = async (message, args) => new Promise(async (resolve, reject) => {
|
|
const channel = await client.channels.fetch(message.channel);
|
|
if (channel.channel_type !== "Group") return client.channels.sendMessage(message.channel, `You can't earn XP in this channel.`);
|
|
|
|
let target = await getUser(args.join(' '));
|
|
const { xp, level, enabled } = (levels.get(target?._id ?? message.author) || {});
|
|
|
|
if (xp === undefined || level === undefined)
|
|
return client.channels.sendMessage(message.channel,
|
|
`${target ? `${target.username} doesn't` : `You don't`} have any XP yet. Check back later!`);
|
|
|
|
const response = `${target ? `${target.username} is` : 'You are'} level **${level}** with **${xp}** XP. `
|
|
+ `XP required for level up: **${levelups.find(l => l > xp) - xp}**.\n`
|
|
+ (process.env.DISABLE_LEVELS === 'true' ? '**Warning:** You can\'t currently gain XP on this instance.' : '');
|
|
|
|
client.channels.sendMessage(message.channel, response)
|
|
.catch(console.warn);
|
|
}); |