steamcommunity 3.47.0 → 3.48.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/classes/CConfirmation.js +37 -37
- package/classes/CEconItem.js +120 -120
- package/classes/CSteamSharedFile.js +221 -221
- package/classes/CSteamUser.js +225 -225
- package/components/confirmations.js +428 -428
- package/components/groups.js +798 -798
- package/components/help.js +64 -64
- package/components/helpers.js +128 -128
- package/components/http.js +150 -150
- package/components/inventoryhistory.js +173 -173
- package/components/login.js +110 -0
- package/components/market.js +387 -387
- package/components/profile.js +475 -475
- package/components/sharedfiles.js +158 -158
- package/components/twofactor.js +152 -152
- package/components/users.js +831 -831
- package/components/webapi.js +128 -25
- package/examples/disable_twofactor.js +22 -59
- package/examples/enable_twofactor.js +22 -61
- package/index.js +462 -600
- package/package.json +44 -46
- package/resources/EChatState.js +14 -14
- package/resources/EConfirmationType.js +12 -12
- package/resources/EFriendRelationship.js +23 -23
- package/resources/EPersonaState.js +23 -23
- package/resources/EPersonaStateFlag.js +32 -32
- package/resources/EResult.js +254 -254
package/components/market.js
CHANGED
|
@@ -1,387 +1,387 @@
|
|
|
1
|
-
const SteamCommunity = require('../index.js');
|
|
2
|
-
const Cheerio = require('cheerio');
|
|
3
|
-
|
|
4
|
-
const Helpers = require('./helpers.js');
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Get a list of all apps on the market
|
|
8
|
-
* @param {function} callback - First argument is null|Error, second is an object of appid => name
|
|
9
|
-
*/
|
|
10
|
-
SteamCommunity.prototype.getMarketApps = function(callback) {
|
|
11
|
-
var self = this;
|
|
12
|
-
this.httpRequest('https://steamcommunity.com/market/', function (err, response, body) {
|
|
13
|
-
if (err) {
|
|
14
|
-
callback(err);
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
var $ = Cheerio.load(body);
|
|
19
|
-
if ($('.market_search_game_button_group')) {
|
|
20
|
-
let apps = {};
|
|
21
|
-
$('.market_search_game_button_group a.game_button').each(function (i, element) {
|
|
22
|
-
var e = Cheerio.load(element);
|
|
23
|
-
var name = e('.game_button_game_name').text().trim();
|
|
24
|
-
var url = element.attribs.href;
|
|
25
|
-
var appid = url.substr(url.indexOf('=') + 1);
|
|
26
|
-
apps[appid] = name;
|
|
27
|
-
});
|
|
28
|
-
callback(null, apps);
|
|
29
|
-
} else {
|
|
30
|
-
callback(new Error("Malformed response"));
|
|
31
|
-
}
|
|
32
|
-
}, "steamcommunity");
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Check if an item is eligible to be turned into gems and if so, get its gem value
|
|
37
|
-
* @param {int} appid
|
|
38
|
-
* @param {int|string} assetid
|
|
39
|
-
* @param {function} callback
|
|
40
|
-
*/
|
|
41
|
-
SteamCommunity.prototype.getGemValue = function(appid, assetid, callback) {
|
|
42
|
-
this._myProfile({
|
|
43
|
-
"endpoint": "ajaxgetgoovalue/",
|
|
44
|
-
"qs": {
|
|
45
|
-
"sessionid": this.getSessionID(),
|
|
46
|
-
"appid": appid,
|
|
47
|
-
"contextid": 6,
|
|
48
|
-
"assetid": assetid
|
|
49
|
-
},
|
|
50
|
-
"checkHttpError": false,
|
|
51
|
-
"json": true
|
|
52
|
-
}, null, (err, res, body) => {
|
|
53
|
-
if (err) {
|
|
54
|
-
callback(err);
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (body.success && body.success != SteamCommunity.EResult.OK) {
|
|
59
|
-
let err = new Error(body.message || SteamCommunity.EResult[body.success]);
|
|
60
|
-
err.eresult = err.code = body.success;
|
|
61
|
-
callback(err);
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (!body.goo_value || !body.strTitle) {
|
|
66
|
-
callback(new Error("Malformed response"));
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
callback(null, {"promptTitle": body.strTitle, "gemValue": parseInt(body.goo_value, 10)});
|
|
71
|
-
});
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Turn an eligible item into gems.
|
|
76
|
-
* @param {int} appid
|
|
77
|
-
* @param {int|string} assetid
|
|
78
|
-
* @param {int} expectedGemsValue
|
|
79
|
-
* @param {function} callback
|
|
80
|
-
*/
|
|
81
|
-
SteamCommunity.prototype.turnItemIntoGems = function(appid, assetid, expectedGemsValue, callback) {
|
|
82
|
-
this._myProfile({
|
|
83
|
-
"endpoint": "ajaxgrindintogoo/",
|
|
84
|
-
"json": true,
|
|
85
|
-
"checkHttpError": false
|
|
86
|
-
}, {
|
|
87
|
-
"appid": appid,
|
|
88
|
-
"contextid": 6,
|
|
89
|
-
"assetid": assetid,
|
|
90
|
-
"goo_value_expected": expectedGemsValue,
|
|
91
|
-
"sessionid": this.getSessionID()
|
|
92
|
-
}, (err, res, body) => {
|
|
93
|
-
if (err) {
|
|
94
|
-
callback(err);
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (body.success && body.success != SteamCommunity.EResult.OK) {
|
|
99
|
-
let err = new Error(body.message || SteamCommunity.EResult[body.success]);
|
|
100
|
-
err.eresult = err.code = body.success;
|
|
101
|
-
callback(err);
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (!body['goo_value_received '] || !body.goo_value_total) { // lol valve
|
|
106
|
-
callback(new Error("Malformed response"));
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
callback(null, {"gemsReceived": parseInt(body['goo_value_received '], 10), "totalGems": parseInt(body.goo_value_total, 10)});
|
|
111
|
-
})
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Open a booster pack.
|
|
116
|
-
* @param {int} appid
|
|
117
|
-
* @param {int|string} assetid
|
|
118
|
-
* @param {function} callback
|
|
119
|
-
*/
|
|
120
|
-
SteamCommunity.prototype.openBoosterPack = function(appid, assetid, callback) {
|
|
121
|
-
this._myProfile({
|
|
122
|
-
"endpoint": "ajaxunpackbooster/",
|
|
123
|
-
"json": true,
|
|
124
|
-
"checkHttpError": false
|
|
125
|
-
}, {
|
|
126
|
-
"appid": appid,
|
|
127
|
-
"communityitemid": assetid,
|
|
128
|
-
"sessionid": this.getSessionID()
|
|
129
|
-
}, (err, res, body) => {
|
|
130
|
-
if (err) {
|
|
131
|
-
callback(err);
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if (body.success && body.success != SteamCommunity.EResult.OK) {
|
|
136
|
-
let err = new Error(body.message || SteamCommunity.EResult[body.success]);
|
|
137
|
-
err.eresult = err.code = body.success;
|
|
138
|
-
callback(err);
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
if (!body.rgItems) {
|
|
143
|
-
callback(new Error("Malformed response"));
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
callback(null, body.rgItems);
|
|
148
|
-
})
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Get the booster pack catalog to see what booster packs you can create
|
|
153
|
-
* @param {function} callback
|
|
154
|
-
*/
|
|
155
|
-
SteamCommunity.prototype.getBoosterPackCatalog = function(callback) {
|
|
156
|
-
this.httpRequestGet('https://steamcommunity.com/tradingcards/boostercreator/', (err, res, body) => {
|
|
157
|
-
if (err) {
|
|
158
|
-
callback(err);
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
let idx = body.indexOf('CBoosterCreatorPage.Init(');
|
|
163
|
-
if (idx == -1) {
|
|
164
|
-
callback(new Error('Malformed response'));
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
let lines = body.slice(idx).split('\n').map(l => l.trim());
|
|
169
|
-
|
|
170
|
-
for (let i = 1; i <= 4; i++) {
|
|
171
|
-
if (typeof lines[i] != 'string' || !lines[i].match(/,$/)) {
|
|
172
|
-
let err = new Error('Malformed response');
|
|
173
|
-
err.line = i;
|
|
174
|
-
callback(err);
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
lines[i] = lines[i].replace(/,$/, '');
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
let boosterPackCatalog, totalGems, tradableGems, untradableGems;
|
|
182
|
-
try {
|
|
183
|
-
boosterPackCatalog = JSON.parse(lines[1]);
|
|
184
|
-
totalGems = parseInt(lines[2].match(/\d+/)[0], 10);
|
|
185
|
-
tradableGems = parseInt(lines[3].match(/\d+/)[0], 10);
|
|
186
|
-
untradableGems = parseInt(lines[4].match(/\d+/)[0], 10);
|
|
187
|
-
} catch (ex) {
|
|
188
|
-
let err = new Error('Malformed response');
|
|
189
|
-
err.inner = ex;
|
|
190
|
-
callback(err);
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
let keyedCatalog = {};
|
|
195
|
-
boosterPackCatalog.forEach((app) => {
|
|
196
|
-
app.price = parseInt(app.price, 10);
|
|
197
|
-
app.unavailable = app.unavailable || false;
|
|
198
|
-
app.availableAtTime = app.available_at_time || null;
|
|
199
|
-
|
|
200
|
-
if (typeof app.availableAtTime == 'string') {
|
|
201
|
-
app.availableAtTime = Helpers.decodeSteamTime(app.availableAtTime);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
delete app.available_at_time;
|
|
205
|
-
|
|
206
|
-
keyedCatalog[app.appid] = app;
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
callback(null, {
|
|
210
|
-
totalGems,
|
|
211
|
-
tradableGems,
|
|
212
|
-
untradableGems,
|
|
213
|
-
catalog: keyedCatalog
|
|
214
|
-
});
|
|
215
|
-
});
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* Create a booster pack using gems.
|
|
220
|
-
* @param {int} appid
|
|
221
|
-
* @param {boolean} [useUntradableGems=false]
|
|
222
|
-
* @param callback
|
|
223
|
-
*/
|
|
224
|
-
SteamCommunity.prototype.createBoosterPack = function(appid, useUntradableGems, callback) {
|
|
225
|
-
if (typeof useUntradableGems == 'function') {
|
|
226
|
-
callback = useUntradableGems;
|
|
227
|
-
useUntradableGems = false;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
this.httpRequestPost({
|
|
231
|
-
uri: 'https://steamcommunity.com/tradingcards/ajaxcreatebooster/',
|
|
232
|
-
form: {
|
|
233
|
-
sessionid: this.getSessionID(),
|
|
234
|
-
appid,
|
|
235
|
-
series: 1,
|
|
236
|
-
// tradability_preference can be a value 1-3
|
|
237
|
-
// 1: Prefer using tradable gems, but use untradable if necessary
|
|
238
|
-
// 2: Only use tradable gems
|
|
239
|
-
// 3: Prefer using untradable gems, but use tradable if necessary
|
|
240
|
-
tradability_preference: useUntradableGems ? 3 : 2
|
|
241
|
-
},
|
|
242
|
-
json: true,
|
|
243
|
-
checkHttpError: false
|
|
244
|
-
}, (err, res, body) => {
|
|
245
|
-
if (err) {
|
|
246
|
-
callback(err);
|
|
247
|
-
return;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
if (body.purchase_eresult && body.purchase_eresult != 1) {
|
|
251
|
-
callback(Helpers.eresultError(body.purchase_eresult));
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
// We can now check HTTP status codes
|
|
256
|
-
if (this._checkHttpError(err, res, callback, body)) {
|
|
257
|
-
return;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
callback(null, {
|
|
261
|
-
totalGems: parseInt(body.goo_amount, 10),
|
|
262
|
-
tradableGems: parseInt(body.tradable_goo_amount, 10),
|
|
263
|
-
untradableGems: parseInt(body.untradable_goo_amount, 10),
|
|
264
|
-
resultItem: body.purchase_result
|
|
265
|
-
});
|
|
266
|
-
});
|
|
267
|
-
};
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* Get details about a gift in your inventory.
|
|
271
|
-
* @param {string} giftID
|
|
272
|
-
* @param {function} callback
|
|
273
|
-
*/
|
|
274
|
-
SteamCommunity.prototype.getGiftDetails = function(giftID, callback) {
|
|
275
|
-
this.httpRequestPost({
|
|
276
|
-
"uri": "https://steamcommunity.com/gifts/" + giftID + "/validateunpack",
|
|
277
|
-
"form": {
|
|
278
|
-
"sessionid": this.getSessionID()
|
|
279
|
-
},
|
|
280
|
-
"json": true
|
|
281
|
-
}, (err, res, body) => {
|
|
282
|
-
if (err) {
|
|
283
|
-
callback(err);
|
|
284
|
-
return;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
if (body.success && body.success != SteamCommunity.EResult.OK) {
|
|
288
|
-
let err = new Error(body.message || SteamCommunity.EResult[body.success]);
|
|
289
|
-
err.eresult = err.code = body.success;
|
|
290
|
-
callback(err);
|
|
291
|
-
return;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
if (!body.packageid || !body.gift_name) {
|
|
295
|
-
callback(new Error("Malformed response"));
|
|
296
|
-
return;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
callback(null, {
|
|
300
|
-
"giftName": body.gift_name,
|
|
301
|
-
"packageID": parseInt(body.packageid, 10),
|
|
302
|
-
"owned": body.owned
|
|
303
|
-
});
|
|
304
|
-
});
|
|
305
|
-
};
|
|
306
|
-
|
|
307
|
-
/**
|
|
308
|
-
* Unpack a gift in your inventory to your library.
|
|
309
|
-
* @param {string} giftID
|
|
310
|
-
* @param {function} callback
|
|
311
|
-
*/
|
|
312
|
-
SteamCommunity.prototype.redeemGift = function(giftID, callback) {
|
|
313
|
-
this.httpRequestPost({
|
|
314
|
-
"uri": "https://steamcommunity.com/gifts/" + giftID + "/unpack",
|
|
315
|
-
"form": {
|
|
316
|
-
"sessionid": this.getSessionID()
|
|
317
|
-
},
|
|
318
|
-
"json": true
|
|
319
|
-
}, (err, res, body) => {
|
|
320
|
-
if (err) {
|
|
321
|
-
callback(err);
|
|
322
|
-
return;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
if (body.success && body.success != SteamCommunity.EResult.OK) {
|
|
326
|
-
|
|
327
|
-
let err = new Error(body.message || SteamCommunity.EResult[body.success]);
|
|
328
|
-
err.eresult = err.code = body.success;
|
|
329
|
-
callback(err);
|
|
330
|
-
return;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
callback(null);
|
|
334
|
-
});
|
|
335
|
-
};
|
|
336
|
-
|
|
337
|
-
/**
|
|
338
|
-
* @param {int|string} assetid
|
|
339
|
-
* @param {int} denominationIn
|
|
340
|
-
* @param {int} denominationOut
|
|
341
|
-
* @param {int} quantityIn
|
|
342
|
-
* @param {int} quantityOut
|
|
343
|
-
* @param {function} callback
|
|
344
|
-
* @private
|
|
345
|
-
*/
|
|
346
|
-
SteamCommunity.prototype._gemExchange = function(assetid, denominationIn, denominationOut, quantityIn, quantityOut, callback) {
|
|
347
|
-
this._myProfile({
|
|
348
|
-
endpoint: 'ajaxexchangegoo/',
|
|
349
|
-
json: true,
|
|
350
|
-
checkHttpError: false
|
|
351
|
-
}, {
|
|
352
|
-
appid: 753,
|
|
353
|
-
assetid,
|
|
354
|
-
goo_denomination_in: denominationIn,
|
|
355
|
-
goo_amount_in: quantityIn,
|
|
356
|
-
goo_denomination_out: denominationOut,
|
|
357
|
-
goo_amount_out_expected: quantityOut,
|
|
358
|
-
sessionid: this.getSessionID()
|
|
359
|
-
}, (err, res, body) => {
|
|
360
|
-
if (err) {
|
|
361
|
-
callback(err);
|
|
362
|
-
return;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
callback(Helpers.eresultError(body.success));
|
|
366
|
-
});
|
|
367
|
-
};
|
|
368
|
-
|
|
369
|
-
/**
|
|
370
|
-
* Pack gems into sack of gems.
|
|
371
|
-
* @param {int|string} assetid - ID of gem stack you want to pack into sacks
|
|
372
|
-
* @param {int} desiredSackCount - How many sacks you want. You must have at least this amount * 1000 gems in the stack you're packing
|
|
373
|
-
* @param {function} callback
|
|
374
|
-
*/
|
|
375
|
-
SteamCommunity.prototype.packGemSacks = function(assetid, desiredSackCount, callback) {
|
|
376
|
-
this._gemExchange(assetid, 1, 1000, desiredSackCount * 1000, desiredSackCount, callback);
|
|
377
|
-
};
|
|
378
|
-
|
|
379
|
-
/**
|
|
380
|
-
* Unpack sack of gems into gems.
|
|
381
|
-
* @param {int|string} assetid - ID of sack stack you want to unpack (say that 5 times fast)
|
|
382
|
-
* @param {int} sacksToUnpack
|
|
383
|
-
* @param {function} callback
|
|
384
|
-
*/
|
|
385
|
-
SteamCommunity.prototype.unpackGemSacks = function(assetid, sacksToUnpack, callback) {
|
|
386
|
-
this._gemExchange(assetid, 1000, 1, sacksToUnpack, sacksToUnpack * 1000, callback);
|
|
387
|
-
};
|
|
1
|
+
const SteamCommunity = require('../index.js');
|
|
2
|
+
const Cheerio = require('cheerio');
|
|
3
|
+
|
|
4
|
+
const Helpers = require('./helpers.js');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Get a list of all apps on the market
|
|
8
|
+
* @param {function} callback - First argument is null|Error, second is an object of appid => name
|
|
9
|
+
*/
|
|
10
|
+
SteamCommunity.prototype.getMarketApps = function(callback) {
|
|
11
|
+
var self = this;
|
|
12
|
+
this.httpRequest('https://steamcommunity.com/market/', function (err, response, body) {
|
|
13
|
+
if (err) {
|
|
14
|
+
callback(err);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
var $ = Cheerio.load(body);
|
|
19
|
+
if ($('.market_search_game_button_group')) {
|
|
20
|
+
let apps = {};
|
|
21
|
+
$('.market_search_game_button_group a.game_button').each(function (i, element) {
|
|
22
|
+
var e = Cheerio.load(element);
|
|
23
|
+
var name = e('.game_button_game_name').text().trim();
|
|
24
|
+
var url = element.attribs.href;
|
|
25
|
+
var appid = url.substr(url.indexOf('=') + 1);
|
|
26
|
+
apps[appid] = name;
|
|
27
|
+
});
|
|
28
|
+
callback(null, apps);
|
|
29
|
+
} else {
|
|
30
|
+
callback(new Error("Malformed response"));
|
|
31
|
+
}
|
|
32
|
+
}, "steamcommunity");
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Check if an item is eligible to be turned into gems and if so, get its gem value
|
|
37
|
+
* @param {int} appid
|
|
38
|
+
* @param {int|string} assetid
|
|
39
|
+
* @param {function} callback
|
|
40
|
+
*/
|
|
41
|
+
SteamCommunity.prototype.getGemValue = function(appid, assetid, callback) {
|
|
42
|
+
this._myProfile({
|
|
43
|
+
"endpoint": "ajaxgetgoovalue/",
|
|
44
|
+
"qs": {
|
|
45
|
+
"sessionid": this.getSessionID(),
|
|
46
|
+
"appid": appid,
|
|
47
|
+
"contextid": 6,
|
|
48
|
+
"assetid": assetid
|
|
49
|
+
},
|
|
50
|
+
"checkHttpError": false,
|
|
51
|
+
"json": true
|
|
52
|
+
}, null, (err, res, body) => {
|
|
53
|
+
if (err) {
|
|
54
|
+
callback(err);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (body.success && body.success != SteamCommunity.EResult.OK) {
|
|
59
|
+
let err = new Error(body.message || SteamCommunity.EResult[body.success]);
|
|
60
|
+
err.eresult = err.code = body.success;
|
|
61
|
+
callback(err);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (!body.goo_value || !body.strTitle) {
|
|
66
|
+
callback(new Error("Malformed response"));
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
callback(null, {"promptTitle": body.strTitle, "gemValue": parseInt(body.goo_value, 10)});
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Turn an eligible item into gems.
|
|
76
|
+
* @param {int} appid
|
|
77
|
+
* @param {int|string} assetid
|
|
78
|
+
* @param {int} expectedGemsValue
|
|
79
|
+
* @param {function} callback
|
|
80
|
+
*/
|
|
81
|
+
SteamCommunity.prototype.turnItemIntoGems = function(appid, assetid, expectedGemsValue, callback) {
|
|
82
|
+
this._myProfile({
|
|
83
|
+
"endpoint": "ajaxgrindintogoo/",
|
|
84
|
+
"json": true,
|
|
85
|
+
"checkHttpError": false
|
|
86
|
+
}, {
|
|
87
|
+
"appid": appid,
|
|
88
|
+
"contextid": 6,
|
|
89
|
+
"assetid": assetid,
|
|
90
|
+
"goo_value_expected": expectedGemsValue,
|
|
91
|
+
"sessionid": this.getSessionID()
|
|
92
|
+
}, (err, res, body) => {
|
|
93
|
+
if (err) {
|
|
94
|
+
callback(err);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (body.success && body.success != SteamCommunity.EResult.OK) {
|
|
99
|
+
let err = new Error(body.message || SteamCommunity.EResult[body.success]);
|
|
100
|
+
err.eresult = err.code = body.success;
|
|
101
|
+
callback(err);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (!body['goo_value_received '] || !body.goo_value_total) { // lol valve
|
|
106
|
+
callback(new Error("Malformed response"));
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
callback(null, {"gemsReceived": parseInt(body['goo_value_received '], 10), "totalGems": parseInt(body.goo_value_total, 10)});
|
|
111
|
+
})
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Open a booster pack.
|
|
116
|
+
* @param {int} appid
|
|
117
|
+
* @param {int|string} assetid
|
|
118
|
+
* @param {function} callback
|
|
119
|
+
*/
|
|
120
|
+
SteamCommunity.prototype.openBoosterPack = function(appid, assetid, callback) {
|
|
121
|
+
this._myProfile({
|
|
122
|
+
"endpoint": "ajaxunpackbooster/",
|
|
123
|
+
"json": true,
|
|
124
|
+
"checkHttpError": false
|
|
125
|
+
}, {
|
|
126
|
+
"appid": appid,
|
|
127
|
+
"communityitemid": assetid,
|
|
128
|
+
"sessionid": this.getSessionID()
|
|
129
|
+
}, (err, res, body) => {
|
|
130
|
+
if (err) {
|
|
131
|
+
callback(err);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (body.success && body.success != SteamCommunity.EResult.OK) {
|
|
136
|
+
let err = new Error(body.message || SteamCommunity.EResult[body.success]);
|
|
137
|
+
err.eresult = err.code = body.success;
|
|
138
|
+
callback(err);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (!body.rgItems) {
|
|
143
|
+
callback(new Error("Malformed response"));
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
callback(null, body.rgItems);
|
|
148
|
+
})
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Get the booster pack catalog to see what booster packs you can create
|
|
153
|
+
* @param {function} callback
|
|
154
|
+
*/
|
|
155
|
+
SteamCommunity.prototype.getBoosterPackCatalog = function(callback) {
|
|
156
|
+
this.httpRequestGet('https://steamcommunity.com/tradingcards/boostercreator/', (err, res, body) => {
|
|
157
|
+
if (err) {
|
|
158
|
+
callback(err);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
let idx = body.indexOf('CBoosterCreatorPage.Init(');
|
|
163
|
+
if (idx == -1) {
|
|
164
|
+
callback(new Error('Malformed response'));
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
let lines = body.slice(idx).split('\n').map(l => l.trim());
|
|
169
|
+
|
|
170
|
+
for (let i = 1; i <= 4; i++) {
|
|
171
|
+
if (typeof lines[i] != 'string' || !lines[i].match(/,$/)) {
|
|
172
|
+
let err = new Error('Malformed response');
|
|
173
|
+
err.line = i;
|
|
174
|
+
callback(err);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
lines[i] = lines[i].replace(/,$/, '');
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
let boosterPackCatalog, totalGems, tradableGems, untradableGems;
|
|
182
|
+
try {
|
|
183
|
+
boosterPackCatalog = JSON.parse(lines[1]);
|
|
184
|
+
totalGems = parseInt(lines[2].match(/\d+/)[0], 10);
|
|
185
|
+
tradableGems = parseInt(lines[3].match(/\d+/)[0], 10);
|
|
186
|
+
untradableGems = parseInt(lines[4].match(/\d+/)[0], 10);
|
|
187
|
+
} catch (ex) {
|
|
188
|
+
let err = new Error('Malformed response');
|
|
189
|
+
err.inner = ex;
|
|
190
|
+
callback(err);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
let keyedCatalog = {};
|
|
195
|
+
boosterPackCatalog.forEach((app) => {
|
|
196
|
+
app.price = parseInt(app.price, 10);
|
|
197
|
+
app.unavailable = app.unavailable || false;
|
|
198
|
+
app.availableAtTime = app.available_at_time || null;
|
|
199
|
+
|
|
200
|
+
if (typeof app.availableAtTime == 'string') {
|
|
201
|
+
app.availableAtTime = Helpers.decodeSteamTime(app.availableAtTime);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
delete app.available_at_time;
|
|
205
|
+
|
|
206
|
+
keyedCatalog[app.appid] = app;
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
callback(null, {
|
|
210
|
+
totalGems,
|
|
211
|
+
tradableGems,
|
|
212
|
+
untradableGems,
|
|
213
|
+
catalog: keyedCatalog
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Create a booster pack using gems.
|
|
220
|
+
* @param {int} appid
|
|
221
|
+
* @param {boolean} [useUntradableGems=false]
|
|
222
|
+
* @param callback
|
|
223
|
+
*/
|
|
224
|
+
SteamCommunity.prototype.createBoosterPack = function(appid, useUntradableGems, callback) {
|
|
225
|
+
if (typeof useUntradableGems == 'function') {
|
|
226
|
+
callback = useUntradableGems;
|
|
227
|
+
useUntradableGems = false;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
this.httpRequestPost({
|
|
231
|
+
uri: 'https://steamcommunity.com/tradingcards/ajaxcreatebooster/',
|
|
232
|
+
form: {
|
|
233
|
+
sessionid: this.getSessionID(),
|
|
234
|
+
appid,
|
|
235
|
+
series: 1,
|
|
236
|
+
// tradability_preference can be a value 1-3
|
|
237
|
+
// 1: Prefer using tradable gems, but use untradable if necessary
|
|
238
|
+
// 2: Only use tradable gems
|
|
239
|
+
// 3: Prefer using untradable gems, but use tradable if necessary
|
|
240
|
+
tradability_preference: useUntradableGems ? 3 : 2
|
|
241
|
+
},
|
|
242
|
+
json: true,
|
|
243
|
+
checkHttpError: false
|
|
244
|
+
}, (err, res, body) => {
|
|
245
|
+
if (err) {
|
|
246
|
+
callback(err);
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if (body.purchase_eresult && body.purchase_eresult != 1) {
|
|
251
|
+
callback(Helpers.eresultError(body.purchase_eresult));
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// We can now check HTTP status codes
|
|
256
|
+
if (this._checkHttpError(err, res, callback, body)) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
callback(null, {
|
|
261
|
+
totalGems: parseInt(body.goo_amount, 10),
|
|
262
|
+
tradableGems: parseInt(body.tradable_goo_amount, 10),
|
|
263
|
+
untradableGems: parseInt(body.untradable_goo_amount, 10),
|
|
264
|
+
resultItem: body.purchase_result
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Get details about a gift in your inventory.
|
|
271
|
+
* @param {string} giftID
|
|
272
|
+
* @param {function} callback
|
|
273
|
+
*/
|
|
274
|
+
SteamCommunity.prototype.getGiftDetails = function(giftID, callback) {
|
|
275
|
+
this.httpRequestPost({
|
|
276
|
+
"uri": "https://steamcommunity.com/gifts/" + giftID + "/validateunpack",
|
|
277
|
+
"form": {
|
|
278
|
+
"sessionid": this.getSessionID()
|
|
279
|
+
},
|
|
280
|
+
"json": true
|
|
281
|
+
}, (err, res, body) => {
|
|
282
|
+
if (err) {
|
|
283
|
+
callback(err);
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
if (body.success && body.success != SteamCommunity.EResult.OK) {
|
|
288
|
+
let err = new Error(body.message || SteamCommunity.EResult[body.success]);
|
|
289
|
+
err.eresult = err.code = body.success;
|
|
290
|
+
callback(err);
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
if (!body.packageid || !body.gift_name) {
|
|
295
|
+
callback(new Error("Malformed response"));
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
callback(null, {
|
|
300
|
+
"giftName": body.gift_name,
|
|
301
|
+
"packageID": parseInt(body.packageid, 10),
|
|
302
|
+
"owned": body.owned
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Unpack a gift in your inventory to your library.
|
|
309
|
+
* @param {string} giftID
|
|
310
|
+
* @param {function} callback
|
|
311
|
+
*/
|
|
312
|
+
SteamCommunity.prototype.redeemGift = function(giftID, callback) {
|
|
313
|
+
this.httpRequestPost({
|
|
314
|
+
"uri": "https://steamcommunity.com/gifts/" + giftID + "/unpack",
|
|
315
|
+
"form": {
|
|
316
|
+
"sessionid": this.getSessionID()
|
|
317
|
+
},
|
|
318
|
+
"json": true
|
|
319
|
+
}, (err, res, body) => {
|
|
320
|
+
if (err) {
|
|
321
|
+
callback(err);
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
if (body.success && body.success != SteamCommunity.EResult.OK) {
|
|
326
|
+
|
|
327
|
+
let err = new Error(body.message || SteamCommunity.EResult[body.success]);
|
|
328
|
+
err.eresult = err.code = body.success;
|
|
329
|
+
callback(err);
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
callback(null);
|
|
334
|
+
});
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* @param {int|string} assetid
|
|
339
|
+
* @param {int} denominationIn
|
|
340
|
+
* @param {int} denominationOut
|
|
341
|
+
* @param {int} quantityIn
|
|
342
|
+
* @param {int} quantityOut
|
|
343
|
+
* @param {function} callback
|
|
344
|
+
* @private
|
|
345
|
+
*/
|
|
346
|
+
SteamCommunity.prototype._gemExchange = function(assetid, denominationIn, denominationOut, quantityIn, quantityOut, callback) {
|
|
347
|
+
this._myProfile({
|
|
348
|
+
endpoint: 'ajaxexchangegoo/',
|
|
349
|
+
json: true,
|
|
350
|
+
checkHttpError: false
|
|
351
|
+
}, {
|
|
352
|
+
appid: 753,
|
|
353
|
+
assetid,
|
|
354
|
+
goo_denomination_in: denominationIn,
|
|
355
|
+
goo_amount_in: quantityIn,
|
|
356
|
+
goo_denomination_out: denominationOut,
|
|
357
|
+
goo_amount_out_expected: quantityOut,
|
|
358
|
+
sessionid: this.getSessionID()
|
|
359
|
+
}, (err, res, body) => {
|
|
360
|
+
if (err) {
|
|
361
|
+
callback(err);
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
callback(Helpers.eresultError(body.success));
|
|
366
|
+
});
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Pack gems into sack of gems.
|
|
371
|
+
* @param {int|string} assetid - ID of gem stack you want to pack into sacks
|
|
372
|
+
* @param {int} desiredSackCount - How many sacks you want. You must have at least this amount * 1000 gems in the stack you're packing
|
|
373
|
+
* @param {function} callback
|
|
374
|
+
*/
|
|
375
|
+
SteamCommunity.prototype.packGemSacks = function(assetid, desiredSackCount, callback) {
|
|
376
|
+
this._gemExchange(assetid, 1, 1000, desiredSackCount * 1000, desiredSackCount, callback);
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Unpack sack of gems into gems.
|
|
381
|
+
* @param {int|string} assetid - ID of sack stack you want to unpack (say that 5 times fast)
|
|
382
|
+
* @param {int} sacksToUnpack
|
|
383
|
+
* @param {function} callback
|
|
384
|
+
*/
|
|
385
|
+
SteamCommunity.prototype.unpackGemSacks = function(assetid, sacksToUnpack, callback) {
|
|
386
|
+
this._gemExchange(assetid, 1000, 1, sacksToUnpack, sacksToUnpack * 1000, callback);
|
|
387
|
+
};
|