Compare commits

..

8 Commits

Author SHA1 Message Date
Alexander Corn
4f618c0a27 2.4.0 2015-06-29 16:38:36 -04:00
Alexander Corn
19fe951d96 Added ability to spoof UI mode 2015-06-29 16:38:24 -04:00
Alexander Corn
a348112ccb 2.3.0 2015-06-28 22:18:48 -04:00
Alexander Corn
dff2727f85 Don't fire callback if not provided 2015-06-28 22:16:49 -04:00
Alexander Corn
1fd12dd4d0 Added CMarketItem 2015-06-28 20:19:42 -04:00
Alexander Corn
31093da1a8 Use better dependency semver 2015-06-28 19:40:00 -04:00
Alexander Corn
1e609524e8 2.2.1 2015-06-24 13:31:17 -04:00
Alexander Corn
2a758fc180 Remember Steam login so that cookies don't expire if logged in elsewhere 2015-06-24 13:31:01 -04:00
4 changed files with 152 additions and 22 deletions

131
classes/CMarketItem.js Normal file
View File

@@ -0,0 +1,131 @@
var SteamCommunity = require('../index.js');
var Cheerio = require('cheerio');
SteamCommunity.prototype.getMarketItem = function(appid, hashName, callback) {
var self = this;
this.request("https://steamcommunity.com/market/listings/" + appid + "/" + encodeURIComponent(hashName), function(err, response, body) {
if(err || response.statusCode != 200) {
callback(err ? err.message : "HTTP error " + response.statusCode);
return;
}
var $ = Cheerio.load(body);
if($('.market_listing_table_message') && $('.market_listing_table_message').text().trim() == 'There are no listings for this item.') {
callback('There are no listings for this item.');
return;
}
var item = new CMarketItem(self, body, $);
if(item.commodity) {
item.updatePrice(function(err) {
if(err) {
callback(err);
} else {
callback(null, item);
}
});
} else {
callback(null, item);
}
});
};
function CMarketItem(community, body, $) {
this._community = community;
this._$ = $;
this._country = "US";
var match = body.match(/var g_strCountryCode = "([^"]+)";/);
if(match) {
this._country = match[1];
}
this.commodity = false;
var match = body.match(/Market_LoadOrderSpread\(\s*(\d+)\s*\);/);
if(match) {
this.commodity = true;
this.commodityID = parseInt(match[1], 10);
}
this.medianSalePrices = null;
match = body.match(/var line1=([^;]+);/);
if(match) {
try {
this.medianSalePrices = JSON.parse(match[1]);
this.medianSalePrices = this.medianSalePrices.map(function(item) {
return {
"hour": new Date(item[0]),
"price": item[1],
"quantity": parseInt(item[2], 10)
};
});
} catch(e) {
// ignore
}
}
this.quantity = 0;
this.lowestPrice = 0;
if(!this.commodity) {
var total = $('#searchResults_total');
if(total) {
this.quantity = parseInt(total.text().replace(/[^\d]/g, '').trim(), 10);
}
var lowest = $('.market_listing_price.market_listing_price_with_fee');
if(lowest[0]) {
this.lowestPrice = parseInt($(lowest[0]).text().replace(/[^\d]/g, '').trim(), 10);
}
}
// TODO: Buying listings and placing buy orders
}
CMarketItem.prototype.updatePrice = function(callback) {
if(!this.commodity) {
throw new Error("Cannot update price for non-commodity item");
}
// TODO: Currency option maybe?
var self = this;
this._community.request({
"uri": "https://steamcommunity.com/market/itemordershistogram?country=US&language=english&currency=1&item_nameid=" + this.commodityID,
"json": true,
}, function(err, response, body) {
if(err || response.statusCode != 200) {
if(callback) {
callback(err ? err.message : "HTTP error " + response.statusCode);
}
return;
}
if(body.success != 1) {
if(callback) {
callback("Error " + body.success);
}
return;
}
var match = (body.sell_order_summary || '').match(/<span class="market_commodity_orders_header_promote">(\d+)<\/span>/);
if(match) {
self.quantity = parseInt(match[1], 10);
}
self.buyQuantity = 0;
match = (body.buy_order_summary || '').match(/<span class="market_commodity_orders_header_promote">(\d+)<\/span>/);
if(match) {
self.buyQuantity = parseInt(match[1], 10);
}
self.lowestPrice = parseInt(body.lowest_sell_order, 10);
self.highestBuyOrder = parseInt(body.highest_buy_order, 10);
// TODO: The tables?
if(callback) {
callback();
}
});
};

