forked from alfficcadenti/splinterlands-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.js
12 lines (10 loc) · 945 Bytes
/
user.js
1
2
3
4
5
6
7
8
9
10
11
12
const fetch = require("node-fetch");
const basicCards = require('./data/basicCards'); //phantom cards available for the players but not visible in the api endpoint
getPlayerCards = (username) => (fetch(`https://game-api.splinterlands.io/cards/collection/${username}`,
{ "credentials": "omit", "headers": { "accept": "application/json, text/javascript, */*; q=0.01" }, "referrer": `https://splinterlands.com/?p=collection&a=${username}`, "referrerPolicy": "no-referrer-when-downgrade", "body": null, "method": "GET", "mode": "cors" })
.then(x => x && x.json())
.then(x => x['cards'] ? x['cards'].filter(x=>x.delegated_to === null || x.delegated_to === username).map(card => card.card_detail_id) : '')
.then(advanced => basicCards.concat(advanced))
.catch(e => {console.log('Using only basic cards due to error when getting user collection from splinterlands: ',e); return basicCards})
)
module.exports.getPlayerCards = getPlayerCards;