-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrags.js
More file actions
executable file
·67 lines (58 loc) · 1.96 KB
/
Copy pathfrags.js
File metadata and controls
executable file
·67 lines (58 loc) · 1.96 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env node
var logger = require('./lib/logger.js')
, missing = require('./lib/missing.js')
, program = require('commander')
, types = require('./lib/types.js')
, session = require('./lib/session.js')
, wotblitz = require('wotblitz')()
program
.option('-c, --count <number>', 'number of vehicles to return', Number, 5)
.option('-t, --tiers <number>', 'filter to kills to this tier', types.numbers, [])
.option(
'-m, --mode <most|least|none>',
'get your most kills, least kills, or never killed [default: most]',
modeType,
'most'
)
.parse(process.argv)
session.load().then(sess => {
if (!sess.isLoggedIn()) throw new Error('frags: session is not logged in')
return Promise.all([
sess,
wotblitz.encyclopedia.vehicles(null, null, ['tier']).then(vehicles => missing(vehicles, ['tier'])),
wotblitz.account.info(sess.account_id, sess.token, null, ['statistics.frags'])
])
}).then(([sess, vehicles, info]) => {
var frags = info[sess.account_id].statistics.frags
var tierFilter = id => program.tiers.length === 0 || program.tiers.indexOf(vehicles[id].tier) > -1
var fields
var tankIds
switch (program.mode) {
case 'most':
tankIds = Object.keys(frags).filter(tierFilter).sort((a, b) => frags[b] - frags[a])
break
case 'least':
tankIds = Object.keys(frags).filter(tierFilter).sort((a, b) => frags[a] - frags[b])
break
case 'none':
tankIds = Object.keys(vehicles).filter(id => !(id in frags) && tierFilter(id))
break
}
tankIds = tankIds.slice(0, program.count)
fields = ['nation', 'name', 'tier']
return wotblitz.encyclopedia.vehicles(tankIds, null, fields).then(tanks => {
tanks = missing(tanks, fields, (_, id) => tankIds.indexOf(id) > -1)
return tankIds.map(id => Object.assign(tanks[id], {frags: frags[id] || 0}))
})
}).then(logger.write, logger.error)
function modeType(val) {
val = val.toLowerCase().trim()
switch (val) {
case 'most':
case 'least':
case 'none':
return val
default:
throw new Error('Invalid mode')
}
}