Adding ability to edit an annoucement.

Added an example.
This commit is contained in:
Shaun Barratt 2016-01-15 17:48:57 +00:00
parent 7627e6a3a0
commit 4152865f5e
3 changed files with 129 additions and 7 deletions

View File

@ -80,6 +80,10 @@ CSteamGroup.prototype.postAnnouncement = function(headline, content, callback) {
this._community.postGroupAnnouncement(this.steamID, headline, content, callback); this._community.postGroupAnnouncement(this.steamID, headline, content, callback);
}; };
CSteamGroup.prototype.editAnnouncement = function(annoucementID, headline, content, callback) {
this._community.editGroupAnnouncement(this.steamID, annoucementID, headline, content, callback)
};
CSteamGroup.prototype.scheduleEvent = function(name, type, description, time, server, callback) { CSteamGroup.prototype.scheduleEvent = function(name, type, description, time, server, callback) {
this._community.scheduleGroupEvent(this.steamID, name, type, description, time, server, callback); this._community.scheduleGroupEvent(this.steamID, name, type, description, time, server, callback);
}; };

View File

@ -159,6 +159,45 @@ SteamCommunity.prototype.postGroupAnnouncement = function(gid, headline, content
}) })
}; };
SteamCommunity.prototype.editGroupAnnouncement = function(gid, aid, headline, content, callback) {
if(typeof gid === 'string') {
gid = new SteamID(gid);
}
var self = this;
var submitData = {
"uri": "https://steamcommunity.com/gid/" + gid.getSteamID64() + "/announcements",
"form": {
"sessionID": this.getSessionID(),
"gid": aid,
"action": "update",
"headline": headline,
"body": content,
"languages[0][headline]": headline,
"languages[0][body]": content,
"languages[0][updated]": 1
}
}
this.request.post(submitData, 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) { SteamCommunity.prototype.scheduleGroupEvent = function(gid, name, type, description, time, server, callback) {
if(typeof gid === 'string') { if(typeof gid === 'string') {
gid = new SteamID(gid); gid = new SteamID(gid);

View File

@ -0,0 +1,79 @@
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) {
doLogin(accountName, password);
});
});
function doLogin(accountName, password, authCode, twoFactorCode) {
community.login({
"accountName": accountName,
"password": password,
"authCode": authCode,
"twoFactorCode": twoFactorCode
}, function(err, sessionID, cookies, steamguard) {
if(err) {
if(err.message == 'SteamGuardMobile') {
rl.question("Steam Authenticator Code: ", function(code) {
doLogin(accountName, password, null, code);
});
return;
}
if(err.message == 'SteamGuard') {
console.log("An email has been sent to your address at " + err.emaildomain);
rl.question("Steam Guard Code: ", function(code) {
doLogin(accountName, password, code);
});
return;
}
console.log(err);
process.exit();
return;
}
console.log("Logged on!");
rl.question("Group ID: ", function(gid) {
community.getSteamGroup(gid, function(err, group) {
if (err) {
console.log(err);
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);
});
});
});
});
});
});
}
function editAnnouncement(group, aid, header, content) {
// Actual community method.
group.editAnnouncement(aid, header, content, function(error) {
if(!error) {
console.log("Annoucement edited!");
} else {
console.log("Unable to edit annoucement! %j", error);
process.exit(1);
}
});
}