command to change tier

merge-requests/4/head
Matthew 2020-03-29 04:32:27 -04:00
parent efc8dc8f02
commit 2159845d46
No known key found for this signature in database
GPG Key ID: 766BE43AE75F7559
1 changed files with 41 additions and 0 deletions

41
src/commands/tier.ts Normal file
View File

@ -0,0 +1,41 @@
/* eslint-disable consistent-return */
import { Message } from 'eris';
import { Client } from '..';
import { Command, RichEmbed } from '../class';
export default class Tier extends Command {
constructor(client: Client) {
super(client);
this.name = 'tier';
this.description = 'Changes the tier level for an account.';
this.usage = `${this.client.config.prefix}tier <username | user ID> <1 | 2 | 3>`;
this.permissions = { roles: ['446104438969466890'] };
this.enabled = true;
}
public async run(message: Message, args: string[]) {
try {
if (!args.length) return this.client.commands.get('help').run(message, [this.name]);
const edit = await message.channel.createMessage(`***${this.client.stores.emojis.loading} Editing tier...***`);
const account = await this.client.db.Account.findOne({ $or: [{ username: args[0] }, { userID: args[0].replace(/[<@!>]/gi, '') }] });
if (!account) return edit.edit(`***${this.client.stores.emojis.error} Cannot find user.***`);
if (account.root) return edit.edit(`***${this.client.stores.emojis.error} Permission denied.***`);
if (Number.isNaN(Number(args[1]))) return edit.edit(`***${this.client.stores.emojis.error} The tier you provided is not a valid number. It should be between 1 and 3.***`);
if (Number(args[1]) > 3 || Number(args[1]) < 1) return edit.edit(`***${this.client.stores.emojis.error} You can only choose a Tier between 1 and 3.***`);
message.delete();
await account.updateOne({ $set: { tier: Number(args[1]) } });
message.channel.createMessage(`***${this.client.stores.emojis.success} Tier for ${account.username} has been changed to ${args[1]}.***`);
const embed = new RichEmbed();
embed.setTitle('Cloud Account | Tier Change');
embed.setColor('#0099ff');
embed.addField('User', `${account.username} | <@${account.userID}>`, true);
embed.addField('Moderator', `<@${message.author.id}>`, true);
embed.addField('Old Tier -> New Tier', `${account.tier} -> ${args[1]}`, true);
embed.setFooter(this.client.user.username, this.client.user.avatarURL);
embed.setTimestamp();
this.client.createMessage('580950455581147146', { embed }); this.client.getDMChannel(account.userID).then((channel) => channel.createMessage({ embed })).catch();
} catch (error) {
await this.client.util.handleError(error, message, this);
}
}
}