changes/fixes

master
Matthew 2021-07-08 16:48:19 -04:00
parent f74a0fd07e
commit d7895cb8c7
No known key found for this signature in database
GPG Key ID: 210AF32ADE3B5C4B
4 changed files with 984 additions and 980 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,185 +1,193 @@
/* eslint-disable no-await-in-loop */ /* eslint-disable no-await-in-loop */
/* eslint-disable no-eval */ /* eslint-disable no-eval */
import Bull from 'bull'; import Bull from 'bull';
import cron from 'cron'; import cron from 'cron';
import { TextableChannel, TextChannel } from 'eris'; import { TextableChannel, TextChannel } from 'eris';
import { Client, RichEmbed } from '.'; import { Client, RichEmbed } from '.';
import { ScoreInterface, InqType as InquiryType } from '../models'; import { ScoreInterface, InqType as InquiryType } from '../models';
import { apply as Apply } from '../commands'; import { apply as Apply } from '../commands';
export default class Queue { export default class Queue {
public client: Client; public client: Client;
public queues: { score: Bull.Queue }; public queues: { score: Bull.Queue };
constructor(client: Client) { constructor(client: Client) {
this.client = client; this.client = client;
this.queues = { this.queues = {
score: new Bull('score', { prefix: 'queue::score' }), score: new Bull('score', { prefix: 'queue::score' }),
}; };
this.setProcessors(); this.setProcessors();
this.setCronJobs(); this.setCronJobs();
} }
protected setCronJobs() { protected setCronJobs() {
const historialCommunityReportJob = new cron.CronJob('0 20 * * *', async () => { const historialCommunityReportJob = new cron.CronJob('0 20 * * *', async () => {
try { try {
const reports = await this.client.db.Score.find().lean().exec(); const reports = await this.client.db.Score.find().lean().exec();
const startDate = new Date(); const startDate = new Date();
for (const report of reports) { for (const report of reports) {
const inqs = await this.client.db.Inquiry.find({ userID: report.userID }); const inqs = await this.client.db.Inquiry.find({ userID: report.userID });
const data = new this.client.db.ScoreHistorical({ const data = new this.client.db.ScoreHistorical({
userID: report.userID, userID: report.userID,
report, report: {
inquiries: inqs.map((inq) => inq._id), total: report.total,
date: startDate, activity: report.activity,
}); roles: report.roles,
await data.save(); moderation: report.moderation,
} cloudServices: report.cloudServices,
} catch (err) { staff: report.staff,
this.client.util.handleError(err); other: report.other,
} },
}); inquiries: inqs.map((inq) => inq._id),
date: startDate,
const clearOldHistoricalReportsJob = new cron.CronJob('0 22 * * *', async () => { });
this.client.db.ScoreHistorical.remove({ date: { $lt: new Date(Date.now() - 30 * 24 * 60 * 60 * 1000) } }); await data.save();
}); }
} catch (err) {
historialCommunityReportJob.start(); this.client.util.handleError(err);
clearOldHistoricalReportsJob.start(); }
} });
public async jobCounts() { const clearOldHistoricalReportsJob = new cron.CronJob('0 22 * * *', async () => {
const data = { this.client.db.ScoreHistorical.remove({ date: { $lt: new Date(Date.now() - 30 * 24 * 60 * 60 * 1000) } });
waiting: 0, });
active: 0,
completed: 0, historialCommunityReportJob.start();
failed: 0, clearOldHistoricalReportsJob.start();
delayed: 0, }
};
for (const entry of Object.entries(this.queues)) { public async jobCounts() {
// eslint-disable-next-line no-await-in-loop const data = {
const counts = await entry[1].getJobCounts(); waiting: 0,
data.waiting += counts.waiting; active: 0,
data.active += counts.active; completed: 0,
data.completed += counts.completed; failed: 0,
data.failed += counts.failed; delayed: 0,
data.delayed += counts.delayed; };
} for (const entry of Object.entries(this.queues)) {
return data; // eslint-disable-next-line no-await-in-loop
} const counts = await entry[1].getJobCounts();
data.waiting += counts.waiting;
protected listeners() { data.active += counts.active;
this.queues.score.on('active', (job) => { data.completed += counts.completed;
this.client.util.signale.pending(`${job.id} has become active.`); data.failed += counts.failed;
}); data.delayed += counts.delayed;
this.queues.score.on('completed', (job) => { }
this.client.util.signale.success(`Job with id ${job.id} has been completed`); return data;
}); }
this.queues.score.on('error', async (err) => {
this.client.util.handleError(err); protected listeners() {
}); this.queues.score.on('active', (job) => {
} this.client.util.signale.pending(`${job.id} has become active.`);
});
protected setProcessors() { this.queues.score.on('completed', (job) => {
this.queues.score.process('score::inquiry', async (job: Bull.Job<{ inqID: string, userID: string, name: string, type: InquiryType, reason?: string }>) => { this.client.util.signale.success(`Job with id ${job.id} has been completed`);
const member = this.client.util.resolveMember(job.data.userID, this.client.guilds.get(this.client.config.guildID)); });
const report = await this.client.db.Score.findOne({ userID: job.data.userID }).lean().exec(); this.queues.score.on('error', async (err) => {
const embed = new RichEmbed(); this.client.util.handleError(err);
if (job.data.type === InquiryType.HARD) { });
embed.setTitle('Inquiry Notification'); }
embed.setDescription(job.data.inqID);
embed.setColor('#800080'); protected setProcessors() {
embed.addField('Member', `${member.user.username}#${member.user.discriminator} | <@${job.data.userID}>`, true); this.queues.score.process('score::inquiry', async (job: Bull.Job<{ inqID: string, userID: string, name: string, type: InquiryType, reason?: string }>) => {
embed.addField('Type', 'HARD', true); const member = this.client.util.resolveMember(job.data.userID, this.client.guilds.get(this.client.config.guildID));
embed.addField('Department/Service', job.data.name.toUpperCase(), true); const report = await this.client.db.Score.findOne({ userID: job.data.userID }).lean().exec();
embed.addField('Reason', job.data.reason ?? 'N/A', true); const embed = new RichEmbed();
embed.setTimestamp(); if (job.data.type === InquiryType.HARD) {
embed.setFooter(this.client.user.username, this.client.user.avatarURL); embed.setTitle('Inquiry Notification');
if (report.notify === true) { embed.setDescription(job.data.inqID);
await this.client.getDMChannel(job.data.userID).then((chan) => { embed.setColor('#800080');
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:** ${job.data.name.toUpperCase()}`); embed.addField('Member', `${member.user.username}#${member.user.discriminator} | <@${job.data.userID}>`, true);
}).catch(() => {}); embed.addField('Type', 'HARD', true);
} embed.addField('Department/Service', job.data.name.toUpperCase(), true);
} else { embed.addField('Reason', job.data.reason ?? 'N/A', true);
embed.setTitle('Inquiry Notification'); embed.setTimestamp();
embed.setColor('#00FFFF'); embed.setFooter(this.client.user.username, this.client.user.avatarURL);
embed.addField('Member', `${member.user.username}#${member.user.discriminator} | <@${job.data.userID}>`, true); if (report.notify === true) {
embed.addField('Type', 'SOFT', true); await this.client.getDMChannel(job.data.userID).then((chan) => {
embed.addField('Department/Service', job.data.name.toUpperCase(), true); 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:** ${job.data.name.toUpperCase()}`);
embed.setTimestamp(); }).catch(() => {});
embed.setFooter(this.client.user.username, this.client.user.avatarURL); }
} } else {
const log = <TextChannel> this.client.guilds.get(this.client.config.guildID).channels.get('611584771356622849'); embed.setTitle('Inquiry Notification');
log.createMessage({ embed }).catch(() => {}); embed.setColor('#00FFFF');
}); embed.addField('Member', `${member.user.username}#${member.user.discriminator} | <@${job.data.userID}>`, true);
this.queues.score.process('score::update', async (job: Bull.Job<{ score: ScoreInterface, total: number, activity: number, roles: number, moderation: number, cloudServices: number, other: number, staff: number }>) => { embed.addField('Type', 'SOFT', true);
await this.client.db.Score.updateOne({ userID: job.data.score.userID }, { $set: { total: job.data.total, activity: job.data.activity, roles: job.data.roles, moderation: job.data.moderation, cloudServices: job.data.cloudServices, other: job.data.other, staff: job.data.staff, lastUpdate: new Date() } }); embed.addField('Department/Service', job.data.name.toUpperCase(), true);
if (!job.data.score.pin || job.data.score.pin?.length < 1) { embed.setTimestamp();
await this.client.db.Score.updateOne({ userID: job.data.score.userID }, { $set: { pin: [this.client.util.randomNumber(100, 999), this.client.util.randomNumber(10, 99), this.client.util.randomNumber(1000, 9999)] } }); embed.setFooter(this.client.user.username, this.client.user.avatarURL);
} }
}); const log = <TextChannel> this.client.guilds.get(this.client.config.guildID).channels.get('611584771356622849');
this.queues.score.process('score::apply', async (job: Bull.Job<{ channelInformation: { messageID: string, guildID: string, channelID: string }, url: string, userID: string, func?: string }>) => { log.createMessage({ embed }).catch(() => {});
const application = await Apply.apply(this.client, job.data.url, job.data.userID); });
const guild = this.client.guilds.get(job.data.channelInformation.guildID); this.queues.score.process('score::update', async (job: Bull.Job<{ score: ScoreInterface, total: number, activity: number, roles: number, moderation: number, cloudServices: number, other: number, staff: number }>) => {
const channel = <TextableChannel> guild.channels.get(job.data.channelInformation.channelID); await this.client.db.Score.updateOne({ userID: job.data.score.userID }, { $set: { total: job.data.total, activity: job.data.activity, roles: job.data.roles, moderation: job.data.moderation, cloudServices: job.data.cloudServices, other: job.data.other, staff: job.data.staff, lastUpdate: new Date() } });
const message = await channel.getMessage(job.data.channelInformation.messageID); if (!job.data.score.pin || job.data.score.pin?.length < 1) {
const member = guild.members.get(job.data.userID); await this.client.db.Score.updateOne({ userID: job.data.score.userID }, { $set: { pin: [this.client.util.randomNumber(100, 999), this.client.util.randomNumber(10, 99), this.client.util.randomNumber(1000, 9999)] } });
await message.delete(); }
const embed = new RichEmbed(); });
embed.setTitle('Application Decision'); this.queues.score.process('score::apply', async (job: Bull.Job<{ channelInformation: { messageID: string, guildID: string, channelID: string }, url: string, userID: string, func?: string }>) => {
if (member) { const application = await Apply.apply(this.client, job.data.url, job.data.userID);
embed.setAuthor(member.username, member.avatarURL); const guild = this.client.guilds.get(job.data.channelInformation.guildID);
} const channel = <TextableChannel> guild.channels.get(job.data.channelInformation.channelID);
if (application.decision === 'APPROVED') { const message = await channel.getMessage(job.data.channelInformation.messageID);
embed.setColor('#50c878'); const member = guild.members.get(job.data.userID);
} else if (application.decision === 'DECLINED') { await message.delete();
embed.setColor('#fe0000'); const embed = new RichEmbed();
} else if (application.decision === 'PRE-DECLINE') { embed.setTitle('Application Decision');
embed.setColor('#ffa500'); if (member) {
} else { embed.setAuthor(member.username, member.avatarURL);
embed.setColor('#eeeeee'); }
} if (application.decision === 'APPROVED') {
const chan = await this.client.getDMChannel(job.data.userID); embed.setColor('#50c878');
if (chan) { } else if (application.decision === 'DECLINED') {
let description = `This application was processed by __${application.processedBy}__ on behalf of the vendor, department, or service who operates this application. Please contact the vendor for further information about your application if needed.`; embed.setColor('#fe0000');
if (application.token) description += `\n\n*This document provides detailed information about the decision given to you by EDS.*: https://eds.libraryofcode.org/dec/${application.token}`; } else if (application.decision === 'PRE-DECLINE') {
embed.setDescription(description); embed.setColor('#ffa500');
embed.addField('Status', application.decision, true); } else {
embed.addField('User ID', job.data.userID, true); embed.setColor('#eeeeee');
embed.addField('Application ID', application.id, true); }
embed.addField('Job ID', job.id.toString(), true); const chan = await this.client.getDMChannel(job.data.userID);
embed.setFooter(`${this.client.user.username} via Electronic Decision Service [EDS]`, this.client.user.avatarURL); if (chan) {
embed.setTimestamp(); let description = `This application was processed by __${application.processedBy}__ on behalf of the vendor, department, or service who operates this application. Please contact the vendor for further information about your application if needed.`;
try { if (application.token) description += `\n\n*This document provides detailed information about the decision given to you by EDS.*: https://eds.libraryofcode.org/dec/${application.token}`;
await chan.createMessage({ embed }); embed.setDescription(description);
} catch { embed.addField('Status', application.decision, true);
await channel.createMessage('**We were not able to send the decision of your application to your DMs. Please contact the Staff Team for further information.**'); embed.addField('User ID', job.data.userID, true);
} embed.addField('Application ID', application.id, true);
embed.addField('Job ID', job.id.toString(), true);
await channel.createMessage({ embed: new RichEmbed().setTitle('Application Decision').setDescription('The decision of your application has been sent to your DMs.\n\n*Please view the PDF document for further information regarding the decision. For reconsiderations or questions, please contact us.*').setFooter(`${this.client.user.username} via Electronic Decision Service [EDS]`, this.client.user.avatarURL) embed.setFooter(`${this.client.user.username} via Electronic Decision Service [EDS]`, this.client.user.avatarURL);
.setTimestamp() }); embed.setTimestamp();
} else { try {
await channel.createMessage('**We were not able to send the decision of your application to your DMs. Please contact the Staff Team for further information.**'); await chan.createMessage({ embed });
} } catch {
if (job.data.func) { await channel.createMessage('**We were not able to send the decision of your application to your DMs. Please contact the Staff Team for further information.**');
const func = eval(job.data.func); }
if (application.status === 'SUCCESS' && application.decision === 'APPROVED') await func(this.client, job.data.userID);
} await channel.createMessage({ embed: new RichEmbed().setTitle('Application Decision').setDescription('The decision of your application has been sent to your DMs.\n\n*Please view the PDF document for further information regarding the decision. For reconsiderations or questions, please contact us.*').setFooter(`${this.client.user.username} via Electronic Decision Service [EDS]`, this.client.user.avatarURL)
}); .setTimestamp() });
} } else {
await channel.createMessage('**We were not able to send the decision of your application to your DMs. Please contact the Staff Team for further information.**');
public addInquiry(inqID: string, userID: string, name: string, type: InquiryType, reason?: string) { }
return this.queues.score.add('score::inquiry', { inqID, userID, name, type, reason }); if (job.data.func) {
} const func = eval(job.data.func);
if (application.status === 'SUCCESS' && application.decision === 'APPROVED') await func(this.client, job.data.userID);
public updateScore(score: ScoreInterface, total: number, activity: number, roles: number, moderation: number, cloudServices: number, other: number, staff: number) { }
return this.queues.score.add('score::update', { score, total, activity, roles, moderation, cloudServices, other, staff }); });
} }
public processApplication(channelInformation: { messageID: string, guildID: string, channelID: string }, url: string, userID: string, func?: string) { public addInquiry(inqID: string, userID: string, name: string, type: InquiryType, reason?: string) {
return this.queues.score.add('score::apply', { channelInformation, url, userID, func }); return this.queues.score.add('score::inquiry', { inqID, userID, name, type, reason });
} }
}
public updateScore(score: ScoreInterface, total: number, activity: number, roles: number, moderation: number, cloudServices: number, other: number, staff: number) {
return this.queues.score.add('score::update', { score, total, activity, roles, moderation, cloudServices, other, staff });
}
public processApplication(channelInformation: { messageID: string, guildID: string, channelID: string }, url: string, userID: string, func?: string) {
return this.queues.score.add('score::apply', { channelInformation, url, userID, func });
}
}

View File

@ -1,184 +1,185 @@
/* eslint-disable no-await-in-loop */ /* eslint-disable no-await-in-loop */
/* eslint-disable no-continue */ /* eslint-disable no-continue */
/* eslint-disable default-case */ /* eslint-disable default-case */
import moment from 'moment'; import moment from 'moment';
import { median, mode, mean } from 'mathjs'; import { median, mode, mean } from 'mathjs';
import { createPaginationEmbed } from 'eris-pagination'; import { createPaginationEmbed } from 'eris-pagination';
import { Message } from 'eris'; import { Message } from 'eris';
import { Client, Command, RichEmbed } from '../class'; import { Client, Command, RichEmbed } from '../class';
import { getTotalMessageCount } from '../intervals/score'; import { getTotalMessageCount } from '../intervals/score';
import { InquiryInterface } from '../models'; import { InquiryInterface } from '../models';
export default class Score_Hist extends Command { export default class Score_Hist extends Command {
constructor(client: Client) { constructor(client: Client) {
super(client); super(client);
this.name = 'hist'; this.name = 'hist';
this.description = 'Pulls a Community Report history for a user.'; this.description = 'Pulls a Community Report history for a user.';
this.usage = `${this.client.config.prefix}score hist <member>`; this.usage = `${this.client.config.prefix}score hist <member>`;
this.permissions = 4; this.permissions = 4;
this.guildOnly = false; this.guildOnly = false;
this.enabled = true; this.enabled = true;
} }
public async run(message: Message, args: string[]) { public async run(message: Message, args: string[]) {
try { try {
if (!args[0]) return this.client.commands.get('help').run(message, [this.name]); if (!args[0]) return this.client.commands.get('help').run(message, [this.name]);
let user = this.client.util.resolveMember(args[0], this.mainGuild)?.user; let user = this.client.util.resolveMember(args[0], this.mainGuild)?.user;
if (!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])] }); 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; user = this.client.util.resolveMember(sc.userID, this.mainGuild)?.user;
} }
if (!user) return this.error(message.channel, 'Member not found.'); const score = await this.client.db.Score.findOne({ userID: user.id }).lean().exec();
const hists = await this.client.db.ScoreHistorical.find({ userID: user.id }).limit(31).lean().exec(); if (!user) return this.error(message.channel, 'Member not found.');
if (!hists) return this.error(message.channel, 'No history found.'); const hists = await this.client.db.ScoreHistorical.find({ userID: user.id }).limit(31).lean().exec();
if (hists.length < 1) return this.error(message.channel, 'No history found.'); if (!hists) return this.error(message.channel, 'No history found.');
const histArray: [{ name: string, value: string }?] = []; if (hists.length < 1) return this.error(message.channel, 'No history found.');
const totalArray: number[] = []; const histArray: [{ name: string, value: string }?] = [];
const activityArray: number[] = []; const totalArray: number[] = [];
const moderationArray: number[] = []; const activityArray: number[] = [];
const roleArray: number[] = []; const moderationArray: number[] = [];
const cloudServicesArray: number[] = []; const roleArray: number[] = [];
const otherArray: number[] = []; const cloudServicesArray: number[] = [];
const miscArray: number[] = []; const otherArray: number[] = [];
for (const hist of hists.reverse()) { const miscArray: number[] = [];
totalArray.push(hist.report.total); for (const hist of hists.reverse()) {
activityArray.push(hist.report.activity); totalArray.push(hist.report.total);
moderationArray.push(hist.report.moderation); activityArray.push(hist.report.activity);
roleArray.push(hist.report.roles); moderationArray.push(hist.report.moderation);
cloudServicesArray.push(hist.report.cloudServices); roleArray.push(hist.report.roles);
otherArray.push(hist.report.other); cloudServicesArray.push(hist.report.cloudServices);
miscArray.push(hist.report.staff); otherArray.push(hist.report.other);
let totalScore = '0'; miscArray.push(hist.report.staff);
let activityScore = '0'; let totalScore = '0';
let moderationScore = '0'; let activityScore = '0';
let roleScore = '0'; let moderationScore = '0';
let cloudServicesScore = '0'; let roleScore = '0';
let otherScore = '0'; let cloudServicesScore = '0';
let miscScore = '0'; let otherScore = '0';
let miscScore = '0';
if (hist.report.total < 200) totalScore = '---';
else if (hist.report.total > 800) totalScore = '800'; if (hist.report.total < 200) totalScore = '---';
else totalScore = `${hist.report.total}`; 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(getTotalMessageCount(this.client)) * 12))) activityScore = String(Math.floor((Math.log1p(getTotalMessageCount(this.client)) * 12))); if (hist.report.activity < 10) activityScore = '---';
else activityScore = `${hist.report.activity}`; else if (hist.report.activity > Math.floor((Math.log1p(getTotalMessageCount(this.client)) * 12))) activityScore = String(Math.floor((Math.log1p(getTotalMessageCount(this.client)) * 12)));
else activityScore = `${hist.report.activity}`;
if (hist.report.roles <= 0) roleScore = '---';
else if (hist.report.roles > 54) roleScore = '54'; if (hist.report.roles <= 0) roleScore = '---';
else roleScore = `${hist.report.roles}`; else if (hist.report.roles > 54) roleScore = '54';
else roleScore = `${hist.report.roles}`;
moderationScore = `${hist.report.moderation}`;
moderationScore = `${hist.report.moderation}`;
if (hist.report.other === 0) otherScore = '---';
else otherScore = `${hist.report.other}`; 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.staff <= 0) miscScore = '---';
else miscScore = `${hist.report.staff}`;
if (hist.report.cloudServices === 0) cloudServicesScore = '---';
else if (hist.report.cloudServices > 10) cloudServicesScore = '10'; if (hist.report.cloudServices === 0) cloudServicesScore = '---';
else cloudServicesScore = `${hist.report.cloudServices}`; else if (hist.report.cloudServices > 10) cloudServicesScore = '10';
else cloudServicesScore = `${hist.report.cloudServices}`;
let data = '';
let hardInquiries = 0; let data = '';
const inquiries: InquiryInterface[] = []; let hardInquiries = 0;
if (hist.inquiries?.length > 0) { const inquiries: InquiryInterface[] = [];
for (const h of hist.inquiries) { if (hist.inquiries?.length > 0) {
const inq = await this.client.db.Inquiry.findOne({ _id: h }); for (const h of hist.inquiries) {
inquiries.push(inq); const inq = await this.client.db.Inquiry.findOne({ _id: h });
} inquiries.push(inq);
} }
if (inquiries?.length > 0) { }
inquiries.forEach((inq) => { if (inquiries?.length > 0) {
const testDate = (new Date(new Date(inq.date).setHours(1460))); inquiries.forEach((inq) => {
// eslint-disable-next-line no-plusplus const testDate = (new Date(new Date(inq.date).setHours(1460)));
if (testDate > new Date()) hardInquiries++; // 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 }); 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:__ ${score.softInquiries?.length ?? '0'}`;
} histArray.push({ name: moment(hist.date).calendar(), value: data });
} }
}
const stat = {
totalMean: mean(totalArray), const stat = {
totalMode: mode(totalArray), totalMean: mean(totalArray),
totalMedian: median(totalArray), totalMode: mode(totalArray),
activityMean: mean(activityArray), totalMedian: median(totalArray),
rolesMean: mean(roleArray), activityMean: mean(activityArray),
moderationMean: mean(moderationArray), rolesMean: mean(roleArray),
cloudServicesMean: mean(cloudServicesArray), moderationMean: mean(moderationArray),
otherMean: mean(otherArray), cloudServicesMean: mean(cloudServicesArray),
miscMean: mean(miscArray), otherMean: mean(otherArray),
}; miscMean: mean(miscArray),
const splitHist = this.client.util.splitFields(histArray); };
const cmdPages: RichEmbed[] = []; const splitHist = this.client.util.splitFields(histArray);
splitHist.forEach((split) => { const cmdPages: RichEmbed[] = [];
const embed = new RichEmbed(); splitHist.forEach((split) => {
embed.setTitle('Historical Community Report'); const embed = new RichEmbed();
let totalMean = '0'; embed.setTitle('Historical Community Report');
let totalMedian = '0'; let totalMean = '0';
let totalMode = '0'; let totalMedian = '0';
let activityMean = '0'; let totalMode = '0';
let moderationMean = '0'; let activityMean = '0';
let roleMean = '0'; let moderationMean = '0';
let cloudServicesMean = '0'; let roleMean = '0';
let otherMean = '0'; let cloudServicesMean = '0';
let miscMean = '0'; let otherMean = '0';
let miscMean = '0';
if (stat.totalMean < 200) totalMean = '---';
else if (stat.totalMean > 800) totalMean = '800'; if (stat.totalMean < 200) totalMean = '---';
else totalMean = `${stat.totalMean}`; else if (stat.totalMean > 800) totalMean = '800';
else totalMean = `${stat.totalMean}`;
if (stat.totalMedian < 200) totalMedian = '---';
else if (stat.totalMedian > 800) totalMedian = '800'; if (stat.totalMedian < 200) totalMedian = '---';
else totalMedian = `${stat.totalMedian}`; else if (stat.totalMedian > 800) totalMedian = '800';
else totalMedian = `${stat.totalMedian}`;
if (stat.totalMode < 200) totalMode = '---';
else if (stat.totalMode > 800) totalMode = '800'; if (stat.totalMode < 200) totalMode = '---';
else totalMode = `${stat.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(getTotalMessageCount(this.client)) * 12))) activityMean = String(Math.floor((Math.log1p(getTotalMessageCount(this.client)) * 12))); if (stat.activityMean < 10) activityMean = '---';
else activityMean = `${stat.activityMean}`; else if (stat.activityMean > Math.floor((Math.log1p(getTotalMessageCount(this.client)) * 12))) activityMean = String(Math.floor((Math.log1p(getTotalMessageCount(this.client)) * 12)));
else activityMean = `${stat.activityMean}`;
if (stat.rolesMean <= 0) roleMean = '---';
else if (stat.rolesMean > 54) roleMean = '54'; if (stat.rolesMean <= 0) roleMean = '---';
else roleMean = `${stat.rolesMean}`; else if (stat.rolesMean > 54) roleMean = '54';
else roleMean = `${stat.rolesMean}`;
moderationMean = `${stat.moderationMean}`;
moderationMean = `${stat.moderationMean}`;
if (stat.otherMean === 0) otherMean = '---';
else otherMean = `${stat.otherMean}`; if (stat.otherMean === 0) otherMean = '---';
else otherMean = `${stat.otherMean}`;
if (stat.miscMean <= 0) miscMean = '---';
else miscMean = `${stat.miscMean}`; if (stat.miscMean <= 0) miscMean = '---';
else miscMean = `${stat.miscMean}`;
if (stat.cloudServicesMean === 0) cloudServicesMean = '---';
else if (stat.cloudServicesMean > 10) cloudServicesMean = '10'; if (stat.cloudServicesMean === 0) cloudServicesMean = '---';
else cloudServicesMean = `${stat.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.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.setThumbnail(user.avatarURL); embed.setAuthor(user.username, user.avatarURL);
embed.setTimestamp(); embed.setThumbnail(user.avatarURL);
embed.setFooter(this.client.user.username, this.client.user.avatarURL); embed.setTimestamp();
split.forEach((c) => embed.addField(c.name, c.value)); embed.setFooter(this.client.user.username, this.client.user.avatarURL);
return cmdPages.push(embed); 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)) { let name = '';
name = `Library of Code sp-us | ${role.name} - [HISTORICAL]`; 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)) {
break; name = `Library of Code sp-us | ${role.name} - [HISTORICAL]`;
} break;
await this.client.report.createInquiry(user.id, name, 1); }
await this.client.report.createInquiry(user.id, name, 1);
if (cmdPages.length === 1) return message.channel.createMessage({ embed: cmdPages[0] });
return createPaginationEmbed(message, cmdPages); if (cmdPages.length === 1) return message.channel.createMessage({ embed: cmdPages[0] });
} catch (err) { return createPaginationEmbed(message, cmdPages);
return this.client.util.handleError(err, message, this); } catch (err) {
} return this.client.util.handleError(err, message, this);
} }
} }
}