From 80b989b9569a897e6c65060d454bef225e2b21b0 Mon Sep 17 00:00:00 2001 From: AnxietyisReal <96593068+AnxietyisReal@users.noreply.github.com> Date: Tue, 26 Dec 2023 04:00:17 +1100 Subject: [PATCH] Add migration to UserLevelsSvc --- src/commands/rank.ts | 2 +- src/models/userLevels.ts | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/commands/rank.ts b/src/commands/rank.ts index 9a80949..4062383 100644 --- a/src/commands/rank.ts +++ b/src/commands/rank.ts @@ -71,7 +71,7 @@ export default class Rank { .setDescription('Which member do you want to view?'))) .addSubcommand(x=>x .setName('leaderboard') - .setDescription('View top 10 users on leaderboard')) + .setDescription('View top 15 users on leaderboard')) .addSubcommand(x=>x .setName('notification') .setDescription('Allow the bot to ping you or not when you level up')) diff --git a/src/models/userLevels.ts b/src/models/userLevels.ts index e9023ce..0735f43 100644 --- a/src/models/userLevels.ts +++ b/src/models/userLevels.ts @@ -3,7 +3,7 @@ import TClient from '../client.js'; import MessageTool from '../helpers/MessageTool.js'; import DatabaseServer from '../components/DatabaseServer.js'; import {Model, DataTypes} from 'sequelize'; -import {writeFileSync} from 'node:fs'; +import {writeFileSync, readFileSync, existsSync} from 'node:fs'; import cron from 'node-cron'; import Logger from '../helpers/Logger.js'; @@ -104,6 +104,19 @@ export class UserLevelsSvc { 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. + + // 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 + }))); + } }