From ff0a254eae0e4c9b58c3c4ca2b8257764320bca4 Mon Sep 17 00:00:00 2001 From: Matthew Date: Sat, 11 Feb 2023 23:50:30 -0500 Subject: [PATCH] update scoring system to be more efficient --- src/class/Queue.ts | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/class/Queue.ts b/src/class/Queue.ts index 22e31da..a9ef87e 100644 --- a/src/class/Queue.ts +++ b/src/class/Queue.ts @@ -3,10 +3,11 @@ import Bull from 'bull'; import { InqType, Score } from 'cr-db/mongodb'; import cron from 'cron'; -import { TextableChannel, TextChannel } from 'eris'; +import { Message, TextableChannel, TextChannel } from 'eris'; import { Client, RichEmbed } from '.'; import { apply as Apply } from '../commands'; +import calculateReport from '../functions/calculateReport'; export default class Queue { public client: Client; @@ -55,8 +56,34 @@ export default class Queue { this.client.db.mongo.ScoreHistorical.remove({ date: { $lt: new Date(Date.now() - 30 * 24 * 60 * 60 * 1000) } }); }); + const calculateScores = new cron.CronJob('0 * * * *', async () => { + const { members } = this.client.guilds.get(this.client.config.guildID); + + const general = await ( this.client.guilds.get(this.client.config.guildID).channels.get('485680288123584525')).getMessages(2200); + const programmingSupport = await ( this.client.guilds.get(this.client.config.guildID).channels.get('506970598631538708')).getMessages(300); + const programmingSupport2 = await ( this.client.guilds.get(this.client.config.guildID).channels.get('554892820553531422')).getMessages(100); + const cloudSupport = await ( this.client.guilds.get(this.client.config.guildID).channels.get('546457788184789013')).getMessages(200); + + const projectChannels: TextChannel[] = []; + for (const c of this.client.guilds.get(this.client.config.guildID).channels.filter((ch) => ch.type === 0)) { + const chan = c; + if (chan.parentID !== '701591772186411108') continue; + projectChannels.push(chan); + } + const projectMessages: Message[] = []; + for (const chan of projectChannels) { + const msg = await chan.getMessages(200); + projectMessages.push(...msg); + } + members.forEach(async member => { + const resolvedMember = await this.client.getRESTGuildMember(this.client.config.guildID, member.id); + calculateReport(this.client, resolvedMember, [...general, ...programmingSupport, ...programmingSupport2, ...cloudSupport, ...projectMessages]) + }) + }) + historialCommunityReportJob.start(); clearOldHistoricalReportsJob.start(); + calculateScores.start(); } public async jobCounts() {