mirror of
https://github.com/DoctorMcKay/node-steamcommunity.git
synced 2026-09-03 22:02:46 +08:00
Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bd87f27c9c | ||
|
|
07c8c724e7 | ||
|
|
ea88c1cda4 | ||
|
|
c291f0fab3 | ||
|
|
88063ebf27 | ||
|
|
8485b447d8 | ||
|
|
df20c1ac25 | ||
|
|
49b038d3d2 | ||
|
|
d1efe5f203 | ||
|
|
b16a8144ff | ||
|
|
019e33d360 | ||
|
|
01093f38fa | ||
|
|
62c2f1b965 | ||
|
|
21895a221c | ||
|
|
f3d88d6b83 | ||
|
|
09327af220 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
|||||||
node_modules/*
|
node_modules/*
|
||||||
test.js
|
test.js
|
||||||
|
.idea/
|
||||||
|
|||||||
@@ -59,228 +59,39 @@ CSteamGroup.prototype.getAvatarURL = function(size, protocol) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
CSteamGroup.prototype.getMembers = function(callback, members, link) {
|
CSteamGroup.prototype.getMembers = function(addresses, callback) {
|
||||||
members = members || [];
|
if(typeof addresses === 'function') {
|
||||||
link = link || "http://steamcommunity.com/gid/" + this.steamID.toString() + "/memberslistxml/?xml=1";
|
callback = addresses;
|
||||||
|
addresses = null;
|
||||||
var self = this;
|
}
|
||||||
this._community.request(link, function(err, response, body) {
|
|
||||||
if(self._community._checkHttpError(err, response, callback)) {
|
this._community.getGroupMembers(this.steamID, callback, null, null, addresses, 0);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
xml2js.parseString(body, function(err, result) {
|
|
||||||
if(err) {
|
|
||||||
callback(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
members = members.concat(result.memberList.members[0].steamID64.map(function(steamID) {
|
|
||||||
return new SteamID(steamID);
|
|
||||||
}));
|
|
||||||
|
|
||||||
if(result.memberList.nextPageLink) {
|
|
||||||
self.getMembers(callback, members, result.memberList.nextPageLink[0]);
|
|
||||||
} else {
|
|
||||||
callback(null, members);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
CSteamGroup.prototype.join = function(callback) {
|
CSteamGroup.prototype.join = function(callback) {
|
||||||
var form = {
|
this._community.joinGroup(this.steamID, callback);
|
||||||
"action": "join",
|
|
||||||
"sessionID": this._community.getSessionID()
|
|
||||||
};
|
|
||||||
|
|
||||||
var self = this;
|
|
||||||
this._community.request.post("https://steamcommunity.com/gid/" + this.steamID.toString(), {"form": form}, function(err, response, body) {
|
|
||||||
if(!callback) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(err || response.statusCode >= 400) {
|
|
||||||
callback(err || new Error("HTTP error " + response.statusCode));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(self._community._checkCommunityError(body, callback)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
callback(null);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
CSteamGroup.prototype.leave = function(callback) {
|
CSteamGroup.prototype.leave = function(callback) {
|
||||||
var form = {
|
this._community.leaveGroup(this.steamID, callback);
|
||||||
"sessionID": this._community.getSessionID(),
|
|
||||||
"action": "leaveGroup",
|
|
||||||
"groupId": this.steamID.toString()
|
|
||||||
};
|
|
||||||
|
|
||||||
var self = this;
|
|
||||||
this._community._myProfile("home_process", form, function(err, response, body) {
|
|
||||||
if(!callback) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(err || response.statusCode >= 400) {
|
|
||||||
callback(err || new Error("HTTP error " + response.statusCode));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(self._community._checkCommunityError(body, callback)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
callback(null);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
CSteamGroup.prototype.postAnnouncement = function(headline, content, callback) {
|
CSteamGroup.prototype.postAnnouncement = function(headline, content, callback) {
|
||||||
var form = {
|
this._community.postGroupAnnouncement(this.steamID, headline, content, callback);
|
||||||
"sessionID": this._community.getSessionID(),
|
|
||||||
"action": "post",
|
|
||||||
"headline": headline,
|
|
||||||
"body": content
|
|
||||||
};
|
|
||||||
|
|
||||||
this._community.request.post("https://steamcommunity.com/gid/" + this.steamID.toString() + "/announcements", {"form": form}, function(err, response, body) {
|
|
||||||
if(!callback) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(err || response.statusCode >= 400) {
|
|
||||||
callback(err || new Error("HTTP error " + response.statusCode));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(self._community._checkCommunityError(body, callback)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
callback(null);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
CSteamGroup.prototype.scheduleEvent = function(name, type, description, time, server, callback) {
|
CSteamGroup.prototype.scheduleEvent = function(name, type, description, time, server, callback) {
|
||||||
// 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
|
this._community.scheduleGroupEvent(this.steamID, name, type, description, time, server, callback);
|
||||||
// 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 {
|
|
||||||
server = {"ip": "", "password": ""};
|
|
||||||
}
|
|
||||||
|
|
||||||
var form = {
|
|
||||||
"sessionid": this._community.getSessionID(),
|
|
||||||
"action": "newEvent",
|
|
||||||
"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._community.request.post("https://steamcommunity.com/gid/" + this.steamID.toString() + "/eventEdit", {"form": form}, function(err, response, body) {
|
|
||||||
if(!callback) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(err || response.statusCode >= 400) {
|
|
||||||
callback(err || new Error("HTTP error " + response.statusCode));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(self._community._checkCommunityError(body, callback)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
callback(null);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
CSteamGroup.prototype.setPlayerOfTheWeek = function(steamID, callback) {
|
CSteamGroup.prototype.setPlayerOfTheWeek = function(steamID, callback) {
|
||||||
var form = {
|
this._community.setGroupPlayerOfTheWeek(this.steamID, steamID, callback);
|
||||||
"xml": 1,
|
|
||||||
"action": "potw",
|
|
||||||
"memberId": steamID.getSteam3RenderedID(),
|
|
||||||
"sessionid": this._community.getSessionID()
|
|
||||||
};
|
|
||||||
|
|
||||||
var self = this;
|
|
||||||
this._community.request.post("https://steamcommunity.com/gid/" + this.steamID.toString() + "/potwEdit", {"form": form}, function(err, response, body) {
|
|
||||||
if(!callback) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(err || response.statusCode != 200) {
|
|
||||||
callback(err || new Error("HTTP error " + response.statusCode));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
xml2js.parseString(body, function(err, results) {
|
|
||||||
if(err) {
|
|
||||||
callback(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(results.response.results[0] == 'OK') {
|
|
||||||
callback(null, new SteamID(results.response.oldPOTW[0]), new SteamID(results.response.newPOTW[0]));
|
|
||||||
} else {
|
|
||||||
callback(new Error(results.response.results[0]));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
CSteamGroup.prototype.kick = function(steamID, callback) {
|
CSteamGroup.prototype.kick = function(steamID, callback) {
|
||||||
var form = {
|
this._community.kickGroupMember(this.steamID, steamID, callback);
|
||||||
"sessionID": this._community.getSessionID(),
|
};
|
||||||
"action": "kick",
|
|
||||||
"memberId": steamID.toString(),
|
CSteamGroup.prototype.getHistory = function(page, callback) {
|
||||||
"queryString": ""
|
this._community.getGroupHistory(this.steamID, page, callback);
|
||||||
};
|
|
||||||
|
|
||||||
var self = this;
|
|
||||||
this._community.request.post("https://steamcommunity.com/gid/" + this.steamID.toString() + "/membersManage", {"form": form}, function(err, response, body) {
|
|
||||||
if(!callback) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(err || response.statusCode >= 400) {
|
|
||||||
callback(err || new Error("HTTP error " + response.statusCode));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(self._community._checkCommunityError(body, callback)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
callback(null);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|||||||
386
components/groups.js
Normal file
386
components/groups.js
Normal file
@@ -0,0 +1,386 @@
|
|||||||
|
var SteamCommunity = require('../index.js');
|
||||||
|
var SteamID = require('steamid');
|
||||||
|
var xml2js = require('xml2js');
|
||||||
|
var Cheerio = require('cheerio');
|
||||||
|
|
||||||
|
SteamCommunity.prototype.getGroupMembers = function(gid, callback, members, link, addresses, addressIdx) {
|
||||||
|
members = members || [];
|
||||||
|
|
||||||
|
if (!link) {
|
||||||
|
if (typeof gid !== 'string') {
|
||||||
|
// It's a SteamID object
|
||||||
|
link = "http://steamcommunity.com/gid/" + gid.toString() + "/memberslistxml/?xml=1";
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
var sid = new SteamID(gid);
|
||||||
|
if (sid.type == SteamID.Type.CLAN && sid.isValid()) {
|
||||||
|
link = "http://steamcommunity.com/gid/" + sid.getSteamID64() + "/memberslistxml/?xml=1";
|
||||||
|
} else {
|
||||||
|
throw new Error("Doesn't particularly matter what this message is");
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
link = "http://steamcommunity.com/groups/" + gid + "/memberslistxml/?xml=1";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
addressIdx = addressIdx || 0;
|
||||||
|
|
||||||
|
var options = {};
|
||||||
|
options.uri = link;
|
||||||
|
|
||||||
|
if(addresses) {
|
||||||
|
if(addressIdx >= addresses.length) {
|
||||||
|
addressIdx = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
options.localAddress = addresses[addressIdx];
|
||||||
|
}
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
this.request(options, function(err, response, body) {
|
||||||
|
if (self._checkHttpError(err, response, callback)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
xml2js.parseString(body, function(err, result) {
|
||||||
|
if (err) {
|
||||||
|
callback(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
members = members.concat(result.memberList.members[0].steamID64.map(function(steamID) {
|
||||||
|
return new SteamID(steamID);
|
||||||
|
}));
|
||||||
|
|
||||||
|
if (result.memberList.nextPageLink) {
|
||||||
|
addressIdx++;
|
||||||
|
self.getGroupMembers(gid, callback, members, result.memberList.nextPageLink[0], addresses, addressIdx);
|
||||||
|
} else {
|
||||||
|
callback(null, members);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
SteamCommunity.prototype.getGroupMembersEx = function(gid, addresses, callback) {
|
||||||
|
this.getGroupMembers(gid, callback, null, null, addresses, 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
SteamCommunity.prototype.joinGroup = function(gid, callback) {
|
||||||
|
if(typeof gid === 'string') {
|
||||||
|
gid = new SteamID(gid);
|
||||||
|
}
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
this.request.post({
|
||||||
|
"uri": "https://steamcommunity.com/gid/" + gid.getSteamID64(),
|
||||||
|
"form": {
|
||||||
|
"action": "join",
|
||||||
|
"sessionID": this.getSessionID()
|
||||||
|
}
|
||||||
|
}, function(err, response, body) {
|
||||||
|
if(!callback) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(err || response.statusCode >= 400) {
|
||||||
|
callback(err || new Error("HTTP error " + response.statusCode));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(self._checkCommunityError(body, callback)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(null);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
SteamCommunity.prototype.leaveGroup = function(gid, callback) {
|
||||||
|
if(typeof gid === 'string') {
|
||||||
|
gid = new SteamID(gid);
|
||||||
|
}
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
this._myProfile("home_process", {
|
||||||
|
"sessionID": this.getSessionID(),
|
||||||
|
"action": "leaveGroup",
|
||||||
|
"groupId": gid.getSteamID64()
|
||||||
|
}, function(err, response, body) {
|
||||||
|
if(!callback) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(err || response.statusCode >= 400) {
|
||||||
|
callback(err || new Error("HTTP error " + response.statusCode));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(self._checkCommunityError(body, callback)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(null);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
SteamCommunity.prototype.postGroupAnnouncement = function(gid, headline, content, callback) {
|
||||||
|
if(typeof gid === 'string') {
|
||||||
|
gid = new SteamID(gid);
|
||||||
|
}
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
this.request.post({
|
||||||
|
"uri": "https://steamcommunity.com/gid/" + gid.getSteamID64() + "/announcements",
|
||||||
|
"form": {
|
||||||
|
"sessionID": this.getSessionID(),
|
||||||
|
"action": "post",
|
||||||
|
"headline": headline,
|
||||||
|
"body": content
|
||||||
|
}
|
||||||
|
}, function(err, response, body) {
|
||||||
|
if(!callback) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(err || response.statusCode >= 400) {
|
||||||
|
callback(err || new Error("HTTP error " + response.statusCode));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(self._checkCommunityError(body, callback)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(null);
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
SteamCommunity.prototype.scheduleGroupEvent = function(gid, 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 {
|
||||||
|
server = {"ip": "", "password": ""};
|
||||||
|
}
|
||||||
|
|
||||||
|
var form = {
|
||||||
|
"sessionid": this.getSessionID(),
|
||||||
|
"action": "newEvent",
|
||||||
|
"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.request.post({
|
||||||
|
"uri": "https://steamcommunity.com/gid/" + this.steamID.toString() + "/eventEdit",
|
||||||
|
"form": form
|
||||||
|
}, function(err, response, body) {
|
||||||
|
if(!callback) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(err || response.statusCode >= 400) {
|
||||||
|
callback(err || new Error("HTTP error " + response.statusCode));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(self._checkCommunityError(body, callback)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(null);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
SteamCommunity.prototype.setGroupPlayerOfTheWeek = function(gid, steamID, callback) {
|
||||||
|
if(typeof gid === 'string') {
|
||||||
|
gid = new SteamID(gid);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(typeof steamID === 'string') {
|
||||||
|
steamID = new SteamID(steamID);
|
||||||
|
}
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
this.request.post({
|
||||||
|
"uri": "https://steamcommunity.com/gid/" + gid.getSteamID64() + "/potwEdit",
|
||||||
|
"form": {
|
||||||
|
"xml": 1,
|
||||||
|
"action": "potw",
|
||||||
|
"memberId": steamID.getSteam3RenderedID(),
|
||||||
|
"sessionid": this.getSessionID()
|
||||||
|
}
|
||||||
|
}, function(err, response, body) {
|
||||||
|
if(!callback) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(err || response.statusCode != 200) {
|
||||||
|
callback(err || new Error("HTTP error " + response.statusCode));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
xml2js.parseString(body, function(err, results) {
|
||||||
|
if(err) {
|
||||||
|
callback(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(results.response.results[0] == 'OK') {
|
||||||
|
callback(null, new SteamID(results.response.oldPOTW[0]), new SteamID(results.response.newPOTW[0]));
|
||||||
|
} else {
|
||||||
|
callback(new Error(results.response.results[0]));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
SteamCommunity.prototype.kickGroupMember = function(gid, steamID, callback) {
|
||||||
|
if(typeof gid === 'string') {
|
||||||
|
gid = new SteamID(gid);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(typeof steamID === 'string') {
|
||||||
|
steamID = new SteamID(steamID);
|
||||||
|
}
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
this.request.post({
|
||||||
|
"uri": "https://steamcommunity.com/gid/" + gid.getSteamID64() + "/membersManage",
|
||||||
|
"form": {
|
||||||
|
"sessionID": this.getSessionID(),
|
||||||
|
"action": "kick",
|
||||||
|
"memberId": steamID.getSteamID64(),
|
||||||
|
"queryString": ""
|
||||||
|
}
|
||||||
|
}, function(err, response, body) {
|
||||||
|
if(!callback) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(err || response.statusCode >= 400) {
|
||||||
|
callback(err || new Error("HTTP error " + response.statusCode));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(self._checkCommunityError(body, callback)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(null);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
SteamCommunity.prototype.getGroupHistory = function(gid, page, callback) {
|
||||||
|
if(typeof gid === 'string') {
|
||||||
|
gid = new SteamID(gid);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(typeof page === 'function') {
|
||||||
|
callback = page;
|
||||||
|
page = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
this.request("https://steamcommunity.com/gid/" + gid.getSteamID64() + "/history?p=" + page, function(err, response, body) {
|
||||||
|
if(self._checkHttpError(err, response, callback)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(self._checkCommunityError(body, callback)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var $ = Cheerio.load(body);
|
||||||
|
var output = {};
|
||||||
|
|
||||||
|
var paging = $('.group_paging p').text();
|
||||||
|
var match = paging.match(/(\d+) - (\d+) of (\d+)/);
|
||||||
|
|
||||||
|
if(match) {
|
||||||
|
output.first = parseInt(match[1], 10);
|
||||||
|
output.last = parseInt(match[2], 10);
|
||||||
|
output.total = parseInt(match[3], 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
output.items = [];
|
||||||
|
var currentYear = (new Date()).getFullYear();
|
||||||
|
var lastDate = Date.now();
|
||||||
|
|
||||||
|
Array.prototype.forEach.call($('.historyItem, .historyItemb'), function(item) {
|
||||||
|
var data = {};
|
||||||
|
|
||||||
|
var $item = $(item);
|
||||||
|
data.type = $item.find('.historyShort').text().replace(/ /g, '');
|
||||||
|
|
||||||
|
var users = $item.find('.whiteLink[data-miniprofile]');
|
||||||
|
var sid;
|
||||||
|
if(users[0]) {
|
||||||
|
sid = new SteamID();
|
||||||
|
sid.universe = SteamID.Universe.PUBLIC;
|
||||||
|
sid.type = SteamID.Type.INDIVIDUAL;
|
||||||
|
sid.instance = SteamID.Instance.DESKTOP;
|
||||||
|
sid.accountid = $(users[0]).data('miniprofile');
|
||||||
|
data.user = sid;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(users[1]) {
|
||||||
|
sid = new SteamID();
|
||||||
|
sid.universe = SteamID.Universe.PUBLIC;
|
||||||
|
sid.type = SteamID.Type.INDIVIDUAL;
|
||||||
|
sid.instance = SteamID.Instance.DESKTOP;
|
||||||
|
sid.accountid = $(users[0]).data('miniprofile');
|
||||||
|
data.actor = sid;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Figure out the date. Of course there's no year, because Valve
|
||||||
|
var dateParts = $item.find('.historyDate').text().split('@');
|
||||||
|
var date = dateParts[0].trim().replace(/(st|nd|th)$/, '').trim() + ', ' + currentYear;
|
||||||
|
var time = dateParts[1].trim().replace(/(am|pm)/, ' $1');
|
||||||
|
|
||||||
|
date = new Date(date + ' ' + time + ' UTC');
|
||||||
|
|
||||||
|
// If this date is in the future, or it's later than the previous one, decrement the year
|
||||||
|
if(date.getTime() > lastDate) {
|
||||||
|
date.setFullYear(date.getFullYear() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
data.date = date;
|
||||||
|
|
||||||
|
output.items.push(data);
|
||||||
|
});
|
||||||
|
|
||||||
|
callback(null, output);
|
||||||
|
});
|
||||||
|
};
|
||||||
25
components/market.js
Normal file
25
components/market.js
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
var SteamCommunity = require('../index.js');
|
||||||
|
var Cheerio = require('cheerio');
|
||||||
|
|
||||||
|
SteamCommunity.prototype.getMarketApps = function(callback) {
|
||||||
|
var self = this;
|
||||||
|
this.request('https://steamcommunity.com/market/', function (err, response, body) {
|
||||||
|
if(self._checkHttpError(err, response, callback)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var $ = Cheerio.load(body);
|
||||||
|
if ($('.market_search_game_button_group')) {
|
||||||
|
apps = {};
|
||||||
|
$('.market_search_game_button_group > a').each(function (i, element) {
|
||||||
|
var e = Cheerio.load(element);
|
||||||
|
var name = e('.game_button_game_name').text().trim();
|
||||||
|
var url = element.attribs.href;
|
||||||
|
var appid = url.substr(url.indexOf('=') + 1);
|
||||||
|
apps[appid] = name;
|
||||||
|
});
|
||||||
|
callback(null, apps);
|
||||||
|
} else {
|
||||||
|
callback(new Error("Malformed response"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
19
index.js
19
index.js
@@ -9,14 +9,23 @@ module.exports = SteamCommunity;
|
|||||||
|
|
||||||
SteamCommunity.SteamID = SteamID;
|
SteamCommunity.SteamID = SteamID;
|
||||||
|
|
||||||
function SteamCommunity() {
|
function SteamCommunity(localAddress) {
|
||||||
this._jar = Request.jar();
|
this._jar = Request.jar();
|
||||||
this._captchaGid = -1;
|
this._captchaGid = -1;
|
||||||
this.request = Request.defaults({"jar": this._jar, "timeout": 50000});
|
|
||||||
this.chatState = SteamCommunity.ChatState.Offline;
|
this.chatState = SteamCommunity.ChatState.Offline;
|
||||||
|
|
||||||
|
var defaults = {"jar": this._jar, "timeout": 50000};
|
||||||
|
if(localAddress) {
|
||||||
|
defaults.localAddress = localAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.request = Request.defaults(defaults);
|
||||||
|
|
||||||
// English
|
// English
|
||||||
this._jar.setCookie(Request.cookie('Steam_Language=english'), 'https://steamcommunity.com');
|
this._jar.setCookie(Request.cookie('Steam_Language=english'), 'https://steamcommunity.com');
|
||||||
|
|
||||||
|
// UTC
|
||||||
|
this._jar.setCookie(Request.cookie('timezoneOffset=0,0'), 'https://steamcommunity.com');
|
||||||
}
|
}
|
||||||
|
|
||||||
SteamCommunity.prototype.login = function(details, callback) {
|
SteamCommunity.prototype.login = function(details, callback) {
|
||||||
@@ -309,9 +318,11 @@ SteamCommunity.prototype._checkHttpError = function(err, response, callback) {
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
require('./components/chat.js');
|
||||||
|
require('./components/profile.js');
|
||||||
|
require('./components/market.js');
|
||||||
|
require('./components/groups.js');
|
||||||
require('./classes/CMarketItem.js');
|
require('./classes/CMarketItem.js');
|
||||||
require('./classes/CMarketSearchResult.js');
|
require('./classes/CMarketSearchResult.js');
|
||||||
require('./classes/CSteamGroup.js');
|
require('./classes/CSteamGroup.js');
|
||||||
require('./classes/CSteamUser.js');
|
require('./classes/CSteamUser.js');
|
||||||
require('./components/chat.js');
|
|
||||||
require('./components/profile.js');
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "steamcommunity",
|
"name": "steamcommunity",
|
||||||
"version": "3.3.2",
|
"version": "3.5.2",
|
||||||
"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",
|
||||||
|
|||||||
Reference in New Issue
Block a user