53 lines
2 KiB
JavaScript
53 lines
2 KiB
JavaScript
const Revolt = require('revolt.js');
|
|
const { client, logger, config, db } = require('..');
|
|
const getUser = require('../util/get_user');
|
|
|
|
module.exports.meta = {
|
|
name: 'devs',
|
|
aliases: [ 'dev', 'setdev' ],
|
|
description: 'Set user\'s developer status.',
|
|
devLevel: 1
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param { Revolt.Message } message
|
|
* @param { string[] } args
|
|
*/
|
|
module.exports.run = async (message, args) => new Promise(async (resolve, reject) => {
|
|
if (!args[0]) return client.channels.sendMessage(message.channel, ':x: No user specified');
|
|
let user = await getUser(args.shift());
|
|
if (!user) return client.channels.sendMessage(message.channel, ':x: User not found');
|
|
|
|
let devStatus = db.devs.get(user._id);
|
|
if (!devStatus) devStatus = {
|
|
level: 0,
|
|
lastModifiedBy: null
|
|
}
|
|
|
|
if (args[0]) {
|
|
if (user._id === message.author)
|
|
return client.channels.sendMessage(message.channel, 'You can\'t modify yourself.');
|
|
|
|
if (user._id === client.user._id)
|
|
return client.channels.sendMessage(message.channel, 'You can\'t modify me, you cunt.');
|
|
|
|
let newLevel = Number(args[0]);
|
|
if (isNaN(newLevel))
|
|
return client.channels.sendMessage(message.channel, `That is not a valid number.`);
|
|
|
|
let authorLevel = require('../util/dev').getDevLevel(message.author);
|
|
if (newLevel >= authorLevel)
|
|
return client.channels.sendMessage(message.channel, `You can't assign a dev level greater than or `
|
|
+ `equal to your own level. (Your level: ${authorLevel})`);
|
|
|
|
devStatus.level = newLevel;
|
|
devStatus.lastModifiedBy = message.author;
|
|
}
|
|
|
|
await client.channels.sendMessage(message.channel, `>## ${args[0] ? 'Updated ' : ''}<@${user._id}>'s dev status\n>\u200b\n`
|
|
+ `>Dev level: \`${user._id === config.botOwner ? 'Bot Owner' : devStatus.level}\`\n`
|
|
+ `>Last modified by: ${devStatus.lastModifiedBy ? `<@${devStatus.lastModifiedBy}>` : '`Nobody`'}`);
|
|
|
|
db.devs.set(user._id, devStatus);
|
|
}); |