2019-10-30 21:25:52 -04:00
/* eslint-disable consistent-return */
import moment from 'moment' ;
import { Message } from 'eris' ;
import { Client } from '..' ;
import { Command , RichEmbed } from '../class' ;
2019-11-09 23:05:17 -05:00
import { dataConversion } from '../functions' ;
2019-11-19 18:57:15 -05:00
import User from './whois_user' ;
2019-10-30 21:25:52 -04:00
export default class Whois extends Command {
constructor ( client : Client ) {
super ( client ) ;
2019-10-30 21:28:07 -04:00
this . name = 'whois' ;
2019-10-30 21:25:52 -04:00
this . description = 'Views information for a cloud account.' ;
this . aliases = [ 'account' , 'user' ] ;
2019-10-30 22:10:06 -04:00
this . usage = ` ${ this . client . config . prefix } account [User Name | User ID | Email Address] ` ;
2019-10-30 21:25:52 -04:00
this . permissions = { roles : [ '446104438969466890' ] } ;
2019-11-19 18:57:15 -05:00
this . subcmds = [ User ] ;
2019-10-30 21:25:52 -04:00
this . enabled = true ;
}
public async run ( message : Message , args : string [ ] ) {
try {
2019-10-30 21:29:08 -04:00
if ( ! args [ 0 ] ) return this . client . commands . get ( 'help' ) . run ( message , [ this . name ] ) ;
2019-10-30 21:25:52 -04:00
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 embed = new RichEmbed ( ) ;
embed . setTitle ( 'Account Information' ) ;
if ( this . client . users . get ( account . userID ) ) embed . setThumbnail ( this . client . users . get ( account . userID ) . avatarURL ) ;
embed . setColor ( 0x36393f ) ;
2020-01-05 14:59:28 -05:00
let fingerInformation : string ;
const result = await this . client . util . exec ( ` finger ${ account . username } ` ) ;
if ( message . member && ! message . member . roles . includes ( '143414786913206272' ) ) {
fingerInformation = result . replace ( /((^\s*((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]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'[MASKED IP ADDRESS]' ) ;
} else {
fingerInformation = result ;
}
embed . setDescription ( ` ${ fingerInformation } \ n ${ await this . client . util . exec ( ` chage -l ${ account . username } ` ) } ` ) ;
2019-10-30 21:25:52 -04:00
embed . addField ( 'Username' , ` ${ account . username } | <@ ${ account . userID } > ` , true ) ;
embed . addField ( 'ID' , account . userID , true ) ;
embed . addField ( 'Email Address' , account . emailAddress , true ) ;
embed . addField ( 'Created By' , ` <@ ${ this . client . users . get ( account . createdBy ) . id } > ` , true ) ;
embed . addField ( 'Created At' , moment ( account . createdAt ) . format ( 'dddd, MMMM Do YYYY, h:mm:ss A' ) , true ) ;
2019-11-09 23:14:14 -05:00
const cpuUsage = await this . client . util . exec ( ` top -b -n 1 -u ${ account . username } | awk 'NR>7 { sum += $ 9; } END { print sum; }' ` ) ;
2019-11-09 23:50:28 -05:00
embed . addField ( 'CPU Usage' , cpuUsage . split ( '\n' ) [ 0 ] ? ` ${ cpuUsage . split ( '\n' ) [ 0 ] } % ` : '0%' , true ) ;
2019-11-10 00:03:35 -05:00
embed . addField ( 'Memory' , dataConversion ( Number ( await this . client . util . exec ( ` memory ${ account . username } ` ) ) * 1000 ) , true ) ;
2019-11-09 23:34:19 -05:00
const data = await this . client . redis . get ( ` storage- ${ account . username } ` ) ? dataConversion ( Number ( await this . client . redis . get ( ` storage- ${ account . username } ` ) ) ) : 'N/A' ;
2019-11-09 23:05:17 -05:00
embed . addField ( 'Storage' , data , true ) ;
2019-10-30 21:25:52 -04:00
let details = '' ;
if ( account . locked ) details += 'This account is currently locked.\n' ;
if ( account . permissions . engineer ) details += 'This account belongs to an Engineer.\n' ;
else if ( account . permissions . communityManager ) details += 'This account belongs to a Community Manager.\n' ;
else if ( account . permissions . supervisor ) details += 'This account belongs to a Supervisor.\n' ;
else if ( account . permissions . staff ) details += 'This account belongs to a Staff member.\n' ;
if ( account . root ) details += 'This account has root/administrative privileges.\n' ;
if ( details ) embed . addField ( 'Additional Details' , details , true ) ;
embed . setFooter ( this . client . user . username , this . client . user . avatarURL ) ;
embed . setTimestamp ( ) ;
// @ts-ignore
message . channel . createMessage ( { embed } ) ;
} catch ( error ) {
await this . client . util . handleError ( error , message , this ) ;
}
}
}