/* eslint-disable no-useless-escape */ import { Message, MessageEmbed, TextChannel } from 'discord.js'; import { Client, Command, Report } from '../class'; export default class ApplyT2 extends Command { constructor(client: Client) { super(client); this.name = 'apply-t2'; this.description = 'Applies for Tier 2.'; this.enabled = false; this.guildOnly = true; this.aliases = ['t2']; this.usage = `${this.client.config.prefix}apply-t2`; } public async run(message: Message, args: string[]) { // eslint-disable-line try { const account = await this.client.db.Account.findOne({ userID: message.author.id }); if (!account) return this.error(message.channel, 'I can\'t find a CS Account for you.'); if (account.tier > 1) return this.error(message.channel, 'You cannot apply for Tier 2 if you already have Tier 2 or higher.'); const loading = await this.loading(message.channel, 'Please wait a moment, processing application...'); const decision = await Report.tier2(account.userID, this.client.config.internalKey); if (decision.status === 'SUCCESS') { await loading.delete(); message.channel.send(`__**Decision**__\n\n**Status:** ${decision.decision}\n**Processed by:** EDS (A\*01)`); if (decision.decision === 'APPROVED') { const tier = await this.client.db.Tier.findOne({ id: 2 }); if (account.ramLimitNotification !== -1) { await account.updateOne({ $set: { tier: 2, ramLimitNotification: tier.resourceLimits.ram - 20 } }); } else { await account.updateOne({ $set: { tier: 2 } }); } const embed = new MessageEmbed(); embed.setTitle('Cloud Account | Tier Change'); embed.setColor('#0099ff'); embed.addField('User', `${account.username} | <@${account.userID}>`, true); embed.addField('Technician', 'SYSTEM', true); embed.addField('Old Tier -> New Tier', `${account.tier} -> 2`, 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 2').catch(() => { }); const ch = await this.client.channels.fetch('580950455581147146') as TextChannel; ch.send({ embeds: [embed] }); return this.client.users.fetch(account.userID).then((channel) => channel.send({ embeds: [embed] })).catch(); } return null; } await loading.delete(); return message.channel.send(`__**Decision**__\n\n**Status:** ${decision.decision}\n**Processed by:** EDS (A*01)\n\n\n*Pre-Declines will not result in a hard pull, and they may be due to a server issue or insufficient information. You may want to contact a Staff member for further information.*`); } catch (error) { return this.client.util.handleError(error, message, this); } } }