diff --git a/src/class/Command.ts b/src/class/Command.ts index 47cee7f..a7cd877 100644 --- a/src/class/Command.ts +++ b/src/class/Command.ts @@ -1,4 +1,4 @@ -import { Guild, Member, Message, TextableChannel } from 'eris'; +import { Member, Message, TextableChannel } from 'eris'; import { Client } from '.'; export default class Command { @@ -82,6 +82,30 @@ export default class Command { } } + public checkCustomPermissions(member: Member, permission: number): boolean { + if (member.id === '278620217221971968' || member.id === '253600545972027394') return true; + switch (permission) { + case 0: + return true; + case 1: + return member.roles.some((r) => ['701481967149121627', '453689940140883988', '455972169449734144', '701454780828221450', '701454855952138300', '662163685439045632'].includes(r)); + case 2: + return member.roles.some((r) => ['453689940140883988', '455972169449734144', '701454780828221450', '701454855952138300', '662163685439045632'].includes(r)); + case 3: + return member.roles.some((r) => ['455972169449734144', '701454855952138300', '662163685439045632'].includes(r)); + case 4: + return member.roles.some((r) => ['701454780828221450', '701454855952138300', '662163685439045632'].includes(r)); + case 5: + return member.roles.some((r) => ['455972169449734144', '701454780828221450', '701454855952138300', '662163685439045632'].includes(r)); + case 6: + return member.roles.some((r) => ['701454855952138300', '662163685439045632'].includes(r)); + case 7: + return member.roles.includes('662163685439045632'); + default: + return false; + } + } + public error(channel: TextableChannel, text: string): Promise { return channel.createMessage(`***${this.client.util.emojis.ERROR} ${text}***`); } diff --git a/src/commands/npm.ts b/src/commands/npm.ts index 7a26301..4d88add 100644 --- a/src/commands/npm.ts +++ b/src/commands/npm.ts @@ -40,8 +40,8 @@ export default class NPM extends Command { } const name: string = data.name || 'None'; const repository: string = bugs.replace('/issues', '') || ''; - const creation: string = data.time.created ? new Date(data.time.created).toLocaleString('en') : 'None'; - const modification: string = data.time.modified ? new Date(data.time.modified).toLocaleString('en') : 'None'; + const creation: string = data?.time.created ? new Date(data.time.created).toLocaleString('en') : 'None'; + const modification: string = data?.time.modified ? new Date(data.time.modified).toLocaleString('en') : 'None'; const embed = new RichEmbed(); embed.setColor(0xCC3534); diff --git a/src/commands/score.ts b/src/commands/score.ts index 2816374..0dbdcfd 100644 --- a/src/commands/score.ts +++ b/src/commands/score.ts @@ -1,20 +1,34 @@ -import { Message } from 'eris'; +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 = 'Gets your Community Score.'; - this.usage = 'score'; + this.description = 'Pulls a hard score report for a member.'; + this.usage = `${this.client.config.prefix} :`; this.permissions = 0; this.guildOnly = true; this.enabled = true; } - public async run(message: Message) { + public async run(message: Message, args: string[]) { try { - const score = await this.client.db.Score.findOne({ userID: message.author.id }); + 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'; @@ -43,10 +57,17 @@ export default class Score extends Command { if (score.cloudServices === 0) cloudServicesScore = '---'; else if (score.cloudServices > 50) cloudServicesScore = '50'; else cloudServicesScore = `${score.cloudServices}`; - } else return this.error(message.channel, 'Your Community Score has not been calculated yet.'); + } else return this.error(message.channel, 'Community Score has not been calculated yet.'); const embed = new RichEmbed(); embed.setTitle('Community Score'); + 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); diff --git a/src/intervals/score.ts b/src/intervals/score.ts index 0571e43..ad9da23 100644 --- a/src/intervals/score.ts +++ b/src/intervals/score.ts @@ -61,7 +61,7 @@ export default async function calculateScore(client: Client): Promise