score hist fix x3

merge-requests/28/head
Matthew 2021-07-08 17:22:53 -04:00
parent da7e720a2c
commit c3d32dbc76
No known key found for this signature in database
GPG Key ID: 210AF32ADE3B5C4B
1 changed files with 12 additions and 9 deletions

View File

@ -2,10 +2,9 @@
/* eslint-disable no-continue */ /* eslint-disable no-continue */
/* eslint-disable default-case */ /* eslint-disable default-case */
import { median, mode, mean } from 'mathjs'; import { median, mode, mean } from 'mathjs';
import { Message } from 'eris'; import { Message, User } 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';
export default class Score_Hist extends Command { export default class Score_Hist extends Command {
constructor(client: Client) { constructor(client: Client) {
@ -13,18 +12,22 @@ export default class Score_Hist extends Command {
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 = 0;
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, ['score', 'hist']); let user: User;
let user = this.client.util.resolveMember(args[0], this.mainGuild)?.user; if (!this.checkCustomPermissions(message.member, 4)) user = message.author;
if (!user) { else if (!args[0]) user = message.author;
const sc = await this.client.db.Score.findOne({ pin: [Number(args[0].split('-')[0]), Number(args[0].split('-')[1]), Number(args[0].split('-')[2])] }); else {
user = this.client.util.resolveMember(sc.userID, this.mainGuild)?.user; user = this.client.util.resolveMember(args[0], 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.'); if (!user) return this.error(message.channel, 'Member not found.');
const hists = await this.client.db.ScoreHistorical.find({ userID: user.id }).lean().exec(); const hists = await this.client.db.ScoreHistorical.find({ userID: user.id }).lean().exec();
@ -114,7 +117,7 @@ export default class Score_Hist extends Command {
embed.setTitle('Historical Community Report'); embed.setTitle('Historical Community Report');
embed.setAuthor(user.username, user.avatarURL); embed.setAuthor(user.username, user.avatarURL);
embed.setThumbnail(user.avatarURL); embed.setThumbnail(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.setDescription(`__**Statistical Averages**__\n**CommScore™ Mean:** ${Number(totalMean).toFixed(2)} | **CommScore™ Mode:** ${Number(totalMode).toFixed(2)} | **CommScore™ Median:** ${Number(totalMedian).toFixed(2)}\n\n**Activity Mean:** ${Number(activityMean).toFixed(2)}\n**Roles Mean:** ${Number(roleMean).toFixed(2)}\n**Moderation Mean:** ${Number(moderationMean).toFixed(2)}\n**Cloud Services Mean:** ${Number(cloudServicesMean).toFixed(2)}\n**Other Mean:** ${Number(otherMean).toFixed(2)}\n**Misc Mean:** ${Number(miscMean).toFixed(2)}`);
embed.setFooter(this.client.user.username, this.client.user.avatarURL); embed.setFooter(this.client.user.username, this.client.user.avatarURL);
return message.channel.createMessage({ embed }); return message.channel.createMessage({ embed });