From a6291c715b8fa21f5cd37143f337d02191239425 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Mon, 14 Sep 2020 02:49:51 -0400 Subject: [PATCH] score fixes & factorizations --- src/commands/score.ts | 6 +++++- src/intervals/score.ts | 11 +++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/commands/score.ts b/src/commands/score.ts index bf84bb7..239f0f0 100644 --- a/src/commands/score.ts +++ b/src/commands/score.ts @@ -18,6 +18,7 @@ export default class Score extends Command { let member: Member; if (args[0] === 'notify') { member = message.member; + if (!member) 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 +35,10 @@ export default class Score extends Command { } if (!args[0] || !this.checkCustomPermissions(message.member, 2)) { member = message.member; + if (!member) 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.'); 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]; @@ -50,6 +53,7 @@ export default class Score extends Command { } } } + if (!member) return this.error(message.channel, 'Member not found.'); const score = await this.client.db.Score.findOne({ userID: member.user.id }); let totalScore = '0'; let activityScore = '0'; @@ -112,7 +116,7 @@ export default class Score extends Command { 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); - embed.addField('Cloud Services | N/A to 10', cloudServicesScore || 'N/C', true); + embed.addField('Cloud Services | N/A to 10+', cloudServicesScore || 'N/C', true); embed.addField('Other', otherScore || 'N/C', true); embed.addField('Misc', miscScore || 'N/C', true); if (score.lastUpdate) { diff --git a/src/intervals/score.ts b/src/intervals/score.ts index 4915f4a..cfcb6ae 100644 --- a/src/intervals/score.ts +++ b/src/intervals/score.ts @@ -76,9 +76,11 @@ export default async function calculateScore(client: Client): Promise new Date()) { - negatives -= 10; + if (response.createdAt) { + const csCreatedTestDate = (new Date(new Date(response.createdAt).setHours(730))); + if (csCreatedTestDate > new Date()) { + negatives -= 10; + } } if (response.warns.length === 0) positives += 5; else { @@ -94,12 +96,13 @@ export default async function calculateScore(client: Client): Promise new Date()) negatives -= 5; } } - if (response.deletes.length === 0) { + if (response.deletes.length > 0) { for (const del of response.deletes) { const date = (new Date(new Date(del).setHours(3650))); if (date > new Date()) negatives -= 20; } } + positives += Math.floor(response.totalReferrals * 1.17); if (response.tier === 2) positives += 2; else if (response.tier === 3) positives += 3; if (negatives < 0) cloudServices = Math.floor((negatives * 1.2) + (positives * 0.06));