-
Notifications
You must be signed in to change notification settings - Fork 0
/
max-xp.js
executable file
·40 lines (34 loc) · 1.23 KB
/
max-xp.js
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
38
39
40
#!/usr/bin/env node
/**
* Example usage with prolongate call
*
* ./max-xp.js -a $(npm run prolongate | sed '/^>\s/ d' | json account_id)
*/
var logger = require('./lib/logger.js');
var wotblitz = require('wotblitz')();
var program = require('commander');
var session = require('./lib/session.js');
var findAccount = require('./lib/findAccount.js');
program
.option('-a, --account <account_id>', 'WarGaming assigned account_id', Number)
.option('-u, --username <username>', 'WarGaming account nickname')
.parse(process.argv);
var account_id_p = null
if (program.account) {
account_id_p = Promise.resolve({account_id: program.account});
} else if (program.username) {
account_id_p = findAccount(program.username);
} else {
account_id_p = session.load();
}
account_id_p
.then(({account_id}) => {
return wotblitz.tanks.stats(account_id, null, null, null, ['tank_id', 'all.max_xp'])
.then(data => data[account_id])
})
.then(stats => stats.sort((a, b) => b.all.max_xp - a.all.max_xp).slice(0, 10))
.then(top10 => {
return wotblitz.encyclopedia.vehicles(top10.map(x => x.tank_id), null, ['name', 'tier', 'nation'])
.then(vehicles => top10.map(x => Object.assign(x.all, vehicles[x.tank_id])))
})
.then(logger.write, logger.error);