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 as TextChannel, '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); } } }