1
0
Fork 0
cloudservices/src/commands/tier.ts

46 lines
2.7 KiB
TypeScript

import { Message } from 'eris';
import { Client, 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: ['662163685439045632', '701454780828221450'] };
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 this.loading(message.channel, '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();
const tier = await this.client.db.Tier.findOne({ id: Number(args[1]) });
if (account.ramLimitNotification !== -1) {
await account.updateOne({ $set: { tier: Number(args[1]), ramLimitNotification: tier.resourceLimits.ram - 20 } });
} else {
await account.updateOne({ $set: { tier: Number(args[1]) } });
}
edit.edit(`***${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('Technician', `<@${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();
await this.client.util.sendMessageToUserTerminal(account.username, `A technician has changed your tier to ${args[1]}`).catch(() => { });
this.client.createMessage('580950455581147146', { embed }); return this.client.getDMChannel(account.userID).then((channel) => channel.createMessage({ embed })).catch();
} catch (error) {
return this.client.util.handleError(error, message, this);
}
}
}