View File

@@ -28,12 +28,13 @@ SteamCommunity.PersonaStateFlag = {
"OnlineUsingBigPicture": 1024
};
SteamCommunity.prototype.chatLogon = function(interval) {
SteamCommunity.prototype.chatLogon = function(interval, uiMode) {
if(this.chatState == SteamCommunity.ChatState.LoggingOn || this.chatState == SteamCommunity.ChatState.LoggedOn) {
return;
}
interval = interval || 500;
uiMode = uiMode || "web";
this.emit('debug', 'Requesting chat WebAPI token');
this.chatState = SteamCommunity.ChatState.LoggingOn;
@@ -58,7 +59,7 @@ SteamCommunity.prototype.chatLogon = function(interval) {
self.request.post({
"uri": "https://api.steampowered.com/ISteamWebUserPresenceOAuth/Logon/v1",
"form": {
"ui_mode": "web",
"ui_mode": uiMode,
"access_token": match[0]
},
"json": true

View File

@@ -46,35 +46,31 @@ SteamCommunity.prototype.login = function(details, callback) {
"emailsteamid": "",
"loginfriendlyname": "",
"password": hex2b64(key.encrypt(details.password)),
"remember_login": false,
"remember_login": "true",
"rsatimestamp": json.timestamp,
"twofactorcode": "",
"username": details.accountName
};
self.request.post("https://steamcommunity.com/login/dologin/", {"form": form}, function(err, response, body) {
self.request.post({
"uri": "https://steamcommunity.com/login/dologin/",
"json": true,
"form": form
}, function(err, response, body) {
if(err) {
callback(err);
return;
}
var json;
try {
json = JSON.parse(body);
} catch(e) {
callback(e);
return;
}
if(!json.success && json.emailauth_needed) {
callback("Please provide the authorization code sent to your address at " + json.emaildomain);
} else if(!json.success) {
callback(json.message || "Unknown error");
if(!body.success && body.emailauth_needed) {
callback("Please provide the authorization code sent to your address at " + body.emaildomain);
} else if(!body.success) {
callback(body.message || "Unknown error");
} else {
var sessionID = generateSessionID();
self._jar.setCookie(Request.cookie('sessionid=' + sessionID), 'http://steamcommunity.com');
self.steamID = new SteamID(json.transfer_parameters.steamid);
self.steamID = new SteamID(body.transfer_parameters.steamid);
var cookies = self._jar.getCookieString("https://steamcommunity.com").split(';').map(function(cookie) {
return cookie.trim();
});
@@ -264,6 +260,7 @@ SteamCommunity.prototype._myProfile = function(endpoint, form, callback) {
});
};
require('./classes/CMarketItem.js');
require('./classes/CSteamGroup.js');
require('./classes/CSteamUser.js');
require('./components/chat.js');

View File

@@ -1,6 +1,6 @@
{
"name": "steamcommunity",
"version": "2.2.0",
"version": "2.4.0",
"description": "Provides an interface for logging into and interacting with the Steam Community website",
"keywords": ["steam", "steam community"],
"homepage": "https://github.com/DoctorMcKay/node-steamcommunity",
@@ -13,9 +13,10 @@
"url": "https://github.com/DoctorMcKay/node-steamcommunity.git"
},
"dependencies": {
"request": "2.51.x",
"node-bignumber": "1.2.x",
"steamid": "0.1.x",
"xml2js": "0.4.x"
"request": "^2.58.0",
"node-bignumber": "^1.2.1",
"steamid": "^0.3.0",
"xml2js": "^0.4.9",
"cheerio": "^0.19.0"
}
}