diff --git a/src/commands/score_hist.ts b/src/commands/score_hist.ts index ff0cfee..7a6af68 100644 --- a/src/commands/score_hist.ts +++ b/src/commands/score_hist.ts @@ -2,10 +2,9 @@ /* eslint-disable no-continue */ /* eslint-disable default-case */ import { median, mode, mean } from 'mathjs'; -import { Message } from 'eris'; +import { Message, User } from 'eris'; import { Client, Command, RichEmbed } from '../class'; import { getTotalMessageCount } from '../intervals/score'; -import { InquiryInterface } from '../models'; export default class Score_Hist extends Command { constructor(client: Client) { @@ -13,18 +12,22 @@ export default class Score_Hist extends Command { this.name = 'hist'; this.description = 'Pulls a Community Report history for a user.'; this.usage = `${this.client.config.prefix}score hist `; - this.permissions = 4; + this.permissions = 0; this.guildOnly = false; this.enabled = true; } public async run(message: Message, args: string[]) { try { - if (!args[0]) return this.client.commands.get('help').run(message, ['score', 'hist']); - let 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; + let user: User; + if (!this.checkCustomPermissions(message.member, 4)) user = message.author; + else if (!args[0]) user = message.author; + else { + 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.'); 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.setAuthor(user.username, 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); return message.channel.createMessage({ embed });