Compare commits

...

48 Commits

Author SHA1 Message Date
Alexander Corn
9c34d18cd9 3.23.1 2016-08-07 00:04:56 -04:00
Alexander Corn
02e3798124 Handle some cases where the session expires while we're using webchat 2016-08-07 00:04:30 -04:00
Alexander Corn
5d9922cc33 3.23.0 2016-07-13 13:12:39 -04:00
Alexander Corn
153011e1c9 Make _community non-enumerable on CConfirmation 2016-07-13 13:11:56 -04:00
Alexander Corn
575c196cb7 Added acceptAllConfirmations method 2016-07-13 13:11:44 -04:00
Alexander Corn
47a24d19cf Added ability to act on multiple confirmations 2016-07-13 13:11:36 -04:00
Alexander Corn
0eac19b71c 3.22.0 2016-07-10 01:02:48 -04:00
Alexander Corn
ca73ecc786 Parse times in getUserAliases into Date objects 2016-07-10 01:02:36 -04:00
Alexander Corn
e8733613d7 Merge pull request #117 from andrewda/master
Add ability to get user aliases
2016-07-10 00:52:13 -04:00
Andrew Dassonville
89a1df67ec Add ability to get user aliases 2016-07-06 16:20:42 -07:00
Alexander Corn
3ba0a8592e 3.21.2 2016-07-01 18:30:32 -04:00
Alexander Corn
57fa7a679f Fixed market search results including query string (fixes #113) 2016-07-01 18:29:56 -04:00
Alexander Corn
446e315183 Fixed market search result prices being horribly wrong 2016-07-01 18:27:39 -04:00
Alexander Corn
c6a9b74471 3.21.1 2016-06-29 23:08:54 -04:00
Alexander Corn
018e18cb5d Give "Family View Restricted" error if access denied due to Family View 2016-06-29 23:08:40 -04:00
Alexander Corn
303ce10e73 3.21.0 2016-06-27 16:57:12 -04:00
Alexander Corn
60e0e63a92 Fixed marketSearch (fixes #112) 2016-06-27 16:56:16 -04:00
Luke
17e5b94782 Added deleting events in CSteamGroup (#109)
* Added deleteEvent()

* Added deleteGroupEvent()
2016-06-21 22:39:23 -04:00
Alexander Corn
beaf012846 3.20.0 2016-06-15 15:07:45 -04:00
Alexander Corn
38c20a342c Merge pull request #105 from luop90/master
Added editing events to CSteamGroup
2016-06-15 14:17:41 -04:00
Luke
a406cfbfe2 Fixed a valid server object being overwritten 2016-06-15 11:25:44 -06:00
Luke Henke
c970eee9d3 Added editing events to CSteamGroup 2016-06-14 20:29:11 -06:00
Alexander Corn
38e3eefb33 3.19.10 2016-06-14 16:08:03 -04:00
Alexander Corn
a2e26459d9 Emit chatLogOnFailed on error, and handle fatal errors (fixes #104) 2016-06-14 16:07:46 -04:00
Alexander Corn
c1b04ee743 Fixed crash if chat poll returns no response
https://dev.doctormckay.com/topic/383-error-in-node-steamcommunity/
2016-06-14 16:02:04 -04:00
Alexander Corn
542eb8d47e 3.19.9 2016-06-03 20:11:56 -04:00
Alexander Corn
9081528f72 Fixed "Error: Error:" in trade errors 2016-06-03 20:10:33 -04:00
Alexander Corn
8be8e395b6 3.19.8 2016-05-05 16:12:35 -04:00
Alexander Corn
4b7ea80fcf Fixed profile URL cache always being deleted when editing profile 2016-05-05 16:12:27 -04:00
Alexander Corn
7f945afbca 3.19.7 2016-05-05 16:00:38 -04:00
Alexander Corn
3b241ba24f Cache profile URL so we don't need to request it all the time 2016-05-05 16:00:28 -04:00
Alexander Corn
fddd74cf24 Fixed crash if response to login is malformed 2016-04-04 21:42:46 -04:00
Alexander Corn
9a3138aa35 3.19.6 2016-04-02 16:15:35 -04:00
Alexander Corn
839d8b51e3 Automatically handle time offset when enabling 2FA (fixes #98) 2016-04-02 16:14:34 -04:00
Alexander Corn
ddf0221489 Added disable_twofactor example 2016-04-02 16:14:17 -04:00
Alexander Corn
64aaca66be 3.19.5 2016-03-31 14:34:27 -04:00
Alexander Corn
aac26212d7 Fixed sessionExpired event always being emitted for confirmation errors 2016-03-23 19:03:55 -04:00
Alexander Corn
d8d99a804f 3.19.4 2016-03-23 14:33:28 -04:00
Alexander Corn
f47afae1ea Pin cheerio version to 0.19.0
https://github.com/DoctorMcKay/node-steam-tradeoffer-manager/issues/120#issuecomment-200179648
2016-03-23 14:33:08 -04:00
Alexander Corn
8d90aac203 Use SteamID v1.0.0 2016-03-22 01:20:02 -04:00
Alexander Corn
f1bfd8b3af 3.19.3 2016-03-18 23:33:41 -04:00
Alexander Corn
579fc04c1c Prompt for CAPTCHA input in examples if needed (fixes #88) 2016-03-18 23:33:30 -04:00
Alexander Corn
58927dc937 Fixed fake error when removing 2FA (fixes #96) 2016-03-18 23:29:17 -04:00
Alexander Corn
018cacac59 Added CONTRIBUTING.md 2016-03-15 15:06:08 -04:00
Alexander Corn
26effb27fe 3.19.2 2016-03-14 21:39:55 -04:00
Alexander Corn
5880e922ab Fixed crashes when checking non-string HTTP responses (fixes #94) 2016-03-14 21:39:45 -04:00
Alexander Corn
fe007811a5 Bumped cheerio version 2016-03-08 01:56:31 -05:00
Alexander Corn
7b882c8439 Updated readme 2016-03-08 01:53:45 -05:00
19 changed files with 455 additions and 116 deletions

35
CONTRIBUTING.md Normal file
View File

@@ -0,0 +1,35 @@
# Contributing to SteamCommunity
Thanks for your interest in making `SteamCommunity` better! I'd appreciate it if you read over this document quickly
before you submit your issue or pull request. It'll make things go much smoother.
# Issues
Submitting an issue?
- If you're **reporting a bug**, please include all relevant details.
- A descriptive title helps for one. Titles of just "Error" or "It doesn't work" really don't help.
- Please describe what you're trying to do, what actually happens, and what you can do to reproduce the problem.
- If you have an error message or a crash, please include the full text of the error message and the stack trace.
- Include the relevant snippet of your code. Wrap it in \`\`\`js /* code */ \`\`\` and GitHub [will format it nicely for you](https://help.github.com/articles/github-flavored-markdown/#syntax-highlighting).
- If you're **requesting a feature**, please be descriptive and understanding.
- A good title makes a difference. Please briefly describe what you're requesting in the title.
- Be descriptive in the issue body, too. Say what you want to do, and ideally what the method should be named.
- Be understanding if I don't think that your feature request falls within the scope of this module.
- If you're **asking a question** or **requesting support**, please don't submit a GitHub issue.
- Issues are only for problems directly relating to the module's code.
- Please [post a thread in the dedicated forum](https://dev.doctormckay.com/forum/8-node-steamcommunity/) instead.
# Pull Requests
Submitting a pull request? Great! Thanks for contributing your time and code! Please keep the following in mind.
- Please follow the existing code style.
- Tabs for indentation
- camelCase for variables and functions
- Opening braces on the same line as the if/for/while statement
- etc.
- Please avoid breaking changes. If you make a breaking change that can be done in a backwards-compatible manner, I won't accept it.
- Please don't increment the version number in `package.json`. I'll do that myself when I publish it to npm.
- Please include a brief description of your change in the pull request if it's not immediately apparent from the code.
- Be understanding if I don't think that your change falls within the scope of this module.

View File

@@ -9,12 +9,15 @@ This module provides an easy interface for the Steam Community website. This mod
It supports Steam Guard and CAPTCHAs.
# Installation
Install it from npm:
$ npm install steamcommunity
**Have a question about the module or coding in general? *Do not create a GitHub issue.* GitHub issues are for feature
requests and bug reports. Instead, post in the [dedicated forum](https://dev.doctormckay.com/forum/8-node-steamcommunity/).
Such issues may be ignored!**
# Documentation
As of version 1.0.0, documentation is on the [GitHub wiki](https://github.com/DoctorMcKay/node-steamcommunity/wiki).
Documentation is available on the [GitHub wiki](https://github.com/DoctorMcKay/node-steamcommunity/wiki).
# Support
Report bugs on the [issue tracker](https://github.com/DoctorMcKay/node-steamcommunity/issues) or ask questions
on the [dedicated forum](https://dev.doctormckay.com/forum/8-node-steamcommunity/).

View File

@@ -1,7 +1,7 @@
module.exports = CConfirmation;
function CConfirmation(community, data) {
this._community = community;
Object.defineProperty(this, "_community", {"value": community});
this.id = data.id;
this.key = data.key;

View File

@@ -27,60 +27,63 @@ SteamCommunity.prototype.marketSearch = function(options, callback) {
qs.count = 100;
qs.sort_column = 'price';
qs.sort_dir = 'asc';
performSearch.call(this, this.httpRequest, qs, [], callback);
var self = this;
var results = [];
performSearch();
function performSearch() {
self.httpRequest({
"uri": "https://steamcommunity.com/market/search/render/",
"qs": qs,
"headers": {
"referer": "https://steamcommunity.com/market/search"
},
"json": true
}, function(err, response, body) {
if (err) {
callback(err);
return;
}
if(!body.success) {
callback(new Error("Success is not true"));
return;
}
if(!body.results_html) {
callback(new Error("No results_html in response"));
return;
}
var $ = Cheerio.load(body.results_html);
var $errorMsg = $('.market_listing_table_message');
if($errorMsg.length > 0) {
callback(new Error($errorMsg.text()));
return;
}
var rows = $('.market_listing_row_link');
for(var i = 0; i < rows.length; i++) {
results.push(new CMarketSearchResult($(rows[i])));
}
if(body.start + body.pagesize >= body.total_count) {
callback(null, results);
} else {
qs.start += body.pagesize;
performSearch();
}
}, "steamcommunity");
}
};
function performSearch(request, qs, results, callback) {
var self = this;
request({
"uri": "https://steamcommunity.com/market/search/render/",
"qs": qs,
"headers": {
"referer": "https://steamcommunity.com/market/search"
},
"json": true
}, function(err, response, body) {
if (err) {
callback(err);
return;
}
if(!body.success) {
callback(new Error("Success is not true"));
return;
}
if(!body.results_html) {
callback(new Error("No results_html in response"));
return;
}
var $ = Cheerio.load(body.results_html);
if($('.market_listing_table_message').length > 0) {
callback(new Error($('.market_listing_table_message').text()));
return;
}
var rows = $('.market_listing_row_link');
for(var i = 0; i < rows.length; i++) {
results.push(new CMarketSearchResult($(rows[i])));
}
if(body.start + body.pagesize >= body.total_count) {
callback(null, results);
} else {
qs.start += body.pagesize;
performSearch.call(self, request, qs, results, callback);
}
}, "steamcommunity");
}
function CMarketSearchResult(row) {
var match = row.attr('href').match(/\/market\/listings\/(\d+)\/(.+)/);
var match = row.attr('href').match(/\/market\/listings\/(\d+)\/([^\?\/]+)/);
this.appid = parseInt(match[1], 10);
this.market_hash_name = decodeURIComponent(match[2]);
this.image = row.find('.market_listing_item_img').attr('src').match(/^https?:\/\/[^\/]+\/economy\/image\/[^\/]+\//)[0];
this.price = parseInt(row.find('.market_listing_their_price .market_table_value span').text().replace(/[^\d]+/g, ''), 10);
this.price = parseInt(row.find('.market_listing_their_price .market_table_value span.normal_price').text().replace(/[^\d]+/g, ''), 10);
this.quantity = parseInt(row.find('.market_listing_num_listings_qty').text().replace(/[^\d]+/g, ''), 10);
}

View File

@@ -7,24 +7,24 @@ SteamCommunity.prototype.getSteamGroup = function(id, callback) {
if(typeof id !== 'string' && !Helpers.isSteamID(id)) {
throw new Error("id parameter should be a group URL string or a SteamID object");
}
if(typeof id === 'object' && (id.universe != SteamID.Universe.PUBLIC || id.type != SteamID.Type.CLAN)) {
throw new Error("SteamID must stand for a clan account in the public universe");
}
var self = this;
this.httpRequest("https://steamcommunity.com/" + (typeof id === 'string' ? "groups/" + id : "gid/" + id.toString()) + "/memberslistxml/?xml=1", function(err, response, body) {
if (err) {
callback(err);
return;
}
xml2js.parseString(body, function(err, result) {
if(err) {
callback(err);
return;
}
callback(null, new CSteamGroup(self, result.memberList));
});
}, "steamcommunity");
@@ -32,7 +32,7 @@ SteamCommunity.prototype.getSteamGroup = function(id, callback) {
function CSteamGroup(community, groupData) {
this._community = community;
this.steamID = new SteamID(groupData.groupID64[0]);
this.name = groupData.groupDetails[0].groupName[0];
this.url = groupData.groupDetails[0].groupURL[0];
@@ -48,7 +48,7 @@ function CSteamGroup(community, groupData) {
CSteamGroup.prototype.getAvatarURL = function(size, protocol) {
size = size || '';
protocol = protocol || 'http://';
var url = protocol + "steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/" + this.avatarHash.substring(0, 2) + "/" + this.avatarHash;
if(size == 'full' || size == 'medium') {
return url + "_" + size + ".jpg";
@@ -62,7 +62,7 @@ CSteamGroup.prototype.getMembers = function(addresses, callback) {
callback = addresses;
addresses = null;
}
this._community.getGroupMembers(this.steamID, callback, null, null, addresses, 0);
};
@@ -94,6 +94,14 @@ CSteamGroup.prototype.scheduleEvent = function(name, type, description, time, se
this._community.scheduleGroupEvent(this.steamID, name, type, description, time, server, callback);
};
CSteamGroup.prototype.editEvent = function(id, name, type, description, time, server, callback) {
this._community.editGroupEvent(this.steamID, id, name, type, description, time, server, callback);
};
CSteamGroup.prototype.deleteEvent = function (id, callback) {
this._community.deleteGroupEvent(this.steamID, id, callback);
};
CSteamGroup.prototype.setPlayerOfTheWeek = function(steamID, callback) {
this._community.setGroupPlayerOfTheWeek(this.steamID, steamID, callback);
};

View File

@@ -150,6 +150,10 @@ CSteamUser.prototype.inviteToGroup = function(groupID, callback) {
this._community.inviteUserToGroup(this.steamID, groupID, callback);
};
CSteamUser.prototype.getAliases = function(callback) {
this._community.getUserAliases(this.steamID, callback);
};
CSteamUser.prototype.getInventoryContexts = function(callback) {
this._community.getUserInventoryContexts(this.steamID, callback);
};

View File

@@ -42,9 +42,17 @@ SteamCommunity.prototype.chatLogon = function(interval, uiMode) {
var self = this;
this.getWebApiOauthToken(function(err, token) {
if(err) {
var fatal = err.message.indexOf('not authorized') != -1;
if (!fatal) {
self.chatState = SteamCommunity.ChatState.LogOnFailed;
setTimeout(self.chatLogon.bind(self), 5000);
} else {
self.chatState = SteamCommunity.ChatState.Offline;
}
self.emit('chatLogOnFailed', err, fatal);
self.emit('debug', "Cannot get oauth token: " + err.message);
self.chatState = SteamCommunity.ChatState.LogOnFailed;
setTimeout(self.chatLogon.bind(self), 5000);
return;
}
@@ -57,15 +65,17 @@ SteamCommunity.prototype.chatLogon = function(interval, uiMode) {
"json": true
}, function(err, response, body) {
if(err || response.statusCode != 200) {
self.emit('debug', 'Error logging into webchat: ' + (err ? err.message : "HTTP error " + response.statusCode));
self.chatState = SteamCommunity.ChatState.LogOnFailed;
self.emit('chatLogOnFailed', err ? err : new Error("HTTP error " + response.statusCode), false);
self.emit('debug', 'Error logging into webchat: ' + (err ? err.message : "HTTP error " + response.statusCode));
setTimeout(self.chatLogon.bind(self), 5000);
return;
}
if(body.error != 'OK') {
self.emit('debug', 'Error logging into webchat: ' + body.error);
self.chatState = SteamCommunity.ChatState.LogOnFailed;
self.emit('chatLogOnFailed', new Error(body.error), false);
self.emit('debug', 'Error logging into webchat: ' + body.error);
setTimeout(self.chatLogon.bind(self), 5000);
return;
}
@@ -74,7 +84,8 @@ SteamCommunity.prototype.chatLogon = function(interval, uiMode) {
"umqid": body.umqid,
"message": body.message,
"accessToken": token,
"interval": interval
"interval": interval,
"uiMode": uiMode
};
self.chatFriends = {};
@@ -178,11 +189,19 @@ SteamCommunity.prototype._chatPoll = function() {
if(err || response.statusCode != 200) {
self.emit('debug', 'Error in chat poll: ' + (err ? err.message : "HTTP error " + response.statusCode));
if (err.message == "Not Logged On") {
self._relogWebChat();
}
return;
}
if(body.error != 'OK') {
self.emit('debug', 'Error in chat poll: ' + body.error);
if(!body || body.error != 'OK') {
self.emit('debug', 'Error in chat poll: ' + (body && body.error ? body.error : "Malformed response"));
if (body && body.error && body.error == "Not Logged On") {
self._relogWebChat();
}
return;
}
@@ -215,6 +234,13 @@ SteamCommunity.prototype._chatPoll = function() {
}, "steamcommunity");
};
SteamCommunity.prototype._relogWebChat = function() {
this.emit('debug', "Relogging web chat");
clearTimeout(this._chat.timer);
this.chatState = SteamCommunity.ChatState.Offline;
this.chatLogon(this._chat.interval, this._chat.uiMode);
};
SteamCommunity.prototype._chatUpdatePersona = function(steamID) {
this.emit('debug', 'Updating persona data for ' + steamID);
var self = this;

View File

@@ -18,10 +18,10 @@ SteamCommunity.prototype.getConfirmations = function(time, key, callback) {
if(err) {
if (err.message == "Invalid protocol: steammobile:") {
err.message = "Not Logged In";
self._notifySessionExpired(err);
}
callback(err);
self._notifySessionExpired(err);
return;
}
@@ -108,15 +108,15 @@ SteamCommunity.prototype.getConfirmationOfferID = function(confID, time, key, ca
/**
* Confirm or cancel a given confirmation.
* @param {int} confID - The ID of the confirmation in question
* @param {string} confKey - The confirmation key associated with the confirmation in question (not a TOTP key, the `key` property of CConfirmation)
* @param {int|int[]} confID - The ID of the confirmation in question, or an array of confirmation IDs
* @param {string|string[]} confKey - The confirmation key associated with the confirmation in question (or an array of them) (not a TOTP key, the `key` property of CConfirmation)
* @param {int} time - The unix timestamp with which the following key was generated
* @param {string} key - The confirmation key that was generated using the preceeding time and the tag "allow" (if accepting) or "cancel" (if not accepting)
* @param {boolean} accept - true if you want to accept the confirmation, false if you want to cancel it
* @param {SteamCommunity~genericErrorCallback} callback - Called when the request is complete
*/
SteamCommunity.prototype.respondToConfirmation = function(confID, confKey, time, key, accept, callback) {
request(this, "ajaxop", key, time, accept ? "allow" : "cancel", {
request(this, (confID instanceof Array) ? "multiajaxop" : "ajaxop", key, time, accept ? "allow" : "cancel", {
"op": accept ? "allow" : "cancel",
"cid": confID,
"ck": confKey
@@ -144,6 +144,31 @@ SteamCommunity.prototype.respondToConfirmation = function(confID, confKey, time,
});
};
SteamCommunity.prototype.acceptAllConfirmations = function(time, confKey, allowKey, callback) {
var self = this;
this.getConfirmations(time, confKey, function(err, confs) {
if (err) {
callback(err);
return;
}
if (confs.length == 0) {
callback(null, []);
return;
}
self.respondToConfirmation(confs.map(function(conf) { return conf.id; }), confs.map(function(conf) { return conf.key; }), time, allowKey, true, function(err) {
if (err) {
callback(err);
return;
}
callback(err, confs);
});
});
};
function request(community, url, key, time, tag, params, json, callback) {
params = params || {};
params.p = SteamTotp.getDeviceID(community.steamID);
@@ -153,11 +178,19 @@ function request(community, url, key, time, tag, params, json, callback) {
params.m = "android";
params.tag = tag;
community.httpRequestGet({
var req = {
"method": url == 'multiajaxop' ? 'POST' : 'GET',
"uri": "https://steamcommunity.com/mobileconf/" + url,
"qs": params,
"json": !!json
}, function(err, response, body) {
};
if (req.method == "GET") {
req.qs = params;
} else {
req.form = params;
}
community.httpRequest(req, function(err, response, body) {
if (err) {
callback(err);
return;

View File

@@ -120,7 +120,7 @@ SteamCommunity.prototype.getAllGroupAnnouncements = function(gid, time, callback
var self = this;
this.httpRequest({
"uri": "https://steamcommunity.com/gid/" + gid.getSteamID64() + "/rss/"
"uri": "https://steamcommunity.com/gid/" + gid.getSteamID64() + "/rss/"
}, function(err, response, body) {
if (err) {
callback(err);
@@ -242,7 +242,7 @@ SteamCommunity.prototype.scheduleGroupEvent = function(gid, name, type, descript
server = {"ip": "", "password": ""};
} else if(typeof server === 'string') {
server = {"ip": server, "password": ""};
} else {
} else if(typeof server !== 'object') {
server = {"ip": "", "password": ""};
}
@@ -286,6 +286,88 @@ SteamCommunity.prototype.scheduleGroupEvent = function(gid, name, type, descript
}, "steamcommunity");
};
SteamCommunity.prototype.editGroupEvent = function (gid, id, name, type, description, time, server, callback) {
if (typeof gid === 'string') {
gid = new SteamID(gid);
}
// Event types: ChatEvent - Chat, OtherEvent - A lil somethin somethin, PartyEvent - Party!, MeetingEvent - Important meeting, SpecialCauseEvent - Special cause (charity ball?), MusicAndArtsEvent - Music or Art type thing, SportsEvent - Sporting endeavor, TripEvent - Out of town excursion
// Passing a number for type will make it a game event for that appid
if (typeof server === 'function') {
callback = server;
server = {"ip": "", "password": ""};
} else if (typeof server === 'string') {
server = {"ip": server, "password": ""};
} else if (typeof server !== 'object') {
server = {"ip": "", "password": ""};
}
var form = {
"sessionid": this.getSessionID(),
"action": "updateEvent",
"eventID": id,
"tzOffset": new Date().getTimezoneOffset() * -60,
"name": name,
"type": (typeof type === 'number' || !isNaN(parseInt(type, 10)) ? "GameEvent" : type),
"appID": (typeof type === 'number' || !isNaN(parseInt(type, 10)) ? type : ''),
"serverIP": server.ip,
"serverPassword": server.password,
"notes": description,
"eventQuickTime": "now"
};
if (time === null) {
form.startDate = 'MM/DD/YY';
form.startHour = '12';
form.startMinute = '00';
form.startAMPM = 'PM';
form.timeChoice = 'quick';
} else {
form.startDate = (time.getMonth() + 1 < 10 ? '0' : '') + (time.getMonth() + 1) + '/' + (time.getDate() < 10 ? '0' : '') + time.getDate() + '/' + time.getFullYear().toString().substring(2);
form.startHour = (time.getHours() === 0 ? '12' : (time.getHours() > 12 ? time.getHours() - 12 : time.getHours()));
form.startMinute = (time.getMinutes() < 10 ? '0' : '') + time.getMinutes();
form.startAMPM = (time.getHours() <= 12 ? 'AM' : 'PM');
form.timeChoice = 'specific';
}
var self = this;
this.httpRequestPost({
"uri": "https://steamcommunity.com/gid/" + gid.toString() + "/eventEdit",
"form": form
}, function(err, response, body) {
if(!callback) {
return;
}
callback(err || null);
}, "steamcommunity");
};
SteamCommunity.prototype.deleteGroupEvent = function(gid, id, callback) {
if (typeof gid === 'string') {
gid = new SteamID(gid);
}
var form = {
"sessionid": this.getSessionID(),
"action": "deleteEvent",
"eventID": id
};
var self = this;
this.httpRequestPost({
"uri": "https://steamcommunity.com/gid/" + gid.toString() + "/eventEdit",
"form": form
}, function(err, response, body) {
if(!callback) {
return;
}
callback(err || null);
}, "steamcommunity");
};
SteamCommunity.prototype.setGroupPlayerOfTheWeek = function(gid, steamID, callback) {
if(typeof gid === 'string') {
gid = new SteamID(gid);

View File

@@ -11,3 +11,13 @@ exports.isSteamID = function(input) {
return keys.length == 4;
};
exports.decodeSteamTime = function(time) {
var parts = time.split('@');
if (!parts[0].match(/,/)) {
// no year, assume current year
parts[0] += ", " + (new Date()).getFullYear();
}
return new Date(parts.join('@').replace(/(am|pm)/, ' $1') + " UTC"); // add a space so JS can decode it
};

View File

@@ -80,19 +80,25 @@ SteamCommunity.prototype._notifySessionExpired = function(err) {
};
SteamCommunity.prototype._checkHttpError = function(err, response, callback) {
if(err) {
if (err) {
callback(err);
return err;
}
if(response.statusCode >= 300 && response.statusCode <= 399 && response.headers.location.indexOf('/login') != -1) {
if (response.statusCode >= 300 && response.statusCode <= 399 && response.headers.location.indexOf('/login') != -1) {
err = new Error("Not Logged In");
callback(err);
this._notifySessionExpired(err);
return err;
}
if(response.statusCode >= 400) {
if (response.statusCode == 403 && response.body && response.body.match(/<div id="parental_notice_instructions">Enter your PIN below to exit Family View.<\/div>/)) {
err = new Error("Family View Restricted");
callback(err);
return err;
}
if (response.statusCode >= 400) {
err = new Error("HTTP error " + response.statusCode);
err.code = response.statusCode;
callback(err);
@@ -105,14 +111,14 @@ SteamCommunity.prototype._checkHttpError = function(err, response, callback) {
SteamCommunity.prototype._checkCommunityError = function(html, callback) {
var err;
if(html && html.match(/<h1>Sorry!<\/h1>/)) {
if(typeof html === 'string' && html.match(/<h1>Sorry!<\/h1>/)) {
var match = html.match(/<h3>(.+)<\/h3>/);
err = new Error(match ? match[1] : "Unknown error occurred");
callback(err);
return err;
}
if (html && html.match(/g_steamID = false;/) && html.match(/<h1>Sign In<\/h1>/)) {
if (typeof html === 'string' && html.match(/g_steamID = false;/) && html.match(/<h1>Sign In<\/h1>/)) {
err = new Error("Not Logged In");
callback(err);
this._notifySessionExpired(err);
@@ -123,14 +129,14 @@ SteamCommunity.prototype._checkCommunityError = function(html, callback) {
};
SteamCommunity.prototype._checkTradeError = function(html, callback) {
if (!html) {
if (typeof html !== 'string') {
return false;
}
var match = html.match(/<div id="error_msg">\s*([^<]+)\s*<\/div>/);
if (match) {
var err = new Error(match[1].trim());
callback(new Error(err));
callback(err);
return err;
}

View File

@@ -114,6 +114,10 @@ SteamCommunity.prototype.editProfile = function(settings, callback) {
}
self._myProfile("edit", values, function(err, response, body) {
if (settings.customURL) {
delete self._profileURL;
}
if(err || response.statusCode != 200) {
if(callback) {
callback(err || new Error("HTTP error " + response.statusCode));

View File

@@ -61,7 +61,15 @@ SteamCommunity.prototype.finalizeTwoFactor = function(secret, activationCode, ca
return;
}
finalize(token);
SteamTotp.getTimeOffset(function(err, offset, latency) {
if (err) {
callback(err);
return;
}
diff = offset;
finalize(token);
});
});
function finalize(token) {
@@ -144,14 +152,8 @@ SteamCommunity.prototype.disableTwoFactor = function(revocationCode, callback) {
return;
}
if(body.response.status == 1) {
callback(null);
return;
}
var error = new Error("Cannot remove authenticator (" + body.response.status + ")");
error.eresult = body.response.status;
callback(error);
// success = true means it worked
callback(null);
}, "steamcommunity");
});
};

View File

@@ -1,6 +1,7 @@
var SteamCommunity = require('../index.js');
var SteamID = require('steamid');
var CEconItem = require('../classes/CEconItem.js');
var Helpers = require('./helpers.js');
SteamCommunity.prototype.addFriend = function(userID, callback) {
if(typeof userID === 'string') {
@@ -190,6 +191,32 @@ SteamCommunity.prototype.inviteUserToGroup = function(userID, groupID, callback)
}, "steamcommunity");
};
SteamCommunity.prototype.getUserAliases = function(userID, callback) {
if (typeof userID === 'string') {
userID = new SteamID(userID);
}
this.httpRequestGet({
"uri": "https://steamcommunity.com/profiles/" + userID.getSteamID64() + "/ajaxaliases",
"json": true
}, function(err, response, body) {
if (err) {
callback(err);
return;
}
if (typeof body !== 'object') {
callback(new Error("Malformed response"));
return;
}
callback(null, body.map(function(entry) {
entry.timechanged = Helpers.decodeSteamTime(entry.timechanged);
return entry;
}));
}, "steamcommunity");
};
SteamCommunity.prototype.getUserInventoryContexts = function(userID, callback) {
if(typeof userID === 'string') {
userID = new SteamID(userID);

View File

@@ -0,0 +1,61 @@
var SteamCommunity = require('../index.js');
var ReadLine = require('readline');
var fs = require('fs');
var community = new SteamCommunity();
var rl = ReadLine.createInterface({
"input": process.stdin,
"output": process.stdout
});
rl.question("Username: ", function(accountName) {
rl.question("Password: ", function(password) {
rl.question("Two-Factor Auth Code: ", function(authCode) {
rl.question("Revocation Code: R", function(rCode) {
doLogin(accountName, password, authCode, "", rCode);
});
});
});
});
function doLogin(accountName, password, authCode, captcha, rCode) {
community.login({
"accountName": accountName,
"password": password,
"twoFactorCode": authCode,
"captcha": captcha
}, function(err, sessionID, cookies, steamguard) {
if(err) {
if(err.message == 'SteamGuard') {
console.log("This account does not have two-factor authentication enabled.");
process.exit();
return;
}
if(err.message == 'CAPTCHA') {
console.log(err.captchaurl);
rl.question("CAPTCHA: ", function(captchaInput) {
doLogin(accountName, password, authCode, captchaInput);
});
return;
}
console.log(err);
process.exit();
return;
}
console.log("Logged on!");
community.disableTwoFactor("R" + rCode, function(err) {
if(err) {
console.log(err);
process.exit();
return;
}
console.log("Two-factor authentication disabled!");
process.exit();
});
});
}

View File

@@ -14,12 +14,13 @@ rl.question("Username: ", function(accountName) {
});
});
function doLogin(accountName, password, authCode, twoFactorCode) {
function doLogin(accountName, password, authCode, twoFactorCode, captcha) {
community.login({
"accountName": accountName,
"password": password,
"authCode": authCode,
"twoFactorCode": twoFactorCode
"twoFactorCode": twoFactorCode,
"captcha": captcha
}, function(err, sessionID, cookies, steamguard) {
if(err) {
if(err.message == 'SteamGuardMobile') {
@@ -39,6 +40,15 @@ function doLogin(accountName, password, authCode, twoFactorCode) {
return;
}
if(err.message == 'CAPTCHA') {
console.log(err.captchaurl);
rl.question("CAPTCHA: ", function(captchaInput) {
doLogin(accountName, password, authCode, twoFactorCode, captchaInput);
});
return;
}
console.log(err);
process.exit();
return;

View File

@@ -14,11 +14,12 @@ rl.question("Username: ", function(accountName) {
});
});
function doLogin(accountName, password, authCode) {
function doLogin(accountName, password, authCode, captcha) {
community.login({
"accountName": accountName,
"password": password,
"authCode": authCode
"authCode": authCode,
"captcha": captcha
}, function(err, sessionID, cookies, steamguard) {
if(err) {
if(err.message == 'SteamGuardMobile') {
@@ -29,13 +30,22 @@ function doLogin(accountName, password, authCode) {
if(err.message == 'SteamGuard') {
console.log("An email has been sent to your address at " + err.emaildomain);
rl.question("Steam Guard Code: ", function(code) {
rl.question("Steam Guard Code: ", function (code) {
doLogin(accountName, password, code);
});
return;
}
if(err.message == 'CAPTCHA') {
console.log(err.captchaurl);
rl.question("CAPTCHA: ", function(captchaInput) {
doLogin(accountName, password, authCode, captchaInput);
});
return;
}
console.log(err);
process.exit();
return;

View File

@@ -135,6 +135,8 @@ SteamCommunity.prototype.login = function(details, callback) {
callback(error);
} else if(!body.success) {
callback(new Error(body.message || "Unknown error"));
} else if(!body.oauth) {
callback(new Error("Malformed response"));
} else {
var sessionID = generateSessionID();
var oAuth = JSON.parse( body.oauth );
@@ -339,20 +341,34 @@ SteamCommunity.prototype.loggedIn = function(callback) {
SteamCommunity.prototype._myProfile = function(endpoint, form, callback) {
var self = this;
this.httpRequest("https://steamcommunity.com/my", {"followRedirect": false}, function(err, response, body) {
if(err || response.statusCode != 302) {
callback(err || "HTTP error " + response.statusCode);
return;
}
var match = response.headers.location.match(/steamcommunity\.com(\/(id|profiles)\/[^\/]+)\/?/);
if(!match) {
callback(new Error("Can't get profile URL"));
return;
}
if (this._profileURL) {
completeRequest(this._profileURL);
} else {
this.httpRequest("https://steamcommunity.com/my", {"followRedirect": false}, function(err, response, body) {
if(err || response.statusCode != 302) {
callback(err || "HTTP error " + response.statusCode);
return;
}
var match = response.headers.location.match(/steamcommunity\.com(\/(id|profiles)\/[^\/]+)\/?/);
if(!match) {
callback(new Error("Can't get profile URL"));
return;
}
self._profileURL = match[1];
setTimeout(function () {
delete self._profileURL; // delete the cache
}, 60000);
completeRequest(match[1]);
}, "steamcommunity");
}
function completeRequest(url) {
var options = {
"uri": "https://steamcommunity.com" + match[1] + "/" + endpoint,
"uri": "https://steamcommunity.com" + url + "/" + endpoint,
"method": "GET"
};
@@ -362,10 +378,9 @@ SteamCommunity.prototype._myProfile = function(endpoint, form, callback) {
}
self.httpRequest(options, callback, "steamcommunity");
}, "steamcommunity");
}
};
require('./components/http.js');
require('./components/chat.js');
require('./components/profile.js');

View File

@@ -1,6 +1,6 @@
{
"name": "steamcommunity",
"version": "3.19.1",
"version": "3.23.1",
"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",
@@ -15,9 +15,9 @@
"dependencies": {
"request": "^2.61.0",
"node-bignumber": "^1.2.1",
"steamid": "^0.3.1",
"steamid": "^1.0.0",
"xml2js": "^0.4.11",
"cheerio": "^0.19.0",
"cheerio": "0.19.0",
"async": "^1.4.2",
"steam-totp": "^1.3.0"
},