From 298d7c82f972d4ba172f5d1e6cb3227b438fa32c Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sun, 13 Sep 2020 18:58:58 -0400 Subject: [PATCH] update score calculations --- src/commands/score.ts | 18 +++++++++++------- src/intervals/score.ts | 9 +++++---- src/models/Score.ts | 2 ++ 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/commands/score.ts b/src/commands/score.ts index 142b3a1..d93db39 100644 --- a/src/commands/score.ts +++ b/src/commands/score.ts @@ -64,7 +64,7 @@ export default class Score extends Command { else totalScore = `${score.total}`; if (score.activity < 10) activityScore = '---'; - else if (score.activity > Math.floor((Math.log1p(1000 + 300 + 200) * 12))) activityScore = String(Math.floor((Math.log1p(1000 + 300 + 200) * 12))); + else if (score.activity > Math.floor((Math.log1p(5000 + 300 + 200 + 100) * 12))) activityScore = String(Math.floor((Math.log1p(5000 + 300 + 200 + 100) * 12))); else activityScore = `${score.activity}`; if (score.roles <= 0) roleScore = '---'; @@ -101,17 +101,21 @@ export default class Score extends Command { } let color = '🔴'; embed.setColor('FF0000'); - if (score.total >= 280) { color = '🟠'; embed.setColor('FFA500'); } - if (score.total >= 490) { color = '🟡'; embed.setColor('FFFF00'); } - if (score.total >= 600) { color = '🟢'; embed.setColor('66FF66'); } + 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(1000 + 300 + 200) * 12)}`, activityScore, 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('Misc', miscScore, true); - embed.setFooter(this.client.user.username, this.client.user.avatarURL); - embed.setTimestamp(); + if (score.lastUpdate) { + embed.setFooter('Report last updated', this.client.user.avatarURL); + embed.setTimestamp(score.lastUpdate); + } else { + embed.setFooter(this.client.user.username, this.client.user.avatarURL); + } return message.channel.createMessage({ embed }); } catch (err) { return this.client.util.handleError(err, message, this); diff --git a/src/intervals/score.ts b/src/intervals/score.ts index ad9da23..cfce33d 100644 --- a/src/intervals/score.ts +++ b/src/intervals/score.ts @@ -10,7 +10,8 @@ export default async function calculateScore(client: Client): Promise { const { members } = client.guilds.get(client.config.guildID); - const general = await ( client.guilds.get(client.config.guildID).channels.get('485680288123584525')).getMessages(1000); + const general = await ( client.guilds.get(client.config.guildID).channels.get('485680288123584525')).getMessages(5000); + const media = await ( client.guilds.get(client.config.guildID).channels.get('508006539768889354')).getMessages(100); const programmingSupport = await ( client.guilds.get(client.config.guildID).channels.get('506970598631538708')).getMessages(300); const cloudSupport = await ( client.guilds.get(client.config.guildID).channels.get('546457788184789013')).getMessages(200); for (const member of members.values()) { @@ -53,14 +54,14 @@ export default async function calculateScore(client: Client): Promise 0) moderation = -moderations.length * 8; else moderation = 2; - const activityTotal = (general.filter((m) => m.member?.id === member.id).length + programmingSupport.filter((m) => m.member?.id === member.id).length + cloudSupport.filter((m) => m.member?.id === member.id).length); + const activityTotal = (general.filter((m) => m.member?.id === member.id).length + media.filter((m) => m.member?.id === member.id).length + programmingSupport.filter((m) => m.member?.id === member.id).length + cloudSupport.filter((m) => m.member?.id === member.id).length); activity = Math.floor(Math.log1p(activityTotal) * 12); - if (activity > (Math.log1p(1000 + 300 + 200) * 12)) activity = Math.floor((Math.log1p(1000 + 300 + 200) * 12)); + if (activity > (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; total = Math.floor(((total + activity + roles + moderation + cloudServices + staff) * 5.13) * 1.87); - await score.updateOne({ $set: { total, activity, roles, moderation, cloudServices, staff } }); + await score.updateOne({ $set: { total, activity, roles, moderation, cloudServices, staff, lastUpdate: new Date() } }); // client.util.signale.debug(`SCORE SET - ${member.username}\nTotal: ${total}\nActivity: ${activity}\nRoles: ${roles}\nModeration: ${moderation}\nCloud Services: ${cloudServices}\nStaff: ${staff}`); } }; diff --git a/src/models/Score.ts b/src/models/Score.ts index f325d4a..942ec5b 100644 --- a/src/models/Score.ts +++ b/src/models/Score.ts @@ -32,6 +32,7 @@ export interface ScoreInterface extends Document { staff: number, notify: boolean, inquiries: [{ name: string, reason: string, date: Date }], + lastUpdate: Date, } const Score: Schema = new Schema({ @@ -44,6 +45,7 @@ const Score: Schema = new Schema({ staff: Number, notify: Boolean, inquiries: Array, + lastUpdate: Date, }); export default model('Score', Score);