diff --git a/classes/CSteamUser.js b/classes/CSteamUser.js index 5d493fe..e21b3d9 100644 --- a/classes/CSteamUser.js +++ b/classes/CSteamUser.js @@ -130,3 +130,7 @@ CSteamUser.prototype.unblockCommunication = function(callback) { CSteamUser.prototype.comment = function(message, callback) { this._community.postUserComment(this.steamID, message, callback); }; + +CSteamUser.prototype.inviteToGroup = function(groupID, callback) { + this._community.inviteUserToGroup(this.steamID, groupID, callback); +}; diff --git a/components/users.js b/components/users.js index 01718aa..a0f664e 100644 --- a/components/users.js +++ b/components/users.js @@ -1,6 +1,11 @@ var SteamCommunity = require('../index.js'); +var SteamID = require('steamid'); SteamCommunity.prototype.addFriend = function(userID, callback) { + if(typeof userID === 'string') { + userID = new SteamID(userID); + } + var self = this; this.request.post({ "uri": "https://steamcommunity.com/actions/AddFriendAjax", @@ -28,6 +33,10 @@ SteamCommunity.prototype.addFriend = function(userID, callback) { }; SteamCommunity.prototype.acceptFriendRequest = function(userID, callback) { + if(typeof userID === 'string') { + userID = new SteamID(userID); + } + var self = this; this.request.post({ "uri": "https://steamcommunity.com/actions/AddFriendAjax", @@ -50,6 +59,10 @@ SteamCommunity.prototype.acceptFriendRequest = function(userID, callback) { }; SteamCommunity.prototype.removeFriend = function(userID, callback) { + if(typeof userID === 'string') { + userID = new SteamID(userID); + } + var self = this; this.request.post({ "uri": "https://steamcommunity.com/actions/RemoveFriendAjax", @@ -71,6 +84,10 @@ SteamCommunity.prototype.removeFriend = function(userID, callback) { }; SteamCommunity.prototype.blockCommunication = function(userID, callback) { + if(typeof userID === 'string') { + userID = new SteamID(userID); + } + var self = this; this.request.post({ "uri": "https://steamcommunity.com/actions/BlockUserAjax", @@ -92,6 +109,10 @@ SteamCommunity.prototype.blockCommunication = function(userID, callback) { }; SteamCommunity.prototype.unblockCommunication = function(userID, callback) { + if(typeof userID === 'string') { + userID = new SteamID(userID); + } + var form = {"action": "unignore"}; form['friends[' + userID.toString() + ']'] = 1; @@ -110,6 +131,10 @@ SteamCommunity.prototype.unblockCommunication = function(userID, callback) { }; SteamCommunity.prototype.postUserComment = function(userID, message, callback) { + if(typeof userID === 'string') { + userID = new SteamID(userID); + } + var self = this; this.request.post({ "uri": "https://steamcommunity.com/comment/Profile/post/" + userID.toString() + "/-1", @@ -136,4 +161,39 @@ SteamCommunity.prototype.postUserComment = function(userID, message, callback) { callback(new Error("Unknown error")); } }); -}; \ No newline at end of file +}; + +SteamCommunity.prototype.inviteUserToGroup = function(userID, groupID, callback) { + if(typeof userID === 'string') { + userID = new SteamID(userID); + } + + var self = this; + this.request.post({ + "uri": "https://steamcommunity.com/actions/GroupInvite", + "form": { + "group": groupID.toString(), + "invitee": userID.toString(), + "json": 1, + "sessionID": this.getSessionID(), + "type": "groupInvite" + }, + "json": true + }, function(err, response, body) { + if(!callback) { + return; + } + + if(self._checkHttpError(err, response, callback)) { + return; + } + + if(body.results == 'OK') { + callback(null); + } else if(body.results) { + callback(new Error(body.results)); + } else { + callback(new Error("Unknown error")); + } + }); +};