-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
50 lines (48 loc) · 1.68 KB
/
index.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const request = require('request');
exports.getinventory = (appid, steamid, contextid, tradeable) => {
return new Promise((resolve, reject) => {
if (typeof appid !== 'number') {
appid = 730;
}
if (!contextid) {
contextid = 2;
}
if (typeof contextid === 'string') {
contextid = parseInt(contextid);
}
if (typeof tradeable !== "boolean") {
tradeable = false;
}
request({
uri: `/inventory/${steamid}/${appid}/${contextid}`,
baseUrl: 'https://steamcommunity.com/',
json: true,
}, (err, res, body) => {
if (!body) return reject(`Please provide a steamid that exists, you provided value ${steamid}`);
let items = body.descriptions;
let assets = body.assets
let marketnames = [];
let assetids = [];
let data = {
raw: body,
items: items,
marketnames: marketnames,
assets: assets,
assetids: assetids
}
if (items !== undefined) {
for (var i = 0; i < items.length; i++) {
marketnames.push(items[i].market_hash_name);
assetids.push(assets[i].assetid);
}
} else if (items === undefined) {
return reject("Couldn't find any items in the inventory of the appid you set. :(");
}
if (tradeable) {
data.items = data.items.filter((x) => x.tradable === 1);
}
if (err) return reject(err);
resolve(data);
});
})
}