mirror of
https://github.com/DoctorMcKay/node-steamcommunity.git
synced 2026-09-05 23:04:53 +08:00
Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e8634e17ca | ||
|
|
2a2947344f | ||
|
|
e789d07833 | ||
|
|
88059596b3 | ||
|
|
399cc5ee84 | ||
|
|
a24bb9d4ad | ||
|
|
81eb26b30d | ||
|
|
0c95e75e39 | ||
|
|
2eaa5b057d | ||
|
|
d5592246cf | ||
|
|
22ab86434a | ||
|
|
d367ceb2a6 | ||
|
|
5ab5a6d401 | ||
|
|
a88a39c62c | ||
|
|
5f4f4a03a4 | ||
|
|
079db4b7bf | ||
|
|
22ba30f5da |
@@ -12,7 +12,7 @@ SteamCommunity.prototype.getSteamGroup = function(id, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
this._request("https://steamcommunity.com/" + (typeof id === 'string' ? "groups/" + id : "gid/" + id.toString()) + "/memberslistxml/?xml=1", function(err, response, body) {
|
this.request("https://steamcommunity.com/" + (typeof id === 'string' ? "groups/" + id : "gid/" + id.toString()) + "/memberslistxml/?xml=1", function(err, response, body) {
|
||||||
if(err || response.statusCode != 200) {
|
if(err || response.statusCode != 200) {
|
||||||
callback(err || "HTTP error " + response.statusCode);
|
callback(err || "HTTP error " + response.statusCode);
|
||||||
return;
|
return;
|
||||||
@@ -65,7 +65,7 @@ CSteamGroup.prototype.getMembers = function(callback, members, link) {
|
|||||||
link = link || "http://steamcommunity.com/gid/" + this.steamID.toString() + "/memberslistxml/?xml=1";
|
link = link || "http://steamcommunity.com/gid/" + this.steamID.toString() + "/memberslistxml/?xml=1";
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
this._community._request(link, function(err, response, body) {
|
this._community.request(link, function(err, response, body) {
|
||||||
if(err || response.statusCode != 200) {
|
if(err || response.statusCode != 200) {
|
||||||
callback(err || "HTTP error " + response.statusCode);
|
callback(err || "HTTP error " + response.statusCode);
|
||||||
return;
|
return;
|
||||||
@@ -97,7 +97,7 @@ CSteamGroup.prototype.join = function(callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
this._community._request.post("https://steamcommunity.com/gid/" + this.steamID.toString(), {"form": form}, function(err, response, body) {
|
this._community.request.post("https://steamcommunity.com/gid/" + this.steamID.toString(), {"form": form}, function(err, response, body) {
|
||||||
if(!callback) {
|
if(!callback) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -149,7 +149,7 @@ CSteamGroup.prototype.postAnnouncement = function(headline, content, callback) {
|
|||||||
"body": content
|
"body": content
|
||||||
};
|
};
|
||||||
|
|
||||||
this._community._request.post("https://steamcommunity.com/gid/" + this.steamID.toString() + "/announcements", {"form": form}, function(err, response, body) {
|
this._community.request.post("https://steamcommunity.com/gid/" + this.steamID.toString() + "/announcements", {"form": form}, function(err, response, body) {
|
||||||
if(!callback) {
|
if(!callback) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -208,7 +208,7 @@ CSteamGroup.prototype.scheduleEvent = function(name, type, description, time, se
|
|||||||
}
|
}
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
this._community._request.post("https://steamcommunity.com/gid/" + this.steamID.toString() + "/eventEdit", {"form": form}, function(err, response, body) {
|
this._community.request.post("https://steamcommunity.com/gid/" + this.steamID.toString() + "/eventEdit", {"form": form}, function(err, response, body) {
|
||||||
if(!callback) {
|
if(!callback) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -235,7 +235,7 @@ CSteamGroup.prototype.setPlayerOfTheWeek = function(steamID, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
this._community._request.post("https://steamcommunity.com/gid/" + this.steamID.toString() + "/potwEdit", {"form": form}, function(err, response, body) {
|
this._community.request.post("https://steamcommunity.com/gid/" + this.steamID.toString() + "/potwEdit", {"form": form}, function(err, response, body) {
|
||||||
if(!callback) {
|
if(!callback) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -269,7 +269,7 @@ CSteamGroup.prototype.kick = function(steamID, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
this._community._request.post("https://steamcommunity.com/gid/" + this.steamID.toString() + "/membersManage", {"form": form}, function(err, response, body) {
|
this._community.request.post("https://steamcommunity.com/gid/" + this.steamID.toString() + "/membersManage", {"form": form}, function(err, response, body) {
|
||||||
if(!callback) {
|
if(!callback) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ SteamCommunity.prototype.getSteamUser = function(id, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
this._request("http://steamcommunity.com/" + (typeof id === 'string' ? "id/" + id : "profiles/" + id.toString()) + "/?xml=1", function(err, response, body) {
|
this.request("http://steamcommunity.com/" + (typeof id === 'string' ? "id/" + id : "profiles/" + id.toString()) + "/?xml=1", function(err, response, body) {
|
||||||
if(err || response.statusCode != 200) {
|
if(err || response.statusCode != 200) {
|
||||||
callback(err || "HTTP error " + response.statusCode);
|
callback(err || "HTTP error " + response.statusCode);
|
||||||
return;
|
return;
|
||||||
@@ -104,7 +104,7 @@ CSteamUser.prototype.getAvatarURL = function(size, protocol) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
CSteamUser.prototype.addFriend = function(callback) {
|
CSteamUser.prototype.addFriend = function(callback) {
|
||||||
this._community._request.post('https://steamcommunity.com/actions/AddFriendAjax', {"form": {"accept_invite": 0, "sessionID": this._community.getSessionID(), "steamid": this.steamID.toString()}}, function(err, response, body) {
|
this._community.request.post('https://steamcommunity.com/actions/AddFriendAjax', {"form": {"accept_invite": 0, "sessionID": this._community.getSessionID(), "steamid": this.steamID.toString()}}, function(err, response, body) {
|
||||||
if(!callback) {
|
if(!callback) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -131,7 +131,7 @@ CSteamUser.prototype.addFriend = function(callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
CSteamUser.prototype.acceptFriendRequest = function(callback) {
|
CSteamUser.prototype.acceptFriendRequest = function(callback) {
|
||||||
this._community._request.post('https://steamcommunity.com/actions/AddFriendAjax', {"form": {"accept_invite": 1, "sessionID": this._community.getSessionID(), "steamid": this.steamID.toString()}}, function(err, response, body) {
|
this._community.request.post('https://steamcommunity.com/actions/AddFriendAjax', {"form": {"accept_invite": 1, "sessionID": this._community.getSessionID(), "steamid": this.steamID.toString()}}, function(err, response, body) {
|
||||||
if(!callback) {
|
if(!callback) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -146,7 +146,7 @@ CSteamUser.prototype.acceptFriendRequest = function(callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
CSteamUser.prototype.removeFriend = function(callback) {
|
CSteamUser.prototype.removeFriend = function(callback) {
|
||||||
this._community._request.post('https://steamcommunity.com/actions/RemoveFriendAjax', {"form": {"sessionID": this._community.getSessionID(), "steamid": this.steamID.toString()}}, function(err, response, body) {
|
this._community.request.post('https://steamcommunity.com/actions/RemoveFriendAjax', {"form": {"sessionID": this._community.getSessionID(), "steamid": this.steamID.toString()}}, function(err, response, body) {
|
||||||
if(!callback) {
|
if(!callback) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -161,7 +161,7 @@ CSteamUser.prototype.removeFriend = function(callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
CSteamUser.prototype.blockCommunication = function(callback) {
|
CSteamUser.prototype.blockCommunication = function(callback) {
|
||||||
this._community._request.post('https://steamcommunity.com/actions/BlockUserAjax', {"form": {"sessionID": this._community.getSessionID(), "steamid": this.steamID.toString()}}, function(err, response, body) {
|
this._community.request.post('https://steamcommunity.com/actions/BlockUserAjax', {"form": {"sessionID": this._community.getSessionID(), "steamid": this.steamID.toString()}}, function(err, response, body) {
|
||||||
if(!callback) {
|
if(!callback) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -194,7 +194,7 @@ CSteamUser.prototype.unblockCommunication = function(callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
CSteamUser.prototype.comment = function(message, callback) {
|
CSteamUser.prototype.comment = function(message, callback) {
|
||||||
this._community._request.post('https://steamcommunity.com/comment/Profile/post/' + this.steamID.toString() + '/-1/', {"form": {
|
this._community.request.post('https://steamcommunity.com/comment/Profile/post/' + this.steamID.toString() + '/-1/', {"form": {
|
||||||
"comment": message,
|
"comment": message,
|
||||||
"count": 6,
|
"count": 6,
|
||||||
"sessionid": this._community.getSessionID()
|
"sessionid": this._community.getSessionID()
|
||||||
|
|||||||
128
index.js
128
index.js
@@ -9,16 +9,17 @@ SteamCommunity.SteamID = SteamID;
|
|||||||
|
|
||||||
function SteamCommunity() {
|
function SteamCommunity() {
|
||||||
this._jar = Request.jar();
|
this._jar = Request.jar();
|
||||||
this._request = Request.defaults({"jar": this._jar});
|
this.request = Request.defaults({"jar": this._jar});
|
||||||
}
|
}
|
||||||
|
|
||||||
SteamCommunity.prototype.login = function(details, callback) {
|
SteamCommunity.prototype.login = function(details, callback) {
|
||||||
if(details.steamID && details.sentry) {
|
if(details.steamguard) {
|
||||||
this._jar.setCookie(Request.cookie('steamMachineAuth' + details.steamID.getSteamID64() + '=' + encodeURIComponent(details.sentry)), 'https://steamcommunity.com');
|
var parts = details.steamguard.split('||');
|
||||||
|
this._jar.setCookie(Request.cookie('steamMachineAuth' + parts[0] + '=' + encodeURIComponent(parts[1])), 'https://steamcommunity.com');
|
||||||
}
|
}
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
this._request.post("https://steamcommunity.com/login/getrsakey/", {"form": {"username": details.accountName}}, function(err, response, body) {
|
this.request.post("https://steamcommunity.com/login/getrsakey/", {"form": {"username": details.accountName}}, function(err, response, body) {
|
||||||
if(err) {
|
if(err) {
|
||||||
callback(err);
|
callback(err);
|
||||||
return;
|
return;
|
||||||
@@ -48,7 +49,7 @@ SteamCommunity.prototype.login = function(details, callback) {
|
|||||||
"username": details.accountName
|
"username": details.accountName
|
||||||
};
|
};
|
||||||
|
|
||||||
self._request.post("https://steamcommunity.com/login/dologin/", {"form": form}, function(err, response, body) {
|
self.request.post("https://steamcommunity.com/login/dologin/", {"form": form}, function(err, response, body) {
|
||||||
if(err) {
|
if(err) {
|
||||||
callback(err);
|
callback(err);
|
||||||
return;
|
return;
|
||||||
@@ -80,7 +81,7 @@ SteamCommunity.prototype.login = function(details, callback) {
|
|||||||
for(var i = 0; i < cookies.length; i++) {
|
for(var i = 0; i < cookies.length; i++) {
|
||||||
var parts = cookies[i].split('=');
|
var parts = cookies[i].split('=');
|
||||||
if(parts[0] == 'steamMachineAuth' + self.steamID) {
|
if(parts[0] == 'steamMachineAuth' + self.steamID) {
|
||||||
steamguard = {"steamID": self.steamID, "sentry": decodeURIComponent(parts[1])};
|
steamguard = self.steamID.toString() + '||' + decodeURIComponent(parts[1]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -121,6 +122,117 @@ function generateSessionID() {
|
|||||||
return Math.floor(Math.random() * 1000000000);
|
return Math.floor(Math.random() * 1000000000);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
SteamCommunity.prototype.getWebApiKey = function(domain, callback) {
|
||||||
|
var self = this;
|
||||||
|
this.request("https://steamcommunity.com/dev/apikey", function(err, response, body) {
|
||||||
|
if(err || response.statusCode != 200) {
|
||||||
|
return callback(err.message || "HTTP error " + response.statusCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(body.match(/<h2>Access Denied<\/h2>/)) {
|
||||||
|
return callback("Access Denied");
|
||||||
|
}
|
||||||
|
|
||||||
|
var match = body.match(/<p>Key: ([0-9A-F]+)<\/p>/);
|
||||||
|
if(match) {
|
||||||
|
// We already have an API key registered
|
||||||
|
callback(null, match[1]);
|
||||||
|
} else {
|
||||||
|
// We need to register a new API key
|
||||||
|
self.request.post('https://steamcommunity.com/dev/registerkey', {
|
||||||
|
"form": {
|
||||||
|
"domain": domain,
|
||||||
|
"agreeToTerms": "agreed",
|
||||||
|
"sessionid": self.getSessionID(),
|
||||||
|
"Submit": "Register"
|
||||||
|
}
|
||||||
|
}, function(err, response, body) {
|
||||||
|
if(err || response.statusCode >= 400) {
|
||||||
|
return callback(err.message || "HTTP error " + response.statusCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
self.getWebApiKey(domain, callback);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
SteamCommunity.prototype.parentalUnlock = function(pin, callback) {
|
||||||
|
this.request.post("https://steamcommunity.com/parental/ajaxunlock", {
|
||||||
|
"json": true,
|
||||||
|
"form": {
|
||||||
|
"pin": pin
|
||||||
|
}
|
||||||
|
}, function(err, response, body) {
|
||||||
|
if(!callback) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(err || response.statusCode != 200) {
|
||||||
|
return callback(err.message || "HTTP error " + response.statusCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!body || typeof body.success !== 'boolean') {
|
||||||
|
return callback("Invalid response");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!body.success) {
|
||||||
|
return callback("Incorrect PIN");
|
||||||
|
}
|
||||||
|
|
||||||
|
callback();
|
||||||
|
}.bind(this));
|
||||||
|
};
|
||||||
|
|
||||||
|
SteamCommunity.prototype.getNotifications = function(callback) {
|
||||||
|
this.request.get("https://steamcommunity.com/actions/RefreshNotificationArea", function(err, response, body) {
|
||||||
|
if(err || response.statusCode != 200) {
|
||||||
|
return callback(err.message || "HTTP error " + response.statusCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
var notifications = {
|
||||||
|
"comments": 0,
|
||||||
|
"items": 0,
|
||||||
|
"invites": 0,
|
||||||
|
"gifts": 0,
|
||||||
|
"chat": 0,
|
||||||
|
"trades": 0
|
||||||
|
};
|
||||||
|
|
||||||
|
var items = {
|
||||||
|
"comments": /(\d+) new comments?/,
|
||||||
|
"items": /(\d+) new items? in your inventory/,
|
||||||
|
"invites": /(\d+) new invites?/,
|
||||||
|
"gifts": /(\d+) new gifts?/,
|
||||||
|
"chat": /(\d+) unread chat messages?/,
|
||||||
|
"trades": /(\d+) new trade notifications?/
|
||||||
|
};
|
||||||
|
|
||||||
|
var match;
|
||||||
|
for(var i in items) {
|
||||||
|
if(match = body.match(items[i])) {
|
||||||
|
notifications[i] = parseInt(match[1], 10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(null, notifications);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
SteamCommunity.prototype.resetItemNotifications = function(callback) {
|
||||||
|
this.request.get("https://steamcommunity.com/my/inventory", function(err, response, body) {
|
||||||
|
if(!callback) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(err || response.statusCode != 200) {
|
||||||
|
callback(err.message || "HTTP error " + response.statusCode);
|
||||||
|
} else {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
SteamCommunity.prototype._checkCommunityError = function(html, callback) {
|
SteamCommunity.prototype._checkCommunityError = function(html, callback) {
|
||||||
if(html.match(/<h1>Sorry!<\/h1>/)) {
|
if(html.match(/<h1>Sorry!<\/h1>/)) {
|
||||||
var match = html.match(/<h3>(.+)<\/h3>/);
|
var match = html.match(/<h3>(.+)<\/h3>/);
|
||||||
@@ -133,7 +245,7 @@ SteamCommunity.prototype._checkCommunityError = function(html, callback) {
|
|||||||
|
|
||||||
SteamCommunity.prototype._myProfile = function(endpoint, form, callback) {
|
SteamCommunity.prototype._myProfile = function(endpoint, form, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
this._request("https://steamcommunity.com/my", {"followRedirect": false}, function(err, response, body) {
|
this.request("https://steamcommunity.com/my", {"followRedirect": false}, function(err, response, body) {
|
||||||
if(err || response.statusCode != 302) {
|
if(err || response.statusCode != 302) {
|
||||||
callback(err || "HTTP error " + response.statusCode);
|
callback(err || "HTTP error " + response.statusCode);
|
||||||
return;
|
return;
|
||||||
@@ -145,7 +257,7 @@ SteamCommunity.prototype._myProfile = function(endpoint, form, callback) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
(form ? self._request.post : self._request)("https://steamcommunity.com" + match[1] + "/" + endpoint, form ? {"form": form} : {}, callback);
|
(form ? self.request.post : self.request)("https://steamcommunity.com" + match[1] + "/" + endpoint, form ? {"form": form} : {}, callback);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "steamcommunity",
|
"name": "steamcommunity",
|
||||||
"version": "1.0.2",
|
"version": "2.1.0",
|
||||||
"description": "Provides an interface for logging into and interacting with the Steam Community website",
|
"description": "Provides an interface for logging into and interacting with the Steam Community website",
|
||||||
"keywords": ["steam", "steam community"],
|
"keywords": ["steam", "steam community"],
|
||||||
"homepage": "https://github.com/DoctorMcKay/node-steamcommunity",
|
"homepage": "https://github.com/DoctorMcKay/node-steamcommunity",
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/Doctor_McKay/node-steamcommunity.git"
|
"url": "https://github.com/DoctorMcKay/node-steamcommunity.git"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"request": "2.51.x",
|
"request": "2.51.x",
|
||||||
|
|||||||
Reference in New Issue
Block a user