mirror of
https://github.com/toast-ts/Daggerbot-TS.git
synced 2024-11-17 00:10:58 -05:00
LevelSys self-destruction test
This commit is contained in:
parent
e97c370edf
commit
2cb7117d50
@ -32,7 +32,7 @@ export class DailyMsgsSvc {
|
|||||||
})
|
})
|
||||||
this.model.sync();
|
this.model.sync();
|
||||||
}
|
}
|
||||||
nukeDays = async()=>await this.model.destroy();
|
nukeDays = async()=>await this.model.truncate();
|
||||||
fetchDays = async()=>await this.model.findAll();
|
fetchDays = async()=>await this.model.findAll();
|
||||||
async newDay(formattedDate:number, total:number) {
|
async newDay(formattedDate:number, total:number) {
|
||||||
const [instance, created] = await this.model.findOrCreate({where: {day: formattedDate}, defaults: {total}});
|
const [instance, created] = await this.model.findOrCreate({where: {day: formattedDate}, defaults: {total}});
|
||||||
|
@ -72,10 +72,6 @@ export class UserLevelsSvc {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async getActiveUsers() {
|
|
||||||
const members = await this.model.findAll({order: [['messages', 'DESC']], limit: 5});
|
|
||||||
return members;
|
|
||||||
}
|
|
||||||
async messageIncremental(userId:string) {
|
async messageIncremental(userId:string) {
|
||||||
const data = await this.model.findByPk(userId);
|
const data = await this.model.findByPk(userId);
|
||||||
if (data && data.dataValues.isBlocked) return;
|
if (data && data.dataValues.isBlocked) return;
|
||||||
@ -110,31 +106,28 @@ export class UserLevelsSvc {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
async initSelfdestruct() {
|
async initSelfdestruct() {
|
||||||
// Every 1st of January at 11:00 (Midnight in London, Middayish in Sydney)
|
// Every 1st of January at 11:00 (London Time)
|
||||||
cron.schedule('0 11 1 1 *', async()=>{
|
cron.schedule('0 11 1 1 *', async()=>{
|
||||||
Logger.console('log', 'Cron', 'Running job "resetAllData", this is activated every 1st of January');
|
Logger.console('log', 'Cron', 'Running job "resetAllData", this is activated every 1st of January');
|
||||||
const performCountBeforeReset = await this.model.count();
|
const performCountBeforeReset = await this.model.count();
|
||||||
const topMembers = await this.getActiveUsers();
|
const topMembers = await this.model.findAll({order: [['messages', 'DESC']], limit: 5});
|
||||||
|
|
||||||
Logger.console('log', 'Cron:resetAllData', `Counted ${performCountBeforeReset.toLocaleString()} members before reset`);
|
Logger.console('log', 'Cron:resetAllData', `Counted ${performCountBeforeReset.toLocaleString()} members before reset`);
|
||||||
|
|
||||||
|
try {
|
||||||
await this.client.dailyMsgs.nukeDays();
|
await this.client.dailyMsgs.nukeDays();
|
||||||
await this.model.truncate();
|
await this.model.truncate();
|
||||||
|
|
||||||
try {
|
|
||||||
// Send notification to dcServer's logs channel after cronjob is complete.
|
// Send notification to dcServer's logs channel after cronjob is complete.
|
||||||
(this.client.channels.resolve(this.client.config.dcServer.channels.bot_log) as Discord.TextChannel).send({embeds: [new this.client.embed()
|
(this.client.channels.resolve(this.client.config.dcServer.channels.bot_log) as Discord.TextChannel).send({embeds: [new this.client.embed()
|
||||||
.setColor('#A3FFE3')
|
.setColor('#A3FFE3')
|
||||||
.setTitle('Yearly data reset has begun!')
|
.setTitle('Yearly data reset has begun!')
|
||||||
.setDescription(MessageTool.concatMessage(
|
.setDescription(MessageTool.concatMessage(
|
||||||
'I have gone ahead and reset everyone\'s rank data.',
|
'I have gone ahead and reset everyone\'s rank data.',
|
||||||
`There was ${Intl.NumberFormat('en-US').format(performCountBeforeReset)} members in database before reset.\n`,
|
`There was **${Intl.NumberFormat('en-US').format(performCountBeforeReset)}** members in database before reset.\n`,
|
||||||
'Top 5 most active members:',
|
'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`)
|
...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.debug('Cron:resetAllData', why)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reset LRSstart to current Epoch and save it to config file
|
// Reset LRSstart to current Epoch and save it to config file
|
||||||
const newEpoch = new Date().getTime();
|
const newEpoch = new Date().getTime();
|
||||||
@ -144,6 +137,9 @@ export class UserLevelsSvc {
|
|||||||
writeFileSync('src/config.json', JSON.stringify(this.client.config, null, 2));
|
writeFileSync('src/config.json', JSON.stringify(this.client.config, null, 2));
|
||||||
Logger.console('log', 'Cron:resetAllData', 'Job completed');
|
Logger.console('log', 'Cron:resetAllData', 'Job completed');
|
||||||
}
|
}
|
||||||
|
} catch (why) {
|
||||||
|
Logger.console('error', 'Cron:resetAllData', why)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
algorithm = (level:number)=>level*level*15;
|
algorithm = (level:number)=>level*level*15;
|
||||||
|
Loading…
Reference in New Issue
Block a user