community-relations/src/commands/score.ts

85 lines
3.7 KiB
TypeScript
Raw Normal View History

2020-09-07 01:22:06 -04:00
import { Member, Message } 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.';
this.usage = `${this.client.config.prefix} <member> <type: 'hard' | 'soft'> <reporting department: ex. Library of Code sp-us | Cloud Account Services>:<reason>`;
2020-09-03 03:47:24 -04:00
this.permissions = 0;
this.guildOnly = true;
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-07 01:22:06 -04:00
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 });
2020-09-03 03:47:24 -04:00
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}`;
2020-09-03 03:57:04 -04:00
if (score.activity < 10) activityScore = '---';
2020-09-06 00:21:09 -04:00
else if (score.activity > Math.floor((Math.log1p(1000 + 300 + 200) * 12))) activityScore = String(Math.floor((Math.log1p(1000 + 300 + 200) * 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}`;
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}`;
2020-09-07 01:22:06 -04:00
} else return this.error(message.channel, 'Community Score has not been calculated yet.');
2020-09-03 03:47:24 -04:00
const embed = new RichEmbed();
embed.setTitle('Community Score');
2020-09-07 01:22:06 -04:00
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);
}
2020-09-03 03:47:24 -04:00
embed.addField('Total | 200 - 800', totalScore, true);
2020-09-06 00:21:09 -04:00
embed.addField(`Activity | 10 - ${Math.floor(Math.log1p(1000 + 300 + 200) * 12)}`, activityScore, true);
2020-09-03 03:47:24 -04:00
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);
}
}
}