From 2159845d467bc56be64065328332f59cf5fafc1f Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sun, 29 Mar 2020 04:32:27 -0400 Subject: [PATCH] command to change tier --- src/commands/tier.ts | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/commands/tier.ts diff --git a/src/commands/tier.ts b/src/commands/tier.ts new file mode 100644 index 0000000..a86d2e6 --- /dev/null +++ b/src/commands/tier.ts @@ -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 <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); + } + } +}