2020-10-06 15:06:02 -04:00
/* eslint-disable no-continue */
2020-09-10 00:54:19 -04:00
/* eslint-disable default-case */
2020-10-28 20:33:21 -04:00
import moment from 'moment' ;
2020-11-05 02:53:12 -05:00
import { median , mode , mean } from 'mathjs' ;
2020-10-24 02:54:01 -04:00
import { v4 as uuid } from 'uuid' ;
2020-11-05 02:53:12 -05:00
import { createPaginationEmbed } from 'eris-pagination' ;
2020-10-02 18:00:05 -04:00
import { Message , User , TextChannel } from 'eris' ;
2020-09-03 03:47:24 -04:00
import { Client , Command , RichEmbed } from '../class' ;
export default class Score extends Command {
constructor ( client : Client ) {
super ( client ) ;
this . name = 'score' ;
2020-09-07 01:22:06 -04:00
this . description = 'Pulls a hard score report for a member.' ;
2020-11-05 02:53:12 -05:00
this . usage = ` ${ this . client . config . prefix } score <member> <type: 'hard' | 'soft'> <reporting department: ex. Library of Code sp-us | Cloud Account Services>:<reason> \ n ${ this . client . config . prefix } score hist <member> \ n ${ this . client . config . prefix } score notify <on | off> \ n ${ this . client . config . prefix } score <lock | unlock> \ n ${ this . client . config . prefix } score hist ` ;
2020-09-03 03:47:24 -04:00
this . permissions = 0 ;
2020-09-19 16:30:44 -04:00
this . guildOnly = false ;
2020-09-03 03:47:24 -04:00
this . enabled = true ;
}
2020-09-07 01:22:06 -04:00
public async run ( message : Message , args : string [ ] ) {
2020-09-03 03:47:24 -04:00
try {
2020-09-20 22:33:56 -04:00
let check = false ;
2020-09-19 16:30:44 -04:00
let user : User ;
2020-11-05 02:53:12 -05:00
if ( args [ 0 ] === 'hist' ) {
if ( ! args [ 1 ] || ! this . checkCustomPermissions ( this . client . util . resolveMember ( message . author . id , this . mainGuild ) , 4 ) ) {
user = message . author ;
if ( ! user ) return this . error ( message . channel , 'Member not found.' ) ;
const hists = await this . client . db . ScoreHistorical . find ( { userID : user.id } ) . lean ( ) . exec ( ) ;
if ( ! hists ) return this . error ( message . channel , 'No history found.' ) ;
const histArray : [ { name : string , value : string } ? ] = [ ] ;
const totalArray : number [ ] = [ ] ;
const activityArray : number [ ] = [ ] ;
const moderationArray : number [ ] = [ ] ;
const roleArray : number [ ] = [ ] ;
const cloudServicesArray : number [ ] = [ ] ;
const otherArray : number [ ] = [ ] ;
const miscArray : number [ ] = [ ] ;
2020-11-05 03:06:02 -05:00
for ( const hist of hists . reverse ( ) ) {
2020-11-05 02:53:12 -05:00
totalArray . push ( hist . report . total ) ;
activityArray . push ( hist . report . activity ) ;
moderationArray . push ( hist . report . moderation ) ;
roleArray . push ( hist . report . roles ) ;
cloudServicesArray . push ( hist . report . cloudServices ) ;
otherArray . push ( hist . report . other ) ;
miscArray . push ( hist . report . staff ) ;
let totalScore = '0' ;
let activityScore = '0' ;
let moderationScore = '0' ;
let roleScore = '0' ;
let cloudServicesScore = '0' ;
let otherScore = '0' ;
let miscScore = '0' ;
if ( hist . report . total < 200 ) totalScore = '---' ;
else if ( hist . report . total > 800 ) totalScore = '800' ;
else totalScore = ` ${ hist . report . total } ` ;
if ( hist . report . activity < 10 ) activityScore = '---' ;
else if ( hist . report . activity > Math . floor ( ( Math . log1p ( 3000 + 300 + 200 + 100 ) * 12 ) ) ) activityScore = String ( Math . floor ( ( Math . log1p ( 3000 + 300 + 200 + 100 ) * 12 ) ) ) ;
else activityScore = ` ${ hist . report . activity } ` ;
if ( hist . report . roles <= 0 ) roleScore = '---' ;
else if ( hist . report . roles > 54 ) roleScore = '54' ;
else roleScore = ` ${ hist . report . roles } ` ;
moderationScore = ` ${ hist . report . moderation } ` ;
if ( hist . report . other === 0 ) otherScore = '---' ;
else otherScore = ` ${ hist . report . other } ` ;
if ( hist . report . staff <= 0 ) miscScore = '---' ;
else miscScore = ` ${ hist . report . staff } ` ;
if ( hist . report . cloudServices === 0 ) cloudServicesScore = '---' ;
else if ( hist . report . cloudServices > 10 ) cloudServicesScore = '10' ;
else cloudServicesScore = ` ${ hist . report . cloudServices } ` ;
let data = '' ;
let hardInquiries = 0 ;
if ( hist . report ? . inquiries ? . length > 0 ) {
hist . report . inquiries . forEach ( ( inq ) = > {
const testDate = ( new Date ( new Date ( inq . date ) . setHours ( 1460 ) ) ) ;
// eslint-disable-next-line no-plusplus
if ( testDate > new Date ( ) ) hardInquiries ++ ;
} ) ;
data += ` __CommScore™:__ ${ totalScore } \ n__Activity:__ ${ activityScore } \ n__Roles:__ ${ roleScore } \ n__Moderation:__ ${ moderationScore } \ n__Cloud Services:__ ${ cloudServicesScore } \ n__Other:__ ${ otherScore } \ n__Misc:__ ${ miscScore } \ n \ n__Hard Inquiries:__ ${ hardInquiries } \ n__Soft Inquiries:__ ${ hist . report . softInquiries ? . length ? ? '0' } ` ;
histArray . push ( { name : moment ( hist . date ) . calendar ( ) , value : data } ) ;
}
}
const stat = {
totalMean : mean ( totalArray ) ,
totalMode : mode ( totalArray ) ,
totalMedian : median ( totalArray ) ,
activityMean : mean ( activityArray ) ,
rolesMean : mean ( roleArray ) ,
moderationMean : mean ( moderationArray ) ,
cloudServicesMean : mean ( cloudServicesArray ) ,
otherMean : mean ( otherArray ) ,
miscMean : mean ( miscArray ) ,
} ;
const splitHist = this . client . util . splitFields ( histArray ) ;
const cmdPages : RichEmbed [ ] = [ ] ;
splitHist . forEach ( ( split ) = > {
const embed = new RichEmbed ( ) ;
embed . setTitle ( 'Historical Community Report' ) ;
let totalMean = '0' ;
let totalMedian = '0' ;
let totalMode = '0' ;
let activityMean = '0' ;
let moderationMean = '0' ;
let roleMean = '0' ;
let cloudServicesMean = '0' ;
let otherMean = '0' ;
let miscMean = '0' ;
if ( stat . totalMean < 200 ) totalMean = '---' ;
else if ( stat . totalMean > 800 ) totalMean = '800' ;
else totalMean = ` ${ stat . totalMean } ` ;
if ( stat . totalMedian < 200 ) totalMedian = '---' ;
else if ( stat . totalMedian > 800 ) totalMedian = '800' ;
else totalMedian = ` ${ stat . totalMedian } ` ;
if ( stat . totalMode < 200 ) totalMode = '---' ;
else if ( stat . totalMode > 800 ) totalMode = '800' ;
else totalMode = ` ${ stat . totalMode } ` ;
if ( stat . activityMean < 10 ) activityMean = '---' ;
else if ( stat . activityMean > Math . floor ( ( Math . log1p ( 3000 + 300 + 200 + 100 ) * 12 ) ) ) activityMean = String ( Math . floor ( ( Math . log1p ( 3000 + 300 + 200 + 100 ) * 12 ) ) ) ;
else activityMean = ` ${ stat . activityMean } ` ;
if ( stat . rolesMean <= 0 ) roleMean = '---' ;
else if ( stat . rolesMean > 54 ) roleMean = '54' ;
else roleMean = ` ${ stat . rolesMean } ` ;
moderationMean = ` ${ stat . moderationMean } ` ;
if ( stat . otherMean === 0 ) otherMean = '---' ;
else otherMean = ` ${ stat . otherMean } ` ;
if ( stat . miscMean <= 0 ) miscMean = '---' ;
else miscMean = ` ${ stat . miscMean } ` ;
if ( stat . cloudServicesMean === 0 ) cloudServicesMean = '---' ;
else if ( stat . cloudServicesMean > 10 ) cloudServicesMean = '10' ;
else cloudServicesMean = ` ${ stat . cloudServicesMean } ` ;
embed . setDescription ( ` __**Statistical Averages**__ \ n**CommScore™ Mean:** ${ totalMean } | **CommScore™ Mode:** ${ totalMode } | **CommScore™ Median:** ${ totalMedian } \ n \ n**Activity Mean:** ${ activityMean } \ n**Roles Mean:** ${ roleMean } \ n**Moderation Mean:** ${ moderationMean } \ n**Cloud Services Mean:** ${ cloudServicesMean } \ n**Other Mean:** ${ otherMean } \ n**Misc Mean:** ${ miscMean } ` ) ;
embed . setAuthor ( user . username , user . avatarURL ) ;
embed . setThumbnail ( user . avatarURL ) ;
embed . setTimestamp ( ) ;
embed . setFooter ( this . client . user . username , this . client . user . avatarURL ) ;
split . forEach ( ( c ) = > embed . addField ( c . name , c . value ) ) ;
return cmdPages . push ( embed ) ;
} ) ;
const name = ` ${ user . username } VIA DISCORD - [HISTORICAL] ` ;
await this . client . db . Score . updateOne ( { userID : user.id } , { $addToSet : { softInquiries : { name : name.toUpperCase ( ) , date : new Date ( ) } } } ) ;
const embed2 = new RichEmbed ( ) ;
embed2 . setTitle ( 'Inquiry Notification' ) ;
embed2 . setColor ( '#00FFFF' ) ;
embed2 . addField ( 'Member' , ` ${ user . username } # ${ user . discriminator } | <@ ${ user . id } > ` , true ) ;
embed2 . addField ( 'Type' , 'SOFT' , true ) ;
embed2 . addField ( 'Department/Service' , name . toUpperCase ( ) , true ) ;
embed2 . setTimestamp ( ) ;
embed2 . setFooter ( this . client . user . username , this . client . user . avatarURL ) ;
const log = < TextChannel > this . client . guilds . get ( this . client . config . guildID ) . channels . get ( '611584771356622849' ) ;
log . createMessage ( { embed : embed2 } ) . catch ( ( ) = > { } ) ;
if ( cmdPages . length === 1 ) return message . channel . createMessage ( { embed : cmdPages [ 0 ] } ) ;
return createPaginationEmbed ( message , cmdPages ) ;
} if ( args [ 1 ] && this . checkCustomPermissions ( this . client . util . resolveMember ( message . author . id , this . mainGuild ) , 4 ) ) {
user = this . client . util . resolveMember ( args [ 1 ] , this . mainGuild ) ? . user ;
if ( ! user ) {
const sc = await this . client . db . Score . findOne ( { pin : [ Number ( args [ 0 ] . split ( '-' ) [ 0 ] ) , Number ( args [ 0 ] . split ( '-' ) [ 1 ] ) , Number ( args [ 0 ] . split ( '-' ) [ 2 ] ) ] } ) ;
user = this . client . util . resolveMember ( sc . userID , this . mainGuild ) ? . user ;
}
if ( ! user ) return this . error ( message . channel , 'Member not found.' ) ;
const hists = await this . client . db . ScoreHistorical . find ( { userID : user.id } ) . lean ( ) . exec ( ) ;
if ( ! hists ) return this . error ( message . channel , 'No history found.' ) ;
const histArray : [ { name : string , value : string } ? ] = [ ] ;
const totalArray : number [ ] = [ ] ;
const activityArray : number [ ] = [ ] ;
const moderationArray : number [ ] = [ ] ;
const roleArray : number [ ] = [ ] ;
const cloudServicesArray : number [ ] = [ ] ;
const otherArray : number [ ] = [ ] ;
const miscArray : number [ ] = [ ] ;
2020-11-05 03:06:02 -05:00
for ( const hist of hists . reverse ( ) ) {
2020-11-05 02:53:12 -05:00
totalArray . push ( hist . report . total ) ;
activityArray . push ( hist . report . activity ) ;
moderationArray . push ( hist . report . moderation ) ;
roleArray . push ( hist . report . roles ) ;
cloudServicesArray . push ( hist . report . cloudServices ) ;
otherArray . push ( hist . report . other ) ;
miscArray . push ( hist . report . staff ) ;
let totalScore = '0' ;
let activityScore = '0' ;
let moderationScore = '0' ;
let roleScore = '0' ;
let cloudServicesScore = '0' ;
let otherScore = '0' ;
let miscScore = '0' ;
if ( hist . report . total < 200 ) totalScore = '---' ;
else if ( hist . report . total > 800 ) totalScore = '800' ;
else totalScore = ` ${ hist . report . total } ` ;
if ( hist . report . activity < 10 ) activityScore = '---' ;
else if ( hist . report . activity > Math . floor ( ( Math . log1p ( 3000 + 300 + 200 + 100 ) * 12 ) ) ) activityScore = String ( Math . floor ( ( Math . log1p ( 3000 + 300 + 200 + 100 ) * 12 ) ) ) ;
else activityScore = ` ${ hist . report . activity } ` ;
if ( hist . report . roles <= 0 ) roleScore = '---' ;
else if ( hist . report . roles > 54 ) roleScore = '54' ;
else roleScore = ` ${ hist . report . roles } ` ;
moderationScore = ` ${ hist . report . moderation } ` ;
if ( hist . report . other === 0 ) otherScore = '---' ;
else otherScore = ` ${ hist . report . other } ` ;
if ( hist . report . staff <= 0 ) miscScore = '---' ;
else miscScore = ` ${ hist . report . staff } ` ;
if ( hist . report . cloudServices === 0 ) cloudServicesScore = '---' ;
else if ( hist . report . cloudServices > 10 ) cloudServicesScore = '10' ;
else cloudServicesScore = ` ${ hist . report . cloudServices } ` ;
let data = '' ;
let hardInquiries = 0 ;
if ( hist . report ? . inquiries ? . length > 0 ) {
hist . report . inquiries . forEach ( ( inq ) = > {
const testDate = ( new Date ( new Date ( inq . date ) . setHours ( 1460 ) ) ) ;
// eslint-disable-next-line no-plusplus
if ( testDate > new Date ( ) ) hardInquiries ++ ;
} ) ;
data += ` __CommScore™:__ ${ totalScore } \ n__Activity:__ ${ activityScore } \ n__Roles:__ ${ roleScore } \ n__Moderation:__ ${ moderationScore } \ n__Cloud Services:__ ${ cloudServicesScore } \ n__Other:__ ${ otherScore } \ n__Misc:__ ${ miscScore } \ n \ n__Hard Inquiries:__ ${ hardInquiries } \ n__Soft Inquiries:__ ${ hist . report . softInquiries ? . length ? ? '0' } ` ;
histArray . push ( { name : moment ( hist . date ) . calendar ( ) , value : data } ) ;
}
}
const stat = {
totalMean : mean ( totalArray ) ,
totalMode : mode ( totalArray ) ,
totalMedian : median ( totalArray ) ,
activityMean : mean ( activityArray ) ,
rolesMean : mean ( roleArray ) ,
moderationMean : mean ( moderationArray ) ,
cloudServicesMean : mean ( cloudServicesArray ) ,
otherMean : mean ( otherArray ) ,
miscMean : mean ( miscArray ) ,
} ;
const splitHist = this . client . util . splitFields ( histArray ) ;
const cmdPages : RichEmbed [ ] = [ ] ;
splitHist . forEach ( ( split ) = > {
const embed = new RichEmbed ( ) ;
embed . setTitle ( 'Historical Community Report' ) ;
let totalMean = '0' ;
let totalMedian = '0' ;
let totalMode = '0' ;
let activityMean = '0' ;
let moderationMean = '0' ;
let roleMean = '0' ;
let cloudServicesMean = '0' ;
let otherMean = '0' ;
let miscMean = '0' ;
if ( stat . totalMean < 200 ) totalMean = '---' ;
else if ( stat . totalMean > 800 ) totalMean = '800' ;
else totalMean = ` ${ stat . totalMean } ` ;
if ( stat . totalMedian < 200 ) totalMedian = '---' ;
else if ( stat . totalMedian > 800 ) totalMedian = '800' ;
else totalMedian = ` ${ stat . totalMedian } ` ;
if ( stat . totalMode < 200 ) totalMode = '---' ;
else if ( stat . totalMode > 800 ) totalMode = '800' ;
else totalMode = ` ${ stat . totalMode } ` ;
if ( stat . activityMean < 10 ) activityMean = '---' ;
else if ( stat . activityMean > Math . floor ( ( Math . log1p ( 3000 + 300 + 200 + 100 ) * 12 ) ) ) activityMean = String ( Math . floor ( ( Math . log1p ( 3000 + 300 + 200 + 100 ) * 12 ) ) ) ;
else activityMean = ` ${ stat . activityMean } ` ;
if ( stat . rolesMean <= 0 ) roleMean = '---' ;
else if ( stat . rolesMean > 54 ) roleMean = '54' ;
else roleMean = ` ${ stat . rolesMean } ` ;
moderationMean = ` ${ stat . moderationMean } ` ;
if ( stat . otherMean === 0 ) otherMean = '---' ;
else otherMean = ` ${ stat . otherMean } ` ;
if ( stat . miscMean <= 0 ) miscMean = '---' ;
else miscMean = ` ${ stat . miscMean } ` ;
if ( stat . cloudServicesMean === 0 ) cloudServicesMean = '---' ;
else if ( stat . cloudServicesMean > 10 ) cloudServicesMean = '10' ;
else cloudServicesMean = ` ${ stat . cloudServicesMean } ` ;
embed . setDescription ( ` __**Statistical Averages**__ \ n**CommScore™ Mean:** ${ totalMean } | **CommScore™ Mode:** ${ totalMode } | **CommScore™ Median:** ${ totalMedian } \ n \ n**Activity Mean:** ${ activityMean } \ n**Roles Mean:** ${ roleMean } \ n**Moderation Mean:** ${ moderationMean } \ n**Cloud Services Mean:** ${ cloudServicesMean } \ n**Other Mean:** ${ otherMean } \ n**Misc Mean:** ${ miscMean } ` ) ;
embed . setAuthor ( user . username , user . avatarURL ) ;
embed . setThumbnail ( user . avatarURL ) ;
embed . setTimestamp ( ) ;
embed . setFooter ( this . client . user . username , this . client . user . avatarURL ) ;
split . forEach ( ( c ) = > embed . addField ( c . name , c . value ) ) ;
return cmdPages . push ( embed ) ;
} ) ;
let name = '' ;
for ( const role of this . client . util . resolveMember ( message . author . id , this . mainGuild ) . roles . map ( ( r ) = > this . mainGuild . roles . get ( r ) ) . sort ( ( a , b ) = > b . position - a . position ) ) {
name = ` Library of Code sp-us | ${ role . name } - [HISTORICAL] ` ;
break ;
}
await this . client . db . Score . updateOne ( { userID : user.id } , { $addToSet : { softInquiries : { name , date : new Date ( ) } } } ) ;
const embed2 = new RichEmbed ( ) ;
embed2 . setTitle ( 'Inquiry Notification' ) ;
embed2 . setColor ( '#00FFFF' ) ;
const mem = this . client . util . resolveMember ( user . id , this . client . guilds . get ( this . client . config . guildID ) ) ;
embed2 . addField ( 'Member' , ` ${ mem . user . username } # ${ mem . user . discriminator } | <@ ${ user . id } > ` , true ) ;
embed2 . addField ( 'Type' , 'SOFT' , true ) ;
embed2 . addField ( 'Department/Service' , name . toUpperCase ( ) , true ) ;
embed2 . setTimestamp ( ) ;
embed2 . setFooter ( this . client . user . username , this . client . user . avatarURL ) ;
const log = < TextChannel > this . client . guilds . get ( this . client . config . guildID ) . channels . get ( '611584771356622849' ) ;
log . createMessage ( { embed : embed2 } ) . catch ( ( ) = > { } ) ;
if ( cmdPages . length === 1 ) return message . channel . createMessage ( { embed : cmdPages [ 0 ] } ) ;
return createPaginationEmbed ( message , cmdPages ) ;
}
}
2020-09-10 02:08:41 -04:00
if ( args [ 0 ] === 'notify' ) {
2020-09-19 16:30:44 -04:00
user = message . author ;
if ( ! user ) return this . error ( message . channel , 'Member not found.' ) ;
2020-09-10 02:08:41 -04:00
const score = await this . client . db . Score . findOne ( { userID : message.author.id } ) ;
if ( ! score ) return this . error ( message . channel , 'Score not calculated yet.' ) ;
if ( ! score . notify ) await this . client . db . Score . updateOne ( { userID : message.author.id } , { $set : { notify : false } } ) ;
switch ( args [ 1 ] ) {
case 'on' :
await this . client . db . Score . updateOne ( { userID : message.author.id } , { $set : { notify : true } } ) ;
return this . success ( message . channel , 'You will now be sent notifications whenever your score is hard-pulled.' ) ;
case 'off' :
await this . client . db . Score . updateOne ( { userID : message.author.id } , { $set : { notify : false } } ) ;
return this . success ( message . channel , 'You will no longer be sent notifications when your score is hard-pulled.' ) ;
default :
return this . error ( message . channel , 'Invalid option. Valid options are `yes` and `no`.' ) ;
2020-09-10 00:54:19 -04:00
}
2020-09-10 02:08:41 -04:00
}
2020-09-14 11:21:00 -04:00
if ( args [ 0 ] === 'lock' || args [ 0 ] === 'unlock' ) {
2020-09-19 16:30:44 -04:00
user = message . author ;
if ( ! user ) return this . error ( message . channel , 'Member not found.' ) ;
2020-09-14 11:21:00 -04:00
const score = await this . client . db . Score . findOne ( { userID : message.author.id } ) ;
if ( ! score ) return this . error ( message . channel , 'Score not calculated yet.' ) ;
if ( ! score . locked ) await this . client . db . Score . updateOne ( { userID : message.author.id } , { $set : { locked : false } } ) ;
switch ( args [ 0 ] ) {
case 'lock' :
await this . client . db . Score . updateOne ( { userID : message.author.id } , { $set : { locked : true } } ) ;
return this . success ( message . channel , 'Your report is now locked.' ) ;
case 'unlock' :
await this . client . db . Score . updateOne ( { userID : message.author.id } , { $set : { locked : false } } ) ;
return this . success ( message . channel , 'Your report is now unlocked.' ) ;
}
}
2020-10-02 21:48:53 -04:00
if ( ! args [ 0 ] || ! this . checkCustomPermissions ( this . client . util . resolveMember ( message . author . id , this . mainGuild ) , 4 ) ) {
2020-09-19 16:30:44 -04:00
user = message . author ;
if ( ! user ) return this . error ( message . channel , 'Member not found.' ) ;
2020-09-20 22:33:56 -04:00
await this . client . db . Score . updateOne ( { userID : user.id } , { $addToSet : { softInquiries : { name : ` ${ user . username } via Discord ` , date : new Date ( ) } } } ) ;
2020-10-02 18:00:05 -04:00
const embed = new RichEmbed ( ) ;
embed . setTitle ( 'Inquiry Notification' ) ;
embed . setColor ( '#00FFFF' ) ;
const mem = this . client . util . resolveMember ( user . id , this . client . guilds . get ( this . client . config . guildID ) ) ;
embed . addField ( 'Member' , ` ${ mem . user . username } # ${ mem . user . discriminator } | <@ ${ user . id } > ` , true ) ;
embed . addField ( 'Type' , 'SOFT' , true ) ;
2020-10-03 03:23:36 -04:00
embed . addField ( 'Department/Service' , ` ${ user . username } via Discord ` . toUpperCase ( ) , true ) ;
2020-10-02 18:00:05 -04:00
embed . setTimestamp ( ) ;
embed . setFooter ( this . client . user . username , this . client . user . avatarURL ) ;
const log = < TextChannel > this . client . guilds . get ( this . client . config . guildID ) . channels . get ( '611584771356622849' ) ;
log . createMessage ( { embed } ) . catch ( ( ) = > { } ) ;
2020-09-20 22:33:56 -04:00
check = true ;
2020-09-07 01:22:06 -04:00
} else {
2020-10-24 02:54:01 -04:00
user = this . client . util . resolveMember ( args [ 0 ] , this . mainGuild ) ? . user ;
2020-09-19 16:30:44 -04:00
if ( ! user ) {
const sc = await this . client . db . Score . findOne ( { pin : [ Number ( args [ 0 ] . split ( '-' ) [ 0 ] ) , Number ( args [ 0 ] . split ( '-' ) [ 1 ] ) , Number ( args [ 0 ] . split ( '-' ) [ 2 ] ) ] } ) ;
user = this . client . util . resolveMember ( sc . userID , this . mainGuild ) . user ;
}
if ( ! user ) return this . error ( message . channel , 'Member not found.' ) ;
if ( message . channel . type !== 0 ) return this . error ( message . channel , 'Hard Inquiries must be initiated in a guild.' ) ;
2020-09-07 01:22:06 -04:00
if ( args [ 1 ] === 'hard' ) {
if ( args . length < 3 ) return this . client . commands . get ( 'help' ) . run ( message , [ this . name ] ) ;
const name = args . slice ( 2 ) . join ( ' ' ) . split ( ':' ) [ 0 ] ;
const reason = args . slice ( 2 ) . join ( ' ' ) . split ( ':' ) [ 1 ] ;
2020-09-19 16:30:44 -04:00
const score = await this . client . db . Score . findOne ( { userID : user.id } ) ;
2020-09-07 01:22:06 -04:00
if ( ! score ) return this . error ( message . channel , 'Score not calculated yet.' ) ;
2020-09-14 11:21:00 -04:00
if ( score . locked ) return this . error ( message . channel , 'The score report you have requested has been locked.' ) ;
2020-10-24 02:54:01 -04:00
const reportID = uuid ( ) ;
await this . client . db . Score . updateOne ( { userID : user.id } , { $addToSet : { inquiries : { id : reportID , name , reason , date : new Date ( ) , report : score.toObject ( ) } } } ) ;
2020-10-02 18:00:05 -04:00
const embed = new RichEmbed ( ) ;
embed . setTitle ( 'Inquiry Notification' ) ;
2020-10-24 02:54:01 -04:00
embed . setDescription ( reportID ) ;
2020-10-02 18:00:05 -04:00
embed . setColor ( '#800080' ) ;
const mem = this . client . util . resolveMember ( score . userID , this . client . guilds . get ( this . client . config . guildID ) ) ;
embed . addField ( 'Member' , ` ${ mem . user . username } # ${ mem . user . discriminator } | <@ ${ score . userID } > ` , true ) ;
embed . addField ( 'Type' , 'HARD' , true ) ;
2020-10-28 21:02:03 -04:00
embed . addField ( 'Department/Service' , name . toUpperCase ( ) , true ) ;
2020-10-02 18:00:05 -04:00
embed . addField ( 'Reason' , reason ? ? 'N/A' , true ) ;
embed . setTimestamp ( ) ;
embed . setFooter ( this . client . user . username , this . client . user . avatarURL ) ;
const log = < TextChannel > this . client . guilds . get ( this . client . config . guildID ) . channels . get ( '611584771356622849' ) ;
log . createMessage ( { embed } ) . catch ( ( ) = > { } ) ;
2020-09-10 00:54:19 -04:00
if ( score . notify === true ) {
2020-09-19 16:30:44 -04:00
await this . client . getDMChannel ( user . id ) . then ( ( chan ) = > {
2020-09-10 00:54:19 -04:00
chan . createMessage ( ` __**Community Score - Hard Pull Notification**__ \ n*You have signed up to be notified whenever your hard score has been pulled. See \` ?score \` for more information.* \ n \ n**Department/Service:** ${ name . toUpperCase ( ) } ` ) ;
} ) . catch ( ( ) = > { } ) ;
}
2020-09-07 01:22:06 -04:00
}
}
2020-09-19 16:30:44 -04:00
if ( ! user ) return this . error ( message . channel , 'Member not found.' ) ;
const score = await this . client . db . Score . findOne ( { userID : user.id } ) ;
2020-09-27 02:11:26 -04:00
if ( ! score ) return this . error ( message . channel , 'Community Report has not been generated yet.' ) ;
2020-09-03 03:47:24 -04:00
let totalScore = '0' ;
let activityScore = '0' ;
let moderationScore = '0' ;
let roleScore = '0' ;
let cloudServicesScore = '0' ;
2020-09-13 23:54:37 -04:00
let otherScore = '0' ;
2020-09-03 03:47:24 -04:00
let miscScore = '0' ;
if ( score ) {
if ( score . total < 200 ) totalScore = '---' ;
else if ( score . total > 800 ) totalScore = '800' ;
else totalScore = ` ${ score . total } ` ;
2020-09-03 03:57:04 -04:00
if ( score . activity < 10 ) activityScore = '---' ;
2020-09-28 00:17:35 -04:00
else if ( score . activity > Math . floor ( ( Math . log1p ( 3000 + 300 + 200 + 100 ) * 12 ) ) ) activityScore = String ( Math . floor ( ( Math . log1p ( 3000 + 300 + 200 + 100 ) * 12 ) ) ) ;
2020-09-03 03:47:24 -04:00
else activityScore = ` ${ score . activity } ` ;
if ( score . roles <= 0 ) roleScore = '---' ;
else if ( score . roles > 54 ) roleScore = '54' ;
else roleScore = ` ${ score . roles } ` ;
moderationScore = ` ${ score . moderation } ` ;
2020-09-13 23:54:37 -04:00
if ( score . other === 0 ) otherScore = '---' ;
else otherScore = ` ${ score . other } ` ;
2020-09-03 03:47:24 -04:00
if ( score . staff <= 0 ) miscScore = '---' ;
else miscScore = ` ${ score . staff } ` ;
if ( score . cloudServices === 0 ) cloudServicesScore = '---' ;
2020-09-13 23:54:37 -04:00
else if ( score . cloudServices > 10 ) cloudServicesScore = '10' ;
2020-09-03 03:47:24 -04:00
else cloudServicesScore = ` ${ score . cloudServices } ` ;
2020-09-13 23:54:37 -04:00
} // else return this.error(message.channel, 'Community Score has not been calculated yet.');
2020-09-03 03:47:24 -04:00
2020-10-06 15:06:02 -04:00
const set = [ ] ;
const accounts = await this . client . db . Score . find ( ) . lean ( ) . exec ( ) ;
for ( const sc of accounts ) {
if ( sc . total < 200 ) { continue ; }
if ( sc . total > 800 ) { set . push ( 800 ) ; continue ; }
set . push ( sc . total ) ;
}
const percentile = this . client . util . percentile ( set , score . total ) ;
2020-09-03 03:47:24 -04:00
const embed = new RichEmbed ( ) ;
2020-10-28 21:02:03 -04:00
embed . setTitle ( 'Community Report' ) ;
2020-09-19 16:30:44 -04:00
embed . setAuthor ( user . username , user . avatarURL ) ;
embed . setThumbnail ( user . avatarURL ) ;
2020-09-13 01:09:25 -04:00
/ * f o r ( c o n s t r o l e o f m e m b e r . r o l e s . m a p ( ( r ) = > t h i s . m a i n G u i l d . r o l e s . g e t ( r ) ) . s o r t ( ( a , b ) = > b . p o s i t i o n - a . p o s i t i o n ) ) {
if ( role ? . color !== 0 ) {
embed . setColor ( role . color ) ;
break ;
}
} * /
2020-09-22 18:34:36 -04:00
if ( score ? . inquiries ? . length > 0 ) {
2020-10-28 20:46:01 -04:00
let desc = '__**Hard Inquiries**__\n*These inquiries will fall off your report within 2 months, try to keep your hard inquiries to a minimum. If you want to file a dispute, please DM Ramirez.*\n\n' ;
2020-09-07 01:22:06 -04:00
score . inquiries . forEach ( ( inq ) = > {
2020-10-28 20:46:01 -04:00
const testDate = ( new Date ( new Date ( inq . date ) . setHours ( 1460 ) ) ) ;
2020-10-11 13:16:00 -04:00
// eslint-disable-next-line no-useless-escape
2020-10-28 20:53:49 -04:00
if ( testDate > new Date ( ) ) desc += ` ${ inq . id ? ` __[ ${ inq . id } ]__ \ n ` : '' } **Department/Service:** ${ inq . name . replace ( /\*/gmi , '' ) } \ n**Reason:** ${ inq . reason } \ n**Date:** ${ inq . date . toLocaleString ( 'en-us' ) } ET \ n**Expires:** ${ moment ( testDate ) . calendar ( ) } \ n \ n ` ;
2020-09-07 01:22:06 -04:00
} ) ;
2020-10-31 02:52:22 -04:00
if ( desc . length >= 1900 ) {
2020-10-31 02:54:59 -04:00
embed . setDescription ( '__***Too many Hard Inquiries to show, please see https://report.libraryofcode.org***__' ) ;
2020-10-31 02:52:22 -04:00
} else {
embed . setDescription ( desc ) ;
}
2020-09-07 01:22:06 -04:00
}
2020-09-13 01:09:25 -04:00
let color = '🔴' ;
2020-09-19 16:30:44 -04:00
let additionalText = 'POOR' ;
2020-09-13 01:09:25 -04:00
embed . setColor ( 'FF0000' ) ;
2020-09-22 19:19:38 -04:00
if ( score . total >= 550 ) { color = '🟠' ; additionalText = 'FAIR' ; embed . setColor ( 'FFA500' ) ; }
if ( score . total >= 630 ) { color = '🟡' ; additionalText = 'GOOD' ; embed . setColor ( 'FFFF00' ) ; }
2020-09-19 16:30:44 -04:00
if ( score . total >= 700 ) { color = '🟢' ; additionalText = 'EXCELLENT' ; embed . setColor ( '66FF66' ) ; }
2020-10-02 15:43:24 -04:00
if ( score . total >= 770 ) { color = '✨' ; additionalText = 'EXCEPTIONAL' ; embed . setColor ( '#99FFFF' ) ; }
2020-10-28 21:02:03 -04:00
embed . addField ( 'CommScore™ | 200 to 800' , score ? ` ${ color } ${ totalScore } | ${ additionalText } | ${ this . client . util . ordinal ( Math . round ( percentile ) ) } Percentile ` : 'N/C' , true ) ;
2020-09-28 00:17:35 -04:00
embed . addField ( ` Activity | 10 to ${ Math . floor ( Math . log1p ( 3000 + 300 + 200 + 100 ) * 12 ) } ` , activityScore || 'N/C' , true ) ;
2020-09-13 23:54:37 -04:00
embed . addField ( 'Roles | 1 to N/A' , roleScore || 'N/C' , true ) ;
embed . addField ( 'Moderation | N/A to 2' || 'N/C' , moderationScore , true ) ;
2020-09-14 02:49:51 -04:00
embed . addField ( 'Cloud Services | N/A to 10+' , cloudServicesScore || 'N/C' , true ) ;
2020-09-13 23:54:37 -04:00
embed . addField ( 'Other' , otherScore || 'N/C' , true ) ;
embed . addField ( 'Misc' , miscScore || 'N/C' , true ) ;
2020-09-14 11:21:00 -04:00
if ( score . locked ) {
embed . addField ( 'Status' , 'Score Report Locked' ) ;
}
2020-09-19 16:30:44 -04:00
if ( score . pin ? . length > 0 && message . channel . type === 1 ) {
embed . addField ( 'PIN' , score . pin . join ( '-' ) , true ) ;
}
2020-09-13 18:58:58 -04:00
if ( score . lastUpdate ) {
embed . setFooter ( 'Report last updated' , this . client . user . avatarURL ) ;
embed . setTimestamp ( score . lastUpdate ) ;
} else {
embed . setFooter ( this . client . user . username , this . client . user . avatarURL ) ;
}
2020-09-20 15:29:25 -04:00
// eslint-disable-next-line no-mixed-operators
2020-10-02 21:48:53 -04:00
if ( ( args [ 1 ] === 'hard' || args [ 1 ] === 'soft' ) && this . checkCustomPermissions ( this . client . util . resolveMember ( message . author . id , this . mainGuild ) , 4 ) ) {
2020-09-20 15:24:33 -04:00
if ( score . pin ? . length > 0 ) embed . addField ( 'PIN' , score . pin . join ( '-' ) , true ) ;
2020-09-20 22:33:56 -04:00
if ( args [ 1 ] === 'soft' && ! check ) {
let name = '' ;
for ( const role of this . client . util . resolveMember ( message . author . id , this . mainGuild ) . roles . map ( ( r ) = > this . mainGuild . roles . get ( r ) ) . sort ( ( a , b ) = > b . position - a . position ) ) {
name = ` Library of Code sp-us | ${ role . name } ` ;
break ;
}
await this . client . db . Score . updateOne ( { userID : user.id } , { $addToSet : { softInquiries : { name , date : new Date ( ) } } } ) ;
2020-10-02 18:00:05 -04:00
const embed2 = new RichEmbed ( ) ;
embed2 . setTitle ( 'Inquiry Notification' ) ;
embed2 . setColor ( '#00FFFF' ) ;
const mem = this . client . util . resolveMember ( score . userID , this . client . guilds . get ( this . client . config . guildID ) ) ;
embed2 . addField ( 'Member' , ` ${ mem . user . username } # ${ mem . user . discriminator } | <@ ${ score . userID } > ` , true ) ;
embed2 . addField ( 'Type' , 'SOFT' , true ) ;
2020-10-03 03:23:36 -04:00
embed2 . addField ( 'Department/Service' , name . toUpperCase ( ) , true ) ;
2020-10-02 18:00:05 -04:00
embed2 . setTimestamp ( ) ;
embed2 . setFooter ( this . client . user . username , this . client . user . avatarURL ) ;
const log = < TextChannel > this . client . guilds . get ( this . client . config . guildID ) . channels . get ( '611584771356622849' ) ;
log . createMessage ( { embed : embed2 } ) . catch ( ( ) = > { } ) ;
2020-09-20 22:33:56 -04:00
}
2020-09-20 15:29:25 -04:00
}
if ( args [ 1 ] === 'hard' && this . checkCustomPermissions ( this . client . util . resolveMember ( message . author . id , this . mainGuild ) , 6 ) ) {
2020-09-17 23:07:47 -04:00
await message . channel . createMessage ( { embed } ) ;
await message . channel . createMessage ( '***===BEGIN ADDITIONAL INFORMATION===***' ) ;
2020-11-05 02:53:12 -05:00
await this . client . commands . get ( 'score' ) . run ( message , [ 'hist' , user . id ] ) ;
2020-09-19 16:30:44 -04:00
await this . client . commands . get ( 'whois' ) . run ( message , [ user . id ] ) ;
await this . client . commands . get ( 'notes' ) . run ( message , [ user . id ] ) ;
const whoisMessage = await message . channel . createMessage ( ` =whois ${ user . id } --full ` ) ;
2020-09-17 23:07:47 -04:00
await whoisMessage . delete ( ) ;
2020-09-25 20:38:16 -04:00
const modlogsMessage = await message . channel . createMessage ( ` =modlogs ${ user . id } ` ) ;
2020-09-17 23:07:47 -04:00
await modlogsMessage . delete ( ) ;
return await message . channel . createMessage ( '***===END ADDITIONAL INFORMATION===***' ) ;
}
2020-09-03 03:47:24 -04:00
return message . channel . createMessage ( { embed } ) ;
} catch ( err ) {
return this . client . util . handleError ( err , message , this ) ;
}
}
}