From 74a32a61341e0cd0dc55351f67c46655b772660b Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sat, 19 Sep 2020 16:30:44 -0400 Subject: [PATCH] updates to scoring model (major) --- src/class/Util.ts | 4 +++ src/commands/score.ts | 62 +++++++++++++++++++++--------------- src/events/CommandHandler.ts | 2 +- src/intervals/score.ts | 11 +++++++ src/models/Score.ts | 13 ++++++++ 5 files changed, 65 insertions(+), 27 deletions(-) diff --git a/src/class/Util.ts b/src/class/Util.ts index 7df6ae9..e9914cc 100644 --- a/src/class/Util.ts +++ b/src/class/Util.ts @@ -143,4 +143,8 @@ export default class Util { const hex = int.toString(16); return '#000000'.substring(0, 7 - hex.length) + hex; } + + public randomNumber(min: number, max: number): number { + return Math.round(Math.random() * (max - min) + min); + } } diff --git a/src/commands/score.ts b/src/commands/score.ts index 590abab..2b19468 100644 --- a/src/commands/score.ts +++ b/src/commands/score.ts @@ -1,5 +1,5 @@ /* eslint-disable default-case */ -import { Member, Message } from 'eris'; +import { Message, User } from 'eris'; import { Client, Command, RichEmbed } from '../class'; export default class Score extends Command { @@ -9,16 +9,16 @@ export default class Score extends Command { this.description = 'Pulls a hard score report for a member.'; this.usage = `${this.client.config.prefix}score :\n${this.client.config.prefix}score notify \n${this.client.config.prefix}score `; this.permissions = 0; - this.guildOnly = true; + this.guildOnly = false; this.enabled = true; } public async run(message: Message, args: string[]) { try { - let member: Member; + let user: User; if (args[0] === 'notify') { - member = message.member; - if (!member) return this.error(message.channel, 'Member not found.'); + user = message.author; + if (!user) return this.error(message.channel, 'Member not found.'); const score = await this.client.db.Score.findOne({ userID: message.author.id }); if (!score) return this.error(message.channel, 'Score not calculated yet.'); if (!score.notify) await this.client.db.Score.updateOne({ userID: message.author.id }, { $set: { notify: false } }); @@ -34,8 +34,8 @@ export default class Score extends Command { } } if (args[0] === 'lock' || args[0] === 'unlock') { - member = message.member; - if (!member) return this.error(message.channel, 'Member not found.'); + user = message.author; + if (!user) return this.error(message.channel, 'Member not found.'); const score = await this.client.db.Score.findOne({ userID: message.author.id }); if (!score) return this.error(message.channel, 'Score not calculated yet.'); if (!score.locked) await this.client.db.Score.updateOne({ userID: message.author.id }, { $set: { locked: false } }); @@ -48,29 +48,34 @@ export default class Score extends Command { return this.success(message.channel, 'Your report is now unlocked.'); } } - if (!args[0] || !this.checkCustomPermissions(message.member, 6)) { - member = message.member; - if (!member) return this.error(message.channel, 'Member not found.'); + if (!args[0] || !this.checkCustomPermissions(this.client.util.resolveMember(message.author.id, this.mainGuild), 6)) { + user = message.author; + if (!user) return this.error(message.channel, 'Member not found.'); } else { - member = this.client.util.resolveMember(args[0], this.mainGuild); - if (!member) return this.error(message.channel, 'Member not found.'); + 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 (message.channel.type !== 0) return this.error(message.channel, 'Hard Inquiries must be initiated in a guild.'); 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 }); + const score = await this.client.db.Score.findOne({ userID: user.id }); if (!score) return this.error(message.channel, 'Score not calculated yet.'); if (score.locked) return this.error(message.channel, 'The score report you have requested has been locked.'); - await this.client.db.Score.updateOne({ userID: member.user.id }, { $addToSet: { inquiries: { name, reason, date: new Date() } } }); + await this.client.db.Score.updateOne({ userID: user.id }, { $addToSet: { inquiries: { name, reason, date: new Date() } } }); if (score.notify === true) { - await this.client.getDMChannel(member.user.id).then((chan) => { + await this.client.getDMChannel(user.id).then((chan) => { chan.createMessage(`__**Community Score - Hard Pull Notification**__\n*You have signed up to be notified whenever your hard score has been pulled. See \`?score\` for more information.*\n\n**Department/Service:** ${name.toUpperCase()}`); }).catch(() => {}); } } } - if (!member) return this.error(message.channel, 'Member not found.'); - const score = await this.client.db.Score.findOne({ userID: member.user.id }); + if (!user) return this.error(message.channel, 'Member not found.'); + const score = await this.client.db.Score.findOne({ userID: user.id }); let totalScore = '0'; let activityScore = '0'; let moderationScore = '0'; @@ -107,8 +112,8 @@ export default class Score extends Command { const embed = new RichEmbed(); embed.setTitle('Community Score'); - embed.setAuthor(member.user.username, member.user.avatarURL); - embed.setThumbnail(member.user.avatarURL); + embed.setAuthor(user.username, user.avatarURL); + embed.setThumbnail(user.avatarURL); /* for (const role of member.roles.map((r) => this.mainGuild.roles.get(r)).sort((a, b) => b.position - a.position)) { if (role?.color !== 0) { embed.setColor(role.color); @@ -124,11 +129,13 @@ export default class Score extends Command { embed.setDescription(desc); } let color = '🔴'; + let additionalText = 'POOR'; embed.setColor('FF0000'); - if (score.total >= 300) { color = '🟠'; embed.setColor('FFA500'); } - if (score.total >= 500) { color = '🟡'; embed.setColor('FFFF00'); } - if (score.total >= 700) { color = '🟢'; embed.setColor('66FF66'); } - embed.addField('Total | 200 to 800', `${color} ${totalScore}`, true); + if (score.total >= 300) { color = '🟠'; additionalText = 'FAIR'; embed.setColor('FFA500'); } + if (score.total >= 500) { color = '🟡'; additionalText = 'GOOD'; embed.setColor('FFFF00'); } + if (score.total >= 700) { color = '🟢'; additionalText = 'EXCELLENT'; embed.setColor('66FF66'); } + if (score.total >= 770) { color = ''; additionalText = 'EXCEPTIONAL'; embed.setColor('#99FFFF'); } + embed.addField('Total | 200 to 800', `${color} ${totalScore} | ${additionalText}`, true); embed.addField(`Activity | 10 to ${Math.floor(Math.log1p(5000 + 300 + 200 + 100) * 12)}`, activityScore || 'N/C', true); embed.addField('Roles | 1 to N/A', roleScore || 'N/C', true); embed.addField('Moderation | N/A to 2' || 'N/C', moderationScore, true); @@ -138,6 +145,9 @@ export default class Score extends Command { if (score.locked) { embed.addField('Status', 'Score Report Locked'); } + if (score.pin?.length > 0 && message.channel.type === 1) { + embed.addField('PIN', score.pin.join('-'), true); + } if (score.lastUpdate) { embed.setFooter('Report last updated', this.client.user.avatarURL); embed.setTimestamp(score.lastUpdate); @@ -147,9 +157,9 @@ export default class Score extends Command { if (args[1] === 'hard') { await message.channel.createMessage({ embed }); await message.channel.createMessage('***===BEGIN ADDITIONAL INFORMATION===***'); - await this.client.commands.get('whois').run(message, [member.id]); - await this.client.commands.get('notes').run(message, [member.id]); - const whoisMessage = await message.channel.createMessage(`=whois ${member.user.id} --full`); + await this.client.commands.get('whois').run(message, [user.id]); + await this.client.commands.get('notes').run(message, [user.id]); + const whoisMessage = await message.channel.createMessage(`=whois ${user.id} --full`); await whoisMessage.delete(); const modlogsMessage = await message.channel.createMessage(`=modlogs ${message.author.id}`); await modlogsMessage.delete(); diff --git a/src/events/CommandHandler.ts b/src/events/CommandHandler.ts index c563175..e34aeee 100644 --- a/src/events/CommandHandler.ts +++ b/src/events/CommandHandler.ts @@ -20,7 +20,7 @@ export default class CommandHandler extends Event { if (!resolved) return; if (resolved.cmd.guildOnly && !(message.channel instanceof TextChannel || message.channel instanceof NewsChannel)) return; if (!resolved.cmd.enabled) { message.channel.createMessage(`***${this.client.util.emojis.ERROR} This command has been disabled***`); return; } - if (!resolved.cmd.checkPermissions(message.member)) return; + if (!resolved.cmd.checkPermissions(this.client.util.resolveMember(message.author.id, this.client.guilds.get('446067825673633794')))) return; if ((message.channel.type === 0) && !message.channel.guild.members.get(message.author.id)) { message.channel.guild.members.add(await message.channel.guild.getRESTMember(message.author.id)); } diff --git a/src/intervals/score.ts b/src/intervals/score.ts index de6246d..9b71836 100644 --- a/src/intervals/score.ts +++ b/src/intervals/score.ts @@ -41,6 +41,12 @@ export default async function calculateScore(client: Client): Promise('Score', Score);