mirror of
https://github.com/DoctorMcKay/node-steamcommunity.git
synced 2025-01-14 21:10:28 +08:00
Added getAllAnnouncements
Added example on how to use it
This commit is contained in:
parent
d84601e256
commit
ac02f6cb49
@ -76,6 +76,10 @@ CSteamGroup.prototype.leave = function(callback) {
|
||||
this._community.leaveGroup(this.steamID, callback);
|
||||
};
|
||||
|
||||
CSteamGroup.prototype.getAllAnnouncements = function(time, callback) {
|
||||
this._community.getAllAnnouncements(this.steamID, time, callback);
|
||||
};
|
||||
|
||||
CSteamGroup.prototype.postAnnouncement = function(headline, content, callback) {
|
||||
this._community.postGroupAnnouncement(this.steamID, headline, content, callback);
|
||||
};
|
||||
|
@ -125,6 +125,62 @@ SteamCommunity.prototype.leaveGroup = function(gid, callback) {
|
||||
});
|
||||
};
|
||||
|
||||
SteamCommunity.prototype.getAllAnnouncements = function(gid, time, callback) {
|
||||
if(typeof gid === 'string') {
|
||||
gid = new SteamID(gid);
|
||||
}
|
||||
|
||||
if(typeof time === 'function') {
|
||||
callback = time;
|
||||
time = new Date(0); // The beginnig of time...
|
||||
}
|
||||
|
||||
var self = this;
|
||||
this.request({
|
||||
"uri": "https://steamcommunity.com/gid/" + gid.getSteamID64() + "/rss/"
|
||||
}, 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;
|
||||
}
|
||||
|
||||
xml2js.parseString(body, function(err, results) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if(!results.rss.channel[0].item) {
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
var announcements = results.rss.channel[0].item.map(function(announcement) {
|
||||
var splitLink = announcement.link[0].split('/');
|
||||
return {
|
||||
headline: announcement.title[0],
|
||||
content: announcement.description[0],
|
||||
date: new Date(announcement.pubDate[0]),
|
||||
author: announcement.author[0], // Unfortunately, the RSS feed likes to give us personanames not steamid's
|
||||
aid: splitLink[splitLink.length - 1] // The ID after the last /
|
||||
// Note this is marked as guid (gid?) in the rss feed but can also be obtained from link
|
||||
// and is actually a unique ID (or it seems that way)
|
||||
}
|
||||
}).filter(function(announcement) { // Only show the ones they wanted
|
||||
return (announcement.date > time);
|
||||
});
|
||||
|
||||
return callback(null, announcements);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
SteamCommunity.prototype.postGroupAnnouncement = function(gid, headline, content, callback) {
|
||||
if(typeof gid === 'string') {
|
||||
gid = new SteamID(gid);
|
||||
|
@ -53,11 +53,22 @@ function doLogin(accountName, password, authCode, twoFactorCode) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
rl.question("Annoucement ID: ", function(aid) {
|
||||
rl.question("New title: ", function(header) {
|
||||
rl.question("New body: ", function(content) {
|
||||
// EW THE PYRAMID!
|
||||
editAnnouncement(group, aid, header, content);
|
||||
group.getAllAnnouncements(function(err, announcements) {
|
||||
|
||||
if(announcements.length === 0) {
|
||||
return console.log("This group has no announcements");
|
||||
}
|
||||
|
||||
for (var i = announcements.length - 1; i >= 0; i--) {
|
||||
console.log("[%s] %s %s: %s", announcements[i].date, announcements[i].aid, announcements[i].author, announcements[i].content);
|
||||
};
|
||||
|
||||
rl.question("Annoucement ID: ", function(aid) {
|
||||
rl.question("New title: ", function(header) {
|
||||
rl.question("New body: ", function(content) {
|
||||
// EW THE PYRAMID!
|
||||
editAnnouncement(group, aid, header, content);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user