-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsets.js
33 lines (29 loc) · 936 Bytes
/
sets.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
'use strict';
exports.BattleSets = (client, pokemon, gen, callback) => {
if (!pokemon || !gen) return;
var options = {
gen: gen,
alias: pokemon
}
client.request.post('http://www.smogon.com/dex/_rpc/dump-Pokemon', {body:options, json:true}, (error, response, body) => {
console.log(!error && response.statusCode == 200 && body != null);
if (!error && response.statusCode == 200 && body != null){
var sets = [];
if (body.strategies.length > 0) {
for(var i = 0; i < body.strategies.length; i++ ){
if(body.strategies[i].movesets.length > 0){
for (var o = 0; o < body.strategies[i].movesets.length; o++){
sets.push(body.strategies[i].movesets[o])
}
}
}
callback(sets)
}
else {
callback({error: 'No builds found.'})
}
} else {
callback({error: 'Pokemon not found.'})
}
})
}