2019-10-28 16:21:04 -04:00
import { Message , PrivateChannel } from 'eris' ;
import uuid from 'uuid/v4' ;
import { Command , RichEmbed } from '../class' ;
2019-10-28 17:29:06 -04:00
import { Client } from '..' ;
2019-10-28 16:21:04 -04:00
export default class DeleteAccount extends Command {
constructor ( client : Client ) {
super ( client ) ;
this . name = 'deleteaccount' ;
this . description = 'Delete an account on the Cloud VM' ;
2019-10-28 17:29:06 -04:00
this . usage = ` ${ this . client . config . prefix } deleteaccount [User ID] [Reason] | ${ this . client . config . prefix } deleteaccount [Username] [Reason] | ${ this . client . config . prefix } deleteaccount [Email] [Reason] ` ;
2019-10-28 16:21:04 -04:00
this . aliases = [ 'deleteacc' , 'dacc' , 'daccount' , 'delete' ] ;
this . permissions = { roles : [ '475817826251440128' , '525441307037007902' ] } ;
this . enabled = true ;
}
public async run ( message : Message , args : string [ ] ) {
try {
if ( ! args [ 1 ] ) 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 ] } , { emailAddress : args [ 0 ] } ] } ) ;
if ( ! account ) return message . channel . createMessage ( ` ${ this . client . stores . emojis . error } ***Account not found*** ` ) ;
const { root , username , userID , emailAddress } = account ;
if ( root ) return message . channel . createMessage ( ` ${ this . client . stores . emojis . error } ***Permission denied*** ` ) ;
const pad = ( number : number , amount : number ) : string = > '0' . repeat ( amount - number . toString ( ) . length ) + number ;
const randomNumber = Math . floor ( Math . random ( ) * 9999 ) ;
const verify = pad ( randomNumber , 4 ) ;
try {
await this . client . util . messageCollector ( message ,
` ***Please confirm that you are permanently deleting ${ username } 's account by entering ${ verify } . This action cannot be reversed.*** ` ,
15000 , true , [ verify ] , ( msg ) = > ! ( message . channel instanceof PrivateChannel && msg . author . id === message . author . id ) ) ;
} catch ( error ) {
if ( error . message . includes ( 'Did not supply' ) ) return message ;
throw error ;
}
const deleting = await message . channel . createMessage ( ` ${ this . client . stores . emojis . loading } ***Deleteing account, please wait...*** ` ) ;
await this . client . util . deleteAccount ( username ) ;
const reason = args . slice ( 1 ) . join ( ' ' ) ;
const logInput = { username , userID , logID : uuid ( ) , moderatorID : message.author.id , type : 4 , date : new Date ( ) , reason : null } ;
if ( reason ) logInput . reason = reason ;
2019-10-29 14:20:51 -04:00
await this . client . util . createModerationLog ( args [ 0 ] , message . member , 4 , reason ) ;
/ *
2019-10-28 16:21:04 -04:00
const log = await new this . client . db . Moderation ( logInput ) ;
await log . save ( ) ;
const embed = new RichEmbed ( ) ;
embed . setTitle ( 'Cloud Account | Delete' ) ;
embed . setColor ( 'ff0000' ) ;
embed . addField ( 'User' , ` ${ username } | <@ ${ userID } > ` ) ;
embed . addField ( 'Engineer' , ` <@ ${ message . author . id } > ` , true ) ;
if ( reason ) embed . addField ( 'Reason' , reason ) ;
embed . setFooter ( this . client . user . username , this . client . user . avatarURL ) ;
embed . setTimestamp ( ) ;
// @ts-ignore
this . client . createMessage ( '580950455581147146' , { embed } ) ;
this . client . getDMChannel ( userID ) . then ( ( user ) = > {
// @ts-ignore
user . createMessage ( { embed } ) . catch ( ) ;
} ) ;
2019-10-29 14:20:51 -04:00
* /
2019-10-28 16:21:04 -04:00
this . client . util . transport . sendMail ( {
to : account.emailAddress ,
from : 'Library of Code sp-us | Cloud Services <support@libraryofcode.org>' ,
subject : 'Your account has been deleted' ,
html : `
< h1 > Library of Code | Cloud Services < / h1 >
2019-10-28 19:56:00 -04:00
< p > Your Cloud Account has been deleted by our Engineers . There is no way to recover your files and this decision cannot be appealed . We ' re sorry to see you go . < / p >
2019-10-28 16:21:04 -04:00
< p > < b > Reason : < / b > $ { reason } < / p >
< p > < b > Engineer : < / b > $ { message . author . username } < / p >
< b > < i > Library of Code sp - us | Support Team < / i > < / b >
` ,
} ) ;
return deleting . edit ( ` ${ this . client . stores . emojis . success } ***Account ${ username } has been deleted by Engineer ${ message . author . username } # ${ message . author . discriminator } *** ` ) ;
} catch ( error ) {
return this . client . util . handleError ( error , message , this ) ;
}
}
}