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

47 lines
2.8 KiB
TypeScript
Raw Normal View History

2020-03-29 04:32:27 -04:00
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>`;
2020-04-20 16:18:19 -04:00
this.permissions = { roles: ['662163685439045632', '701454780828221450'] };
2020-03-29 04:32:27 -04:00
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();
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]) } });
}
2020-03-29 23:57:55 -04:00
edit.edit(`***${this.client.stores.emojis.success} Tier for ${account.username} has been changed to ${args[1]}.***`);
2020-03-29 04:32:27 -04:00
const embed = new RichEmbed();
embed.setTitle('Cloud Account | Tier Change');
embed.setColor('#0099ff');
embed.addField('User', `${account.username} | <@${account.userID}>`, true);
2020-05-05 19:50:14 -04:00
embed.addField('Technician', `<@${message.author.id}>`, true);
2020-03-29 04:32:27 -04:00
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 upgraded your tier to ${args[1]}`).catch(() => { });
2020-03-30 07:22:32 -04:00
this.client.createMessage('580950455581147146', { embed }); return this.client.getDMChannel(account.userID).then((channel) => channel.createMessage({ embed })).catch();
2020-03-29 04:32:27 -04:00
} catch (error) {
2020-03-30 07:22:32 -04:00
return this.client.util.handleError(error, message, this);
2020-03-29 04:32:27 -04:00
}
}
}