-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.js
104 lines (93 loc) · 3.47 KB
/
utils.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
let _ = require('lodash'),
request = require('request'),
fs = require('fs'),
config = require("./SETTINGS/config.js"),
t = {};
t.getInventory = (SID, B, callback) => {
B.getUserInventoryContents(SID, 753, 6, true, (ERR, INV, CURR) => {
if (ERR) {
callback(ERR);
} else {
INV = INV.filter((ITEM) => ITEM.getTag("item_class").internal_name == "item_class_2");
INV = INV.filter((ITEM) => ITEM.getTag("cardborder").internal_name == "cardborder_0");
var sInventory = INV;
sInventory = _.groupBy(sInventory, (CEconItem) => CEconItem['market_hash_name'].split('-')[0]);
_.forOwn(sInventory, function (CEconItemArray, appid) {
sInventory[appid] = _.groupBy(CEconItemArray, 'classid');
});
callback(null, sInventory);
}
});
};
t.maxSets = function (cardsFromSortedInventory) {
let cardCounts = _.mapValues(cardsFromSortedInventory, (cardsArray) => cardsArray.length);
cardCounts = Object.keys(cardCounts).map((key) => cardCounts[key]);
return Math.min(...cardCounts);
}
t.getCardsInSets = (callback) => {
/*request("http://cdn.steam.tools/data/set_data.json", { json: true, headers: { Referer: "http://steam.tools/cards/" } }, (ERR, RES, BODY) => {
if (!ERR && RES.statusCode == 200 && BODY) {
let c = BODY,
d = {};
if(typeof c === 'undefined'){
console.log("steam.tools API seems not working...");
process.exit();
}
for (let i = 0; i < c.sets.length; i++) {
d[c.sets[i].appid] = { appid: c.sets[i].appid, name: c.sets[i].game, count: c.sets[i].true_count };
}
callback(null, d);
} else {
callback(ERR);
}
});*/
fs.readFile("./sets.json", (ERR, DATA) => {
if (ERR) {
callback(ERR);
} else {
callback(null, JSON.parse(DATA));
}
});
};
t.getSets = (INV, DATA, callback) => {
let s = {};
_.forOwn(INV, (c, id) => {
let uc = Object.keys(c).length;
if (DATA[id.toString()] && uc == DATA[id.toString()].count) {
r = t.maxSets(c);
s[id.toString()] = [];
for (let i = 0; i < r; i++) {
let set = [];
_.forOwn(c, (e) => {
set.push(e[i]);
});
s[id.toString()].push(set);
}
} else if (!DATA[id.toString()]) {
console.log("## Card set non-existant (" + id.toString() + ")");
}
});
callback(null, s);
};
t.getBadges = (SID, callback) => {
request("http://api.steampowered.com/IPlayerService/GetBadges/v1/?key=" + config.STEAMAPIKEY + "&steamid=" + SID, {json: true}, (ERR, RES, BODY) => {
if (!ERR && RES.statusCode == 200 && BODY.response) {
let badges = BODY.response,
b = {};
//console.log(badges);
if (badges.badges) {
badges.badges.forEach(function (badge) {
if ('appid' in badge) {
b[badge.appid] = badge.level;
}
});
callback(null, b, badges.player_level, (badges.player_xp - badges.player_xp_needed_current_level));
} else {
callback(null, "nobadges")
}
} else {
callback(ERR);
}
});
};
module.exports = t;