2020-08-28 02:35:39 -04:00
|
|
|
import { Message } from 'eris';
|
|
|
|
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 <user>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async run(message: Message, args: string[]) { // eslint-disable-line
|
|
|
|
try {
|
|
|
|
if (!args.length) return this.client.commands.get('help').run(message, [this.name]);
|
2020-08-28 02:55:29 -04:00
|
|
|
const account = await this.client.db.Account.findOne({ $or: [{ username: args[0] }, { referralCode: args[0] }, { userID: args[0].replace(/[<@!>]/gi, '') }] });
|
2020-08-28 02:35:39 -04:00
|
|
|
if (!account) return this.error(message.channel, 'Cannot find user.');
|
|
|
|
|
|
|
|
await account.updateOne({ $inc: { totalReferrals: 1 } });
|
|
|
|
return this.success(message.channel, 'Added referral value to account.');
|
|
|
|
} catch (error) {
|
|
|
|
return this.client.util.handleError(error, message, this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|