Refactored gem sack code

This commit is contained in:
Alex Corn 2020-11-05 02:19:31 -05:00
parent b00b871a5b
commit 2fc8d1f4aa
No known key found for this signature in database
GPG Key ID: E51989A3E7A27FDF

View File

@ -1,5 +1,7 @@
var SteamCommunity = require('../index.js');
var Cheerio = require('cheerio');
const SteamCommunity = require('../index.js');
const Cheerio = require('cheerio');
const Helpers = require('./helpers.js');
/**
* Get a list of all apps on the market
@ -203,6 +205,7 @@ SteamCommunity.prototype.redeemGift = function(giftID, callback) {
}
if (body.success && body.success != SteamCommunity.EResult.OK) {
let err = new Error(body.message || SteamCommunity.EResult[body.success]);
err.eresult = err.code = body.success;
callback(err);
@ -214,75 +217,53 @@ SteamCommunity.prototype.redeemGift = function(giftID, callback) {
};
/**
* Pack gems into sack of gems.
* @param {int|string} assetid
* @param {int} gemsToPack
* @param {int} expectedSacksOfGems
* @param {int} denominationIn
* @param {int} denominationOut
* @param {int} quantityIn
* @param {int} quantityOut
* @param {function} callback
* @private
*/
SteamCommunity.prototype.toSackOfGems = function(assetid, gemsToPack, expectedSacksOfGems, callback) {
SteamCommunity.prototype._gemExchange = function(assetid, denominationIn, denominationOut, quantityIn, quantityOut, callback) {
this._myProfile({
"endpoint": "ajaxexchangegoo/",
"json": true,
"checkHttpError": false
endpoint: 'ajaxexchangegoo/',
json: true,
checkHttpError: false
}, {
"appid": 753,
"assetid": assetid,
"goo_denomination_in": 1,
"goo_amount_in": gemsToPack,
"goo_denomination_out": 1000,
"goo_amount_out_expected": expectedSacksOfGems,
"sessionid": this.getSessionID()
appid: 753,
assetid,
goo_denomination_in: denominationIn,
goo_amount_in: quantityIn,
goo_denomination_out: denominationOut,
goo_amount_out_expected: quantityOut,
sessionid: this.getSessionID()
}, (err, res, body) => {
if (err) {
callback(err);
return;
}
if (body.success && body.success != SteamCommunity.EResult.OK) {
let err = new Error(body.message || SteamCommunity.EResult[body.success]);
err.eresult = err.code = body.success;
callback(err);
return;
}
callback(Helpers.eresultError(body.success));
});
};
callback(null);
})
/**
* Pack gems into sack of gems.
* @param {int|string} assetid - ID of gem stack you want to pack into sacks
* @param {int} desiredSackCount - How many sacks you want. You must have at least this amount * 1000 gems in the stack you're packing
* @param {function} callback
*/
SteamCommunity.prototype.packGemSacks = function(assetid, desiredSackCount, callback) {
this._gemExchange(assetid, 1, 1000, desiredSackCount * 1000, desiredSackCount, callback);
};
/**
* Unpack sack of gems into gems.
* @param {int|string} assetid
* @param {int} sacksOfGemsToUnpack
* @param {int} expectedSacksOfGems
* @param {int|string} assetid - ID of sack stack you want to unpack (say that 5 times fast)
* @param {int} sacksToUnpack
* @param {function} callback
*/
SteamCommunity.prototype.unpackSackOfGems = function(assetid, sacksOfGemsToUnpack, expectedGemsValue, callback) {
this._myProfile({
"endpoint": "ajaxexchangegoo/",
"json": true,
"checkHttpError": false
}, {
"appid": 753,
"assetid": assetid,
"goo_denomination_in": 1000,
"goo_amount_in": sacksOfGemsToUnpack,
"goo_denomination_out": 1,
"goo_amount_out_expected": expectedGemsValue,
"sessionid": this.getSessionID()
}, (err, res, body) => {
if (err) {
callback(err);
return;
}
if (body.success && body.success != SteamCommunity.EResult.OK) {
let err = new Error(body.message || SteamCommunity.EResult[body.success]);
err.eresult = err.code = body.success;
callback(err);
return;
}
callback(null);
})
SteamCommunity.prototype.unpackGemSacks = function(assetid, sacksToUnpack, callback) {
this._gemExchange(assetid, 1000, 1, sacksToUnpack, sacksToUnpack * 1000, callback);
};