Skip to content

Instantly share code, notes, and snippets.

@ktilcu
Last active January 17, 2018 21:21
Show Gist options
  • Select an option

  • Save ktilcu/f0830d6c69d1f055b328db973d10fd9d to your computer and use it in GitHub Desktop.

Select an option

Save ktilcu/f0830d6c69d1f055b328db973d10fd9d to your computer and use it in GitHub Desktop.
imfearless
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