blob: 5c080d18d0b31bbba00ce1eea6add9b6903ca8ea (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
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!'));
|