const { createInterface } = require('readline/promises'); const LC = require('./src/client'); const playerName = process.env.PLAYER_NAME || 'A shy user'; const client = LC.newClient({ playerName, challengerURL: process.env.CHALLENGER_URL, }); let token; const solveNextChallenge = (token) => client .nextChallenge(token) .then(challenge => console.log(`Next challenge: ${challenge}`) || challenge) .then(client.solve) .then(solution => console.log(`Posting solution: ${solution}`) || solution) .then(solution => client.postSolution(token, solution)); const waitForEnterToBePressed = () => { const readlineInterface = createInterface({ input: process.stdin, output: process.stdout, }); return readlineInterface.question(`Done. Press Enter to unregister ${playerName}.`) .then(() => readlineInterface.close()); }; client.start() .then(t => { token = t; console.log(`${playerName} has registered with token ${t}`); }) .then(() => solveNextChallenge(token)) .then(() => waitForEnterToBePressed()) .then(() => client.unregister(token)) .then(() => console.log(`${playerName} unregistered!`));