diff --git a/lib/Utils.ts b/lib/Utils.ts index c2377aad..7cdf4cad 100644 --- a/lib/Utils.ts +++ b/lib/Utils.ts @@ -142,3 +142,26 @@ export async function repairUser( return user as User; } + +/** + * Intended for use in scripts + * + * @param prompt What to ask the user + * @returns The user's input + */ +export function getCommandLineInput(prompt: string) { + return new Promise((resolve) => { + const readline = require("readline").createInterface({ + input: process.stdin, + output: process.stdout, + }); + + readline.question( + prompt + " ", + (answer: string) => { + readline.close(); + resolve(answer); + }, + ); + }); +} diff --git a/scripts/repairUsers.ts b/scripts/repairUsers.ts index 708eefff..cf6db5bf 100644 --- a/scripts/repairUsers.ts +++ b/scripts/repairUsers.ts @@ -1,6 +1,6 @@ import CollectionId from "@/lib/client/CollectionId"; import { getDatabase } from "@/lib/MongoDB"; -import { repairUser } from "@/lib/Utils"; +import { getCommandLineInput, repairUser } from "@/lib/Utils"; async function repairUsers() { console.log("Getting database..."); @@ -22,6 +22,11 @@ async function repairUsers() { console.log(`Found ${users.length} incomplete users`); + if (await getCommandLineInput("Do you want to continue? (yes/no)") !== "yes") { + console.log("Exiting..."); + process.exit(0); + } + for (let i = 0; i < users.length; i++) { const user = users[i]; console.log(`Repairing user ${user._id} (${i + 1}/${users.length})`);