2019-10-14 23:35:30 -04:00
import fs from 'fs-extra' ;
2019-10-26 00:01:02 -04:00
import uuid from 'uuid/v4' ;
import moment from 'moment' ;
2019-10-14 23:35:30 -04:00
import { Message } from 'eris' ;
2019-10-18 18:16:32 -04:00
import { Client } from '..' ;
2019-10-26 00:01:02 -04:00
import { Command , RichEmbed } from '../class' ;
2019-10-14 23:35:30 -04:00
export default class Lock extends Command {
constructor ( client : Client ) {
super ( client ) ;
this . name = 'lock' ;
this . description = 'Locks an account.' ;
this . permissions = { roles : [ '608095934399643649' , '521312697896271873' ] } ;
2019-10-15 18:38:49 -04:00
this . enabled = true ;
2019-10-14 23:35:30 -04:00
}
2019-10-15 18:38:49 -04:00
public async run ( message : Message , args : string [ ] ) { // eslint-disable-line
2019-10-15 19:10:37 -04:00
try {
const account = await this . client . db . Account . findOne ( { $or : [ { account : args [ 0 ] } , { userID : args [ 0 ] . replace ( /[<@!>]/gi , '' ) } ] } ) ;
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 locked.*** ` ) ;
2019-10-15 19:10:37 -04:00
const edit = await message . channel . createMessage ( ` *** ${ this . client . stores . emojis . loading } Locking account...*** ` ) ;
2019-10-26 13:06:18 -04:00
if ( account . username === 'matthew' || account . root ) return edit . edit ( ` *** ${ this . client . stores . emojis . error } Permission denied.*** ` ) ;
2019-10-26 00:01:02 -04:00
await this . client . util . exec ( ` lock ${ account . username } ` ) ;
2019-10-26 13:06:18 -04:00
await account . update ( { locked : true } ) ;
2019-10-26 00:01:02 -04:00
const expiry = new Date ( ) ;
2019-10-26 14:32:56 -04:00
const lockLength = args [ 1 ] . match ( /[a-z]+|[^a-z]+/gi ) ;
2019-10-26 00:01:02 -04:00
// @ts-ignore
2019-10-26 14:32:56 -04:00
const momentMilliseconds = moment . duration ( Number ( lockLength [ 0 ] ) , lockLength [ 1 ] ) . asMilliseconds ;
2019-10-26 00:01:02 -04:00
expiry . setMilliseconds ( momentMilliseconds ) ;
2019-10-26 14:32:56 -04:00
let processed : boolean = false ;
if ( ! momentMilliseconds ) processed = true ;
2019-10-26 00:01:02 -04:00
const moderation = new this . client . db . Moderation ( {
username : account.username ,
userID : account.userID ,
logID : uuid ( ) ,
moderatorID : message.author.id ,
reason : momentMilliseconds ? args . slice ( 2 ) . join ( ' ' ) : args . slice ( 1 ) . join ( ' ' ) ,
2019-10-26 13:06:18 -04:00
type : 2 ,
2019-10-26 00:01:02 -04:00
date : new Date ( ) ,
expiration : {
expirationDate : momentMilliseconds ? expiry : null ,
processed ,
} ,
} ) ;
await moderation . save ( ) ;
edit . edit ( ` *** ${ this . client . stores . emojis . success } Account ${ account . username } has been locked by Supervisor ${ message . author . username } # ${ message . author . discriminator } .*** ` ) ;
const embed = new RichEmbed ( ) ;
embed . setTitle ( 'Account Infraction | Lock' ) ;
embed . setColor ( 15158332 ) ;
embed . addField ( 'User' , ` ${ account . username } | <@ ${ account . userID } > ` , true ) ;
embed . addField ( 'Supervisor' , ` <@ ${ message . author . id } > ` , true ) ;
2019-10-26 13:06:18 -04:00
if ( ( momentMilliseconds ? args . slice ( 2 ) . join ( ' ' ) : args . slice ( 1 ) . join ( ' ' ) ) . length > 0 ) embed . addField ( 'Reason' , momentMilliseconds ? args . slice ( 2 ) . join ( ' ' ) : args . slice ( 1 ) . join ( ' ' ) , true ) ;
2019-10-26 00:01:02 -04:00
embed . setFooter ( this . client . user . username , this . client . user . avatarURL ) ;
embed . setTimestamp ( ) ;
this . client . getDMChannel ( account . userID ) . then ( ( user ) = > {
// @ts-ignore
2019-10-26 13:34:29 -04:00
user . createMessage ( { embed } ) . catch ( ) ;
2019-10-26 00:01:02 -04:00
} ) ;
// @ts-ignore
this . client . createMessage ( '580950455581147146' , { embed } ) ;
this . client . util . transport . sendMail ( {
to : account.emailAddress ,
from : 'Library of Code sp-us | Cloud Services <support@libraryofcode.org>' ,
subject : 'Your account has been locked' ,
html : `
< h1 > Library of Code | Cloud Services < / h1 >
< p > Your Cloud Account has been locked until $ { momentMilliseconds ? moment ( expiry ) . calendar ( ) : 'indefinitely' } under the EULA . < / p >
2019-10-26 14:32:56 -04:00
< p > < b > Reason : < / b > $ { momentMilliseconds ? args . slice ( 2 ) . join ( ' ' ) : args . slice ( 1 ) . join ( ' ' ) } < / p >
< p > < b > Supervisor : < / b > $ { message . author . username } < / p >
< p > < b > Expiration : < / b > $ { momentMilliseconds ? moment ( expiry ) . format ( 'dddd, MMMM Do YYYY, h:mm:ss A' ) : 'N/A' } < / p >
2019-10-26 00:01:02 -04:00
2019-10-26 14:32:56 -04:00
< b > < i > Library of Code sp - us | Support Team < / i > < / b >
2019-10-26 00:01:02 -04:00
` ,
} ) ;
2019-10-15 19:10:37 -04:00
} catch ( error ) {
2019-10-17 15:43:32 -04:00
return this . client . util . handleError ( error , message , this ) ;
2019-10-15 19:10:37 -04:00
}
2019-10-14 23:35:30 -04:00
}
}