2020-03-30 07:22:32 -04:00
import { Message } from 'eris' ;
2020-06-29 02:50:26 -04:00
import { Client , Command } from '../class' ;
2020-03-30 07:22:32 -04:00
export default class Bearer extends Command {
constructor ( client : Client ) {
super ( client ) ;
this . name = 'bearer' ;
this . description = 'Creates a bearer token.' ;
this . usage = ` ${ this . client . config . prefix } bearer ` ;
this . guildOnly = false ;
this . enabled = true ;
}
public async run ( message : Message ) {
try {
const account = await this . client . db . Account . findOne ( { userID : message.author.id } ) ;
2020-06-29 02:35:14 -04:00
if ( ! account ) return this . error ( message . channel , 'Account not found.' ) ;
2020-03-30 07:22:32 -04:00
// eslint-disable-next-line no-underscore-dangle
const bearer = await this . client . server . security . createBearer ( account . _id ) ;
const dm = await this . client . getDMChannel ( message . author . id ) ;
const msg = await dm . createMessage ( ` __**Library of Code sp-us | Cloud Services [API]**__ \ n*This message will automatically be deleted in 60 seconds, copy the token and save it. You cannot recover it.* \ n \ n ${ bearer } ` ) ;
2020-06-29 02:35:14 -04:00
this . error ( message . channel , 'Bearer token sent to direct messages.' ) ;
2020-03-30 07:22:32 -04:00
return setTimeout ( ( ) = > {
msg . delete ( ) ;
} , 60000 ) ;
} catch ( error ) {
return this . client . util . handleError ( error , message , this ) ;
}
}
}