2021-08-06 17:11:27 -04:00
import { Message , TextChannel } from 'discord.js' ;
2020-08-28 02:35:39 -04:00
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 ] ) ;
2021-08-08 22:41:32 -04:00
const account = await this . client . db . Account . findOne ( { $or : [ { username : args [ 0 ] } , { referralCode : args [ 0 ] } , { userID : args [ 0 ] . replace ( /[<@!>]/gi , '' ) } ] } ) ;
2021-08-10 15:27:07 -04:00
if ( ! account ) return this . error ( message . channel , 'Cannot find user.' ) ;
2020-08-28 02:35:39 -04:00
await account . updateOne ( { $inc : { totalReferrals : 1 } } ) ;
2021-08-08 22:41:32 -04:00
this . client . users . fetch ( account . userID ) . then ( ( chan ) = > {
2021-08-06 17:11:27 -04:00
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.' ) ;
2020-08-28 03:07:51 -04:00
} ) . catch ( ( ) = > { } ) ;
2021-08-08 22:41:32 -04:00
return this . success ( message . channel as TextChannel , ` Added referral value to account. \ nReferrer: \` ${ account . username } \` | <@ ${ account . userID } > ` ) ;
2020-08-28 02:35:39 -04:00
} catch ( error ) {
return this . client . util . handleError ( error , message , this ) ;
}
}
}