From 27ef78cc4bfd6f781b41284d59944d958259eefd Mon Sep 17 00:00:00 2001 From: Shaun Barratt Date: Sun, 17 Jan 2016 02:27:11 +0000 Subject: [PATCH] Added ability to deleteAnnoucement --- classes/CSteamGroup.js | 4 ++++ components/groups.js | 28 ++++++++++++++++++++++++ examples/edit-group-announcement.js | 33 +++++++++++++++++++++++------ 3 files changed, 58 insertions(+), 7 deletions(-) diff --git a/classes/CSteamGroup.js b/classes/CSteamGroup.js index 9c26b78..7b6801d 100644 --- a/classes/CSteamGroup.js +++ b/classes/CSteamGroup.js @@ -88,6 +88,10 @@ CSteamGroup.prototype.editAnnouncement = function(annoucementID, headline, conte this._community.editGroupAnnouncement(this.steamID, annoucementID, headline, content, callback) }; +CSteamGroup.prototype.deleteAnnouncement = function(annoucementID, headline, content, callback) { + this._community.deleteGroupAnnouncement(this.steamID, annoucementID, headline, content, callback) +}; + CSteamGroup.prototype.scheduleEvent = function(name, type, description, time, server, callback) { this._community.scheduleGroupEvent(this.steamID, name, type, description, time, server, callback); }; diff --git a/components/groups.js b/components/groups.js index 49df825..3b19c46 100644 --- a/components/groups.js +++ b/components/groups.js @@ -246,6 +246,34 @@ SteamCommunity.prototype.editGroupAnnouncement = function(gid, aid, headline, co }) }; +SteamCommunity.prototype.deleteGroupAnnouncement = function(gid, aid, callback) { + if(typeof gid === 'string') { + gid = new SteamID(gid); + } + + var self = this; + + var submitData = { + "uri": "https://steamcommunity.com/gid/" + gid.getSteamID64() + "/announcements/delete/" + aid + "?sessionID=" + this.getSessionID(), + } + + this.request.get(submitData, function(err, response, body) { + if(!callback) { + return; + } + + if(self._checkHttpError(err, response, callback)) { + 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); diff --git a/examples/edit-group-announcement.js b/examples/edit-group-announcement.js index bc4d7d3..4d6fbcc 100644 --- a/examples/edit-group-announcement.js +++ b/examples/edit-group-announcement.js @@ -54,7 +54,7 @@ function doLogin(accountName, password, authCode, twoFactorCode) { } group.getAllAnnouncements(function(err, announcements) { - + if(announcements.length === 0) { return console.log("This group has no announcements"); } @@ -63,12 +63,19 @@ function doLogin(accountName, password, authCode, twoFactorCode) { 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); - }); + rl.question("Would you like to delete delete or edit an annoucement? (Type edit/delete): ", function(choice) { + rl.question("Annoucement ID: ", function(aid) { + if(choice === 'edit') { + rl.question("New title: ", function(header) { + rl.question("New body: ", function(content) { + // EW THE PYRAMID! + // Try replace this with delete! + editAnnouncement(group, aid, header, content); + }); + }); + } else { + deleteAnnouncement(group, aid); + } }); }); }); @@ -88,3 +95,15 @@ function editAnnouncement(group, aid, header, content) { } }); } + +function deleteAnnouncement(group, aid) { + // group.deleteAnnouncement(aid); + // Or + group.deleteAnnouncement(aid, function(err) { + if(!err) { + console.log("Deleted"); + } else { + console.log("Error deleting announcement."); + } + }) +}