From 231fb618f6ec36b534fa211660e8870a20286ec1 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sun, 13 Sep 2020 22:20:55 -0400 Subject: [PATCH] update scoring model --- src/commands/score.ts | 12 +++++------ src/intervals/score.ts | 45 ++++++++++++++++++++++++++++++++++++++++++ types/index.d.ts | 1 + 3 files changed, 52 insertions(+), 6 deletions(-) diff --git a/src/commands/score.ts b/src/commands/score.ts index d93db39..e2bf962 100644 --- a/src/commands/score.ts +++ b/src/commands/score.ts @@ -95,7 +95,7 @@ export default class Score extends Command { let desc = '__**Hard Inquiries**__\n*These inquiries will fall off your report within 3 months, try to keep your hard inquiries to a minimum. If you want to file a dispute, please DM Ramirez.*\n\n'; score.inquiries.forEach((inq) => { const testDate = (new Date(new Date(inq.date).setHours(2190))); - if (testDate > inq.date) desc += `**Department/Service:** ${inq.name}\n**Reason:** ${inq.reason}\n**Date:** ${inq.date.toLocaleString('en-us')} ET\n\n`; + if (testDate > new Date()) desc += `**Department/Service:** ${inq.name}\n**Reason:** ${inq.reason}\n**Date:** ${inq.date.toLocaleString('en-us')} ET\n\n`; }); embed.setDescription(desc); } @@ -104,11 +104,11 @@ export default class Score extends Command { 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 - 800', `${color} ${totalScore}`, true); - embed.addField(`Activity | 10 - ${Math.floor(Math.log1p(5000 + 300 + 200 + 100) * 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('Total | 200 to 800', `${color} ${totalScore}`, true); + embed.addField(`Activity | 10 to ${Math.floor(Math.log1p(5000 + 300 + 200 + 100) * 12)}`, activityScore, true); + embed.addField('Roles | 1 to 54', roleScore, true); + embed.addField('Moderation | -50 to 2', moderationScore, true); + embed.addField('Cloud Services | N/A to 21', cloudServicesScore, true); embed.addField('Misc', miscScore, true); if (score.lastUpdate) { embed.setFooter('Report last updated', this.client.user.avatarURL); diff --git a/src/intervals/score.ts b/src/intervals/score.ts index cfce33d..38f2f2e 100644 --- a/src/intervals/score.ts +++ b/src/intervals/score.ts @@ -1,9 +1,20 @@ /* eslint-disable no-continue */ /* eslint-disable one-var-declaration-per-line */ /* eslint-disable no-await-in-loop */ +import axios from 'axios'; import { TextChannel } from 'eris'; import { Client } from '../class'; +interface CSResponse { + found: boolean, + tier: number, + totalReferrals?: number, + createdAt?: Date, + warns?: Date[], + locks?: Date[], + deletes?: Date[], +} + let interval: NodeJS.Timeout; export default async function calculateScore(client: Client): Promise { @@ -59,6 +70,40 @@ export default async function calculateScore(client: Client): Promise (Math.log1p(5000 + 300 + 200) * 12 + 100)) activity = Math.floor((Math.log1p(5000 + 300 + 200 + 100) * 12)); if (member.roles.includes('446104438969466890') || member.roles.includes('701481967149121627')) staff = 20; + const response = (await axios.get(`https://api.cloud.libraryofcode.org/wh/score?id=${member.user.id}&authorization=${client.config.internalKey}`)).data; + if (response.found === true) { + let negatives = 0; + let positives = 0; + const csCreatedTestDate = (new Date(new Date(response.createdAt).setHours(730))); + if (csCreatedTestDate > new Date()) { + negatives -= 10; + } + if (response.warns.length === 0) positives += 5; + else { + for (const warn of response.warns) { + const date = (new Date(new Date(warn).setHours(730))); + if (date > new Date()) negatives -= 2; + } + } + if (response.locks.length === 0) positives += 10; + else { + for (const lock of response.locks) { + const date = (new Date(new Date(lock).setHours(1460))); + if (date > new Date()) negatives -= 5; + } + } + 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; + } + } + 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)); + else cloudServices = Math.floor(positives * 0.61); + } + total = Math.floor(((total + activity + roles + moderation + cloudServices + staff) * 5.13) * 1.87); await score.updateOne({ $set: { total, activity, roles, moderation, cloudServices, staff, lastUpdate: new Date() } }); diff --git a/types/index.d.ts b/types/index.d.ts index 971ffc9..b9d27a7 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -6,4 +6,5 @@ export declare interface Config { emailPass: string; webhookID: string; webhookToken: string; + internalKey: string; }