|
| 1 | +import fs from "fs"; |
| 2 | +import { createUser } from "./models/userSchema"; |
| 3 | +import path from "path"; |
| 4 | + |
| 5 | +interface oldDataFormat { |
| 6 | + xp: number; |
| 7 | + userID: string; |
| 8 | + serverID: string; |
| 9 | + lastMessageTimestamp: number | null; |
| 10 | + xpTimeoutUntil: number | null; |
| 11 | + level: number | null; |
| 12 | + colorHexCode: string | null; |
| 13 | + reminders: [] | null; |
| 14 | + profileFrame: string | null; |
| 15 | + exclusiveFrames: [] | null; |
| 16 | + xpboost: object | null; |
| 17 | + other: object | null; |
| 18 | + privateVoiceID: string | null; |
| 19 | + privateVoiceThreadID: string | null; |
| 20 | + modLogs: [] | null; |
| 21 | + discordAuthToken: string | null; |
| 22 | + saveToken: string | null; |
| 23 | + hasGotMessage: boolean | null; |
| 24 | + loveMessage: boolean | null; |
| 25 | + hasCheckedInSverok: boolean | null; |
| 26 | + paryBotBeta: boolean | null; |
| 27 | + paryBotBetaKey: string | null; |
| 28 | + minecraftWhiteList: boolean | null; |
| 29 | + codeCount: number | null; |
| 30 | + votedResult: string | null; |
| 31 | + old_messages: [] | null; |
| 32 | + extraObjects: object | null; |
| 33 | + hashed_email: string | null; |
| 34 | + minecraftWhiteListConfirm: boolean | null; |
| 35 | + minecraftSecretCode: string | null; |
| 36 | + minecraftUsername: string | null; |
| 37 | + minecraftUuid: string | null; |
| 38 | +} |
| 39 | + |
| 40 | +export const moveData = () => { |
| 41 | + const oldDataPath = path.resolve("./oldData/xpsystem.profilemodels.json"); |
| 42 | + const rawOldData = fs.readFileSync(oldDataPath, "utf-8"); |
| 43 | + const oldData = JSON.parse(rawOldData) as oldDataFormat[]; |
| 44 | + let count = 0; |
| 45 | + oldData.forEach(async (oldUser) => { |
| 46 | + count++; |
| 47 | + console.log(`Processing user ${count}/${oldData.length}`); |
| 48 | + const userData = await createUser(oldUser.userID); |
| 49 | + if (!userData) return; |
| 50 | + console.log(`Migrating data for userID: ${oldUser.userID}`); |
| 51 | + userData.levelSystem.xp = oldUser.xp || 0; |
| 52 | + userData.levelSystem.level = oldUser.level || 0; |
| 53 | + userData.levelSystem.lastMessageTimestamp = |
| 54 | + oldUser.lastMessageTimestamp || Date.now(); |
| 55 | + userData.levelSystem.xpTimeoutUntil = |
| 56 | + oldUser.xpTimeoutUntil || Date.now(); |
| 57 | + |
| 58 | + userData.frameData.frameColorHexCode = |
| 59 | + oldUser.colorHexCode || "#787C75"; |
| 60 | + userData.frameData.selectedFrame = oldUser.profileFrame |
| 61 | + ? parseInt(oldUser.profileFrame) |
| 62 | + : 0; |
| 63 | + |
| 64 | + oldUser.exclusiveFrames = oldUser.exclusiveFrames || []; |
| 65 | + userData.frameData.frames = |
| 66 | + oldUser.exclusiveFrames && oldUser.exclusiveFrames.length > 0 |
| 67 | + ? userData.frameData.frames.concat( |
| 68 | + oldUser.exclusiveFrames as string[], |
| 69 | + ) |
| 70 | + : userData.frameData.frames; |
| 71 | + userData.voiceData.voiceChannelId = oldUser.privateVoiceID || null; |
| 72 | + userData.voiceData.voiceChannelThreadId = |
| 73 | + oldUser.privateVoiceThreadID || null; |
| 74 | + |
| 75 | + if (oldUser.modLogs && oldUser.modLogs.length > 0) { |
| 76 | + //eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 77 | + const modLogs = oldUser.modLogs.map((log: any) => { |
| 78 | + const newLog = { |
| 79 | + type: log.type || "unknown", |
| 80 | + userId: log.userID || "unknown", |
| 81 | + username: log.userName || "unknown", |
| 82 | + reason: log.Reason || "No reason provided", |
| 83 | + timestamp: new Date(log.date).getTime() || Date.now(), |
| 84 | + length: log.length || "permanent", |
| 85 | + authorId: log.authorID || "unknown", |
| 86 | + }; |
| 87 | + return newLog; |
| 88 | + }); |
| 89 | + userData.modLogs.push(...modLogs); |
| 90 | + } |
| 91 | + |
| 92 | + userData.minecraftData.uuid = oldUser.minecraftUuid || null; |
| 93 | + userData.minecraftData.username = oldUser.minecraftUsername || null; |
| 94 | + |
| 95 | + userData.hashedEmail = oldUser.hashed_email || null; |
| 96 | + |
| 97 | + await userData.save(); |
| 98 | + }); |
| 99 | +}; |
0 commit comments