update scoring system to be more efficient

ctx
Matthew 2023-02-11 23:50:30 -05:00
parent 9e7e938c14
commit ff0a254eae
1 changed files with 28 additions and 1 deletions

View File

@ -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 (<TextChannel> this.client.guilds.get(this.client.config.guildID).channels.get('485680288123584525')).getMessages(2200);
const programmingSupport = await (<TextChannel> this.client.guilds.get(this.client.config.guildID).channels.get('506970598631538708')).getMessages(300);
const programmingSupport2 = await (<TextChannel> this.client.guilds.get(this.client.config.guildID).channels.get('554892820553531422')).getMessages(100);
const cloudSupport = await (<TextChannel> 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 = <TextChannel> c;
if (chan.parentID !== '701591772186411108') continue;
projectChannels.push(chan);
}
const projectMessages: Message<TextChannel>[] = [];
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() {