From 61f358e76e94bdc43f9d1023054fb89ab2adc6fb Mon Sep 17 00:00:00 2001 From: AnxietyisReal <96593068+AnxietyisReal@users.noreply.github.com> Date: Sun, 14 Jan 2024 16:31:26 +1100 Subject: [PATCH] Add top 5 members to yearly nuke. --- src/models/userLevels.ts | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/models/userLevels.ts b/src/models/userLevels.ts index f253ffe..c40068c 100644 --- a/src/models/userLevels.ts +++ b/src/models/userLevels.ts @@ -60,6 +60,10 @@ export class UserLevelsSvc { await this.model.update({messages: updatedMessages}, {where: {id: userId}}); return (await this.model.findByPk(userId)).dataValues; } + async getActiveUsers() { + const members = (await this.model.findAll()).sort((a,b)=>b.dataValues.messages-a.dataValues.messages); + return members.slice(0, 5); + } async messageIncremental(userId:string) { const data = await this.model.findByPk(userId); if (data) { @@ -82,19 +86,27 @@ export class UserLevelsSvc { cron.schedule('0 11 1 1 *', async()=>{ Logger.console('log', 'Cron', 'Running job "resetAllData", this is activated every 1st of January'); const performCountBeforeReset = await this.model.count(); + const topMembers = await this.getActiveUsers(); + Logger.console('log', 'Cron:resetAllData', `Counted ${performCountBeforeReset.toLocaleString()} members before reset`); await this.client.dailyMsgs.nukeDays(); await this.model.drop().then(async()=>await this.model.sync()); - // Send notification to dcServer's logs channel after cronjob is complete. - (this.client.channels.resolve(this.client.config.dcServer.channels.logs) as Discord.TextChannel).send({embeds: [new this.client.embed() - .setColor('#A3FFE3') - .setTitle('Yearly data reset has begun!') - .setDescription(MessageTool.concatMessage( - 'I have gone ahead and reset everyone\'s rank data.', - `There was ${Intl.NumberFormat('en-US').format(performCountBeforeReset)} members in database before reset.` - )) - ]}); + try { + // Send notification to dcServer's logs channel after cronjob is complete. + (this.client.channels.resolve(this.client.config.dcServer.channels.logs) as Discord.TextChannel).send({embeds: [new this.client.embed() + .setColor('#A3FFE3') + .setTitle('Yearly data reset has begun!') + .setDescription(MessageTool.concatMessage( + 'I have gone ahead and reset everyone\'s rank data.', + `There was ${Intl.NumberFormat('en-US').format(performCountBeforeReset)} members in database before reset.\n`, + 'Top 5 most active members:', + ...topMembers.map((m,i)=>`${i+1}. **${(this.client.users.resolve(m.dataValues.id) ? this.client.users.resolve(m.dataValues.id).displayName : '*Unknown User*')}** - **${m.dataValues.messages.toLocaleString()}** messages`) + )) + ]}); + } catch (why) { + Logger.console('error', 'Cron:resetAllData:DEBUG', why) + } // Reset LRSstart to current Epoch and save it to config file const newEpoch = new Date().getTime();