Last active
January 17, 2018 21:21
-
-
Save ktilcu/f0830d6c69d1f055b328db973d10fd9d to your computer and use it in GitHub Desktop.
imfearless
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const get = key => obj => obj[key]; | |
| const flatten = list => list.reduce((a, b) => a.concat(b), []); | |
| //https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises | |
| function queryAPI(region, realm, character) { | |
| if (region == null && realm == null && character == null) { | |
| return; // new Error or whatever | |
| } | |
| return blizzard.wow | |
| .character(['profile', 'items', 'talents', 'progression'], { | |
| origin: region, | |
| realm: realm, | |
| name: character, | |
| }) | |
| .then(get('data')) | |
| .catch(err => { | |
| console.log(err.response.data); | |
| message.channel.send(err.response.data.reason); | |
| }); | |
| } | |
| if (args[1] == 'list') { | |
| characterDB.find({owner: message.author.id}, function(err, docs) { | |
| if (err) console.log(err); | |
| // no need to do this here. Do empty checks and messaging back up the chain | |
| // if (docs == '') { | |
| // message.channel.send( | |
| // "You don't have any characters added to your account. !character add region/realm/character" | |
| // ); | |
| // return | |
| // } | |
| const {characters} = docs[0]; | |
| const data = characters.map(({region, realm, value}) => | |
| queryAPI(region, realm, name) | |
| ); | |
| return Promise.all(data).then(console.log); | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment