2019-10-26 13:06:40 -04:00
import { Message } from 'eris' ;
import { Client } from '..' ;
2019-11-21 21:22:07 -05:00
import { Command } from '../class' ;
2019-10-26 13:06:40 -04:00
export default class Unlock extends Command {
constructor ( client : Client ) {
super ( client ) ;
this . name = 'unlock' ;
this . description = 'Unlocks an account.' ;
2020-01-03 10:15:30 -05:00
this . permissions = { roles : [ '455972169449734144' , '662163685439045632' ] } ;
2019-10-26 13:06:40 -04:00
this . enabled = true ;
}
public async run ( message : Message , args : string [ ] ) { // eslint-disable-line
try {
2019-10-28 16:21:04 -04:00
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 ] } , { userID : args [ 0 ] . replace ( /[<@!>]/gi , '' ) } ] } ) ;
2019-10-26 13:06:40 -04:00
if ( ! account ) return message . channel . createMessage ( ` *** ${ this . client . stores . emojis . error } Cannot find user.*** ` ) ;
2019-10-26 14:32:56 -04:00
if ( ! account . locked ) return message . channel . createMessage ( ` *** ${ this . client . stores . emojis . error } This account is already unlocked.*** ` ) ;
2019-10-26 13:30:51 -04:00
const edit = await message . channel . createMessage ( ` *** ${ this . client . stores . emojis . loading } Unlocking account...*** ` ) ;
2019-10-26 13:06:40 -04:00
if ( account . username === 'matthew' || account . root ) return edit . edit ( ` *** ${ this . client . stores . emojis . error } Permission denied.*** ` ) ;
await this . client . util . exec ( ` unlock ${ account . username } ` ) ;
2019-10-28 16:21:04 -04:00
await account . updateOne ( { locked : false } ) ;
2019-10-26 13:06:40 -04:00
2019-10-29 14:20:51 -04:00
await this . client . util . createModerationLog ( account . userID , message . member , 3 , args . slice ( 1 ) . join ( ' ' ) ) ;
2019-11-21 21:22:07 -05:00
edit . edit ( ` *** ${ this . client . stores . emojis . success } Account ${ account . username } has been unlocked by Moderator ${ message . author . username } # ${ message . author . discriminator } .*** ` ) ;
2019-10-26 13:06:40 -04:00
} catch ( error ) {
await this . client . util . handleError ( error , message , this ) ;
}
}
}