import { Message, TextChannel } from 'discord.js'; import { Client, Command } from '../class'; export default class AddReferral extends Command { constructor(client: Client) { super(client); this.name = 'addreferral'; this.description = 'Adds a referral value to an account.'; this.permissions = { roles: ['662163685439045632', '701454780828221450'] }; this.enabled = true; this.aliases = ['af', 'refer']; this.usage = `${this.client.config.prefix}addreferral `; } public async run(message: Message, args: string[]) { // eslint-disable-line try { if (!args.length) return this.client.commands.get('help').run(message, [this.name]); const account = await this.client.db.Account.findOne({ $or: [{ username: args[0] }, { referralCode: args[0] }, { userID: args[0].replace(/[<@!>]/gi, '') }] }); if (!account) return this.error(message.channel, 'Cannot find user.'); await account.updateOne({ $inc: { totalReferrals: 1 } }); this.client.users.fetch(account.userID).then((chan) => { chan.send('__**Referral - Application Approval**__\nAn applicant who used your referral code during the application process has been approved. Your referral count has been increased.'); }).catch(() => {}); return this.success(message.channel as TextChannel, `Added referral value to account.\nReferrer: \`${account.username}\` | <@${account.userID}>`); } catch (error) { return this.client.util.handleError(error, message, this); } } }