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(`… solved into: ${solution}`)); const waitForEnterToBePressed = () => { const readlineInterface = createInterface({ input: process.stdin, output: process.stdout, }); return readlineInterface.question('Done. Press Enter to finish.') .then(() => readlineInterface.close()); }; client.start() .then(t => { token = t; console.log(`${playerName} has registered with token ${t}`); }) .then(() => solveNextChallenge(token)) .then(() => waitForEnterToBePressed()) .then(() => console.log('Done done!'));