From f5d65a9ad4bc3e8ca84af932163946f81765e56c Mon Sep 17 00:00:00 2001 From: Alex Corn Date: Wed, 2 Feb 2022 03:15:50 -0500 Subject: [PATCH 1/3] Added getBoosterPackCatalog and createBoosterPack --- components/market.js | 119 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) diff --git a/components/market.js b/components/market.js index ad436d6..081e16c 100644 --- a/components/market.js +++ b/components/market.js @@ -148,6 +148,125 @@ SteamCommunity.prototype.openBoosterPack = function(appid, assetid, callback) { }) }; +/** + * Get the booster pack catalog to see what booster packs you can create + * @param {function} callback + */ +SteamCommunity.prototype.getBoosterPackCatalog = function(callback) { + this.httpRequestGet('https://steamcommunity.com/tradingcards/boostercreator/', (err, res, body) => { + if (err) { + callback(err); + return; + } + + let idx = body.indexOf('CBoosterCreatorPage.Init('); + if (idx == -1) { + callback(new Error('Malformed response')); + return; + } + + let lines = body.slice(idx).split('\n').map(l => l.trim()); + + for (let i = 1; i <= 4; i++) { + if (typeof lines[i] != 'string' || !lines[i].match(/,$/)) { + let err = new Error('Malformed response'); + err.line = i; + callback(err); + return; + } + + lines[i] = lines[i].replace(/,$/, ''); + } + + let boosterPackCatalog, totalGems, tradableGems, untradableGems; + try { + boosterPackCatalog = JSON.parse(lines[1]); + totalGems = parseInt(lines[2].match(/\d+/)[0], 10); + tradableGems = parseInt(lines[3].match(/\d+/)[0], 10); + untradableGems = parseInt(lines[4].match(/\d+/)[0], 10); + } catch (ex) { + let err = new Error('Malformed response'); + err.inner = ex; + callback(err); + return; + } + + let keyedCatalog = {}; + boosterPackCatalog.forEach((app) => { + app.price = parseInt(app.price, 10); + app.unavailable = app.unavailable || false; + app.availableAtTime = app.available_at_time || null; + + if (typeof app.availableAtTime == 'string') { + app.availableAtTime = Helpers.decodeSteamTime(app.availableAtTime); + } + + delete app.available_at_time; + + keyedCatalog[app.appid] = app; + }); + + callback(null, { + totalGems, + tradableGems, + untradableGems, + catalog: keyedCatalog + }); + }); +}; + +/** + * Create a booster pack using gems. + * @param {int} appid + * @param {boolean} [useUntradableGems=false] + * @param callback + */ +SteamCommunity.prototype.createBoosterPack = function(appid, useUntradableGems, callback) { + if (typeof useUntradableGems == 'function') { + callback = useUntradableGems; + useUntradableGems = false; + } + + this.httpRequestPost({ + uri: 'https://steamcommunity.com/tradingcards/ajaxcreatebooster/', + form: { + sessionid: this.getSessionID(), + appid, + series: 1, + // tradability_preference can be a value 1-3 + // 1: Prefer using tradable gems + // 2: Prefer using tradable gems (this value is sent when you don't have any untradable gems and thus aren't + // prompted whether you want to use tradable or untradable gems, but it appears to work the same as 1) + // 3: Prefer using untradable gems + tradability_preference: useUntradableGems ? 3 : 2 + }, + json: true, + checkHttpError: false + }, (err, res, body) => { + if (err) { + callback(err); + return; + } + + if (body.purchase_eresult && body.purchase_eresult != 1) { + callback(Helpers.eresultError(body.purchase_eresult)); + return; + } + + // We can now check HTTP status codes + if (this._checkHttpError(err, res, callback, body)) { + return; + } + + callback(null, { + totalGems: parseInt(body.goo_amount, 10), + tradableGems: parseInt(body.tradable_goo_amount, 10), + untradableGems: parseInt(body.untradable_goo_amount, 10), + resultItem: body.purchase_result + }); + }); +}; + /** * Get details about a gift in your inventory. * @param {string} giftID From 640c47b9333b8eef795c445ccbf52d5772bbbe1a Mon Sep 17 00:00:00 2001 From: Alex Corn Date: Wed, 2 Feb 2022 03:35:44 -0500 Subject: [PATCH 2/3] Updated comment --- .idea/codeStyles/Project.xml | 3 --- .idea/codeStyles/codeStyleConfig.xml | 1 + .idea/modules.xml | 1 + .idea/steamcommunity.iml | 1 + .idea/vcs.xml | 1 + components/market.js | 7 +++---- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index ea198ab..797d04f 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,8 +1,5 @@ - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 35eb1dd..18cac0e 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -2,5 +2,6 @@ + \ No newline at end of file diff --git a/components/market.js b/components/market.js index 081e16c..01f3d2e 100644 --- a/components/market.js +++ b/components/market.js @@ -234,10 +234,9 @@ SteamCommunity.prototype.createBoosterPack = function(appid, useUntradableGems, appid, series: 1, // tradability_preference can be a value 1-3 - // 1: Prefer using tradable gems - // 2: Prefer using tradable gems (this value is sent when you don't have any untradable gems and thus aren't - // prompted whether you want to use tradable or untradable gems, but it appears to work the same as 1) - // 3: Prefer using untradable gems + // 1: Prefer using tradable gems, but use untradable if necessary + // 2: Only use tradable gems + // 3: Prefer using untradable gems, but use tradable if necessary tradability_preference: useUntradableGems ? 3 : 2 }, json: true, From 9a069e80fb84aa69a4dc6c6468968d234c8725b1 Mon Sep 17 00:00:00 2001 From: Alex Corn Date: Wed, 2 Feb 2022 03:36:23 -0500 Subject: [PATCH 3/3] 3.44.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c0366a8..5991d93 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "steamcommunity", - "version": "3.43.1", + "version": "3.44.0", "description": "Provides an interface for logging into and interacting with the Steam Community website", "keywords": [ "steam",