import { Member, Message } from 'eris'; import { Client, Command, RichEmbed } from '../class'; export default class Score extends Command { constructor(client: Client) { super(client); this.name = 'score'; this.description = 'Pulls a hard score report for a member.'; this.usage = `${this.client.config.prefix}score :`; this.permissions = 0; this.guildOnly = true; this.enabled = true; } public async run(message: Message, args: string[]) { try { let member: Member; if (!args[0] || !this.checkCustomPermissions(message.member, 2)) { member = message.member; } else { member = this.client.util.resolveMember(args[0], this.mainGuild); 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]; const score = await this.client.db.Score.findOne({ userID: member.user.id }); if (!score) return this.error(message.channel, 'Score not calculated yet.'); await this.client.db.Score.updateOne({ userID: member.user.id }, { $addToSet: { inquiries: { name, reason, date: new Date() } } }); } } const score = await this.client.db.Score.findOne({ userID: member.user.id }); let totalScore = '0'; let activityScore = '0'; let moderationScore = '0'; let roleScore = '0'; let cloudServicesScore = '0'; let miscScore = '0'; if (score) { if (score.total < 200) totalScore = '---'; else if (score.total > 800) totalScore = '800'; else totalScore = `${score.total}`; if (score.activity < 10) activityScore = '---'; else if (score.activity > Math.floor((Math.log1p(1000 + 300 + 200) * 12))) activityScore = String(Math.floor((Math.log1p(1000 + 300 + 200) * 12))); else activityScore = `${score.activity}`; if (score.roles <= 0) roleScore = '---'; else if (score.roles > 54) roleScore = '54'; else roleScore = `${score.roles}`; moderationScore = `${score.moderation}`; if (score.staff <= 0) miscScore = '---'; else miscScore = `${score.staff}`; if (score.cloudServices === 0) cloudServicesScore = '---'; else if (score.cloudServices > 50) cloudServicesScore = '50'; else cloudServicesScore = `${score.cloudServices}`; } else return this.error(message.channel, 'Community Score has not been calculated yet.'); const embed = new RichEmbed(); embed.setTitle('Community Score'); embed.setAuthor(member.user.username, member.user.avatarURL); if (score.inquiries?.length > 0) { let desc = ''; score.inquiries.forEach((inq) => { desc += `**Department/Service:** ${inq.name}\n**Reason:** ${inq.reason}\n**Date:** ${inq.date.toLocaleString('en-us')} ET\n`; }); embed.setDescription(desc); } embed.addField('Total | 200 - 800', totalScore, true); embed.addField(`Activity | 10 - ${Math.floor(Math.log1p(1000 + 300 + 200) * 12)}`, activityScore, true); embed.addField('Roles | 1 - 54', roleScore, true); embed.addField('Moderation | -50 - 2', moderationScore, true); embed.addField('Cloud Services | -20 - 50', cloudServicesScore, true); embed.addField('Misc', miscScore, true); embed.setFooter(this.client.user.username, this.client.user.avatarURL); embed.setTimestamp(); return message.channel.createMessage({ embed }); } catch (err) { return this.client.util.handleError(err, message, this); } } }