1
0
mirror of https://github.com/toast-ts/Daggerbot-TS.git synced 2024-11-17 04:10:59 -05:00

Add migration to UserLevelsSvc

This commit is contained in:
toast-ts 2023-12-26 04:00:17 +11:00
parent 0cff16c168
commit 6e97774cda
2 changed files with 16 additions and 3 deletions

View File

@ -71,7 +71,7 @@ export default class Rank {
.setDescription('Which member do you want to view?'))) .setDescription('Which member do you want to view?')))
.addSubcommand(x=>x .addSubcommand(x=>x
.setName('leaderboard') .setName('leaderboard')
.setDescription('View top 10 users on leaderboard')) .setDescription('View top 15 users on leaderboard'))
.addSubcommand(x=>x .addSubcommand(x=>x
.setName('notification') .setName('notification')
.setDescription('Allow the bot to ping you or not when you level up')) .setDescription('Allow the bot to ping you or not when you level up'))

View File

@ -3,7 +3,7 @@ import TClient from '../client.js';
import MessageTool from '../helpers/MessageTool.js'; import MessageTool from '../helpers/MessageTool.js';
import DatabaseServer from '../components/DatabaseServer.js'; import DatabaseServer from '../components/DatabaseServer.js';
import {Model, DataTypes} from 'sequelize'; import {Model, DataTypes} from 'sequelize';
import {writeFileSync} from 'node:fs'; import {writeFileSync, readFileSync, existsSync} from 'node:fs';
import cron from 'node-cron'; import cron from 'node-cron';
import Logger from '../helpers/Logger.js'; import Logger from '../helpers/Logger.js';
@ -104,6 +104,19 @@ export class UserLevelsSvc {
Logger.console('log', 'Cron:resetAllData', 'Job completed'); Logger.console('log', 'Cron:resetAllData', 'Job completed');
}) })
} }
algorithm = (level:number)=>level*level*18; algorithm = (level:number)=>level*level*15;
// Algorithm for determining levels. If adjusting, recommended to only change the integer at the end of equation. // Algorithm for determining levels. If adjusting, recommended to only change the integer at the end of equation.
// Deadge on 1.6k users in database...
async migrate() {
let file:string = 'src/userLevels.json';
if (!existsSync(file)) return Error(`File not found, have you tried checking if it exists? (${file})`);
await this.model.bulkCreate(JSON.parse(readFileSync(file, 'utf8')).map(x=>({
id: x._id,
messages: x.messages,
level: x.level,
pingToggle: x.notificationPing
})));
}
} }