Made CSteamUser methods available directly on SteamCommunity

This commit is contained in:
Alexander Corn 2015-08-13 23:57:08 -04:00
parent f341dbe72a
commit 3db3d47e92
3 changed files with 147 additions and 105 deletions

View File

@ -107,124 +107,26 @@ CSteamUser.prototype.getAvatarURL = function(size, protocol) {
};
CSteamUser.prototype.addFriend = function(callback) {
var self = this;
this._community.request.post('https://steamcommunity.com/actions/AddFriendAjax', {"form": {"accept_invite": 0, "sessionID": this._community.getSessionID(), "steamid": this.steamID.toString()}}, function(err, response, body) {
if(!callback) {
return;
}
if(self._community._checkHttpError(err, response, callback)) {
return;
}
var json;
try {
json = JSON.parse(body);
} catch(e) {
callback(e);
return;
}
if(json.success) {
callback(null);
} else {
callback(new Error("Unknown error"));
}
});
this._community.addFriend(this.steamID, callback);
};
CSteamUser.prototype.acceptFriendRequest = function(callback) {
var self = this;
this._community.request.post('https://steamcommunity.com/actions/AddFriendAjax', {"form": {"accept_invite": 1, "sessionID": this._community.getSessionID(), "steamid": this.steamID.toString()}}, function(err, response, body) {
if(!callback) {
return;
}
if(self._community._checkHttpError(err, response, callback)) {
return;
}
callback(null);
});
this._community.acceptFriendRequest(this.steamID, callback);
};
CSteamUser.prototype.removeFriend = function(callback) {
var self = this;
this._community.request.post('https://steamcommunity.com/actions/RemoveFriendAjax', {"form": {"sessionID": this._community.getSessionID(), "steamid": this.steamID.toString()}}, function(err, response, body) {
if(!callback) {
return;
}
if(self._community._checkHttpError(err, response, callback)) {
return;
}
callback(null);
});
this._community.removeFriend(this.steamID, callback);
};
CSteamUser.prototype.blockCommunication = function(callback) {
var self = this;
this._community.request.post('https://steamcommunity.com/actions/BlockUserAjax', {"form": {"sessionID": this._community.getSessionID(), "steamid": this.steamID.toString()}}, function(err, response, body) {
if(!callback) {
return;
}
if(self._community._checkHttpError(err, response, callback)) {
return;
}
callback(null);
});
this._community.blockCommunication(this.steamID, callback);
};
CSteamUser.prototype.unblockCommunication = function(callback) {
var form = {"action": "unignore"};
form['friends[' + this.steamID.toString() + ']'] = 1;
this._community._myProfile('friends/blocked/', form, function(err, response, body) {
if(!callback) {
return;
}
if(err || response.statusCode >= 400) {
callback(err || new Error("HTTP error " + response.statusCode));
return;
}
callback(null);
});
this._community.unblockCommunication(this.steamID, callback);
};
CSteamUser.prototype.comment = function(message, callback) {
this._community.request.post('https://steamcommunity.com/comment/Profile/post/' + this.steamID.toString() + '/-1/', {"form": {
"comment": message,
"count": 6,
"sessionid": this._community.getSessionID()
}}, function(err, response, body) {
if(!callback) {
return;
}
if(err || response.statusCode != 200) {
callback(err || new Error("HTTP error " + response.statusCode));
return;
}
var json;
try {
json = JSON.parse(body);
} catch(e) {
callback(e);
return;
}
if(json.success) {
callback(null);
} else if(json.error) {
callback(new Error(json.error));
} else {
callback(new Error("Unknown error"));
}
});
this._community.postUserComment(this.steamID, message, callback);
};

139
components/users.js Normal file
View File

@ -0,0 +1,139 @@
var SteamCommunity = require('../index.js');
SteamCommunity.prototype.addFriend = function(userID, callback) {
var self = this;
this.request.post({
"uri": "https://steamcommunity.com/actions/AddFriendAjax",
"form": {
"accept_invite": 0,
"sessionID": this.getSessionID(),
"steamid": userID.toString()
},
"json": true
}, function(err, response, body) {
if(!callback) {
return;
}
if(self._checkHttpError(err, response, callback)) {
return;
}
if(body.success) {
callback(null);
} else {
callback(new Error("Unknown error"));
}
});
};
SteamCommunity.prototype.acceptFriendRequest = function(userID, callback) {
var self = this;
this.request.post({
"uri": "https://steamcommunity.com/actions/AddFriendAjax",
"form": {
"accept_invite": 1,
"sessionID": this.getSessionID(),
"steamid": userID.toString()
}
}, function(err, response, body) {
if(!callback) {
return;
}
if(self._checkHttpError(err, response, callback)) {
return;
}
callback(null);
});
};
SteamCommunity.prototype.removeFriend = function(userID, callback) {
var self = this;
this.request.post({
"uri": "https://steamcommunity.com/actions/RemoveFriendAjax",
"form": {
"sessionID": this.getSessionID(),
"steamid": userID.toString()
}
}, function(err, response, body) {
if(!callback) {
return;
}
if(self._checkHttpError(err, response, callback)) {
return;
}
callback(null);
});
};
SteamCommunity.prototype.blockCommunication = function(userID, callback) {
var self = this;
this.request.post({
"uri": "https://steamcommunity.com/actions/BlockUserAjax",
"form": {
"sessionID": this.getSessionID(),
"steamid": userID.toString()
}
}, function(err, response, body) {
if(!callback) {
return;
}
if(self._checkHttpError(err, response, callback)) {
return;
}
callback(null);
});
};
SteamCommunity.prototype.unblockCommunication = function(userID, callback) {
var form = {"action": "unignore"};
form['friends[' + userID.toString() + ']'] = 1;
this._myProfile('friends/blocked/', form, function(err, response, body) {
if(!callback) {
return;
}
if(err || response.statusCode >= 400) {
callback(err || new Error("HTTP error " + response.statusCode));
return;
}
callback(null);
});
};
SteamCommunity.prototype.postUserComment = function(userID, message, callback) {
var self = this;
this.request.post({
"uri": "https://steamcommunity.com/comment/Profile/post/" + userID.toString() + "/-1",
"form": {
"comment": message,
"count": 6,
"sessionid": this.getSessionID()
},
"json": true
}, function(err, response, body) {
if(!callback) {
return;
}
if(self._checkHttpError(err, response, callback)) {
return;
}
if(body.success) {
callback(null);
} else if(bpdy.error) {
callback(new Error(body.error));
} else {
callback(new Error("Unknown error"));
}
});
};

View File

@ -322,6 +322,7 @@ require('./components/chat.js');
require('./components/profile.js');
require('./components/market.js');
require('./components/groups.js');
require('./components/users.js');
require('./classes/CMarketItem.js');
require('./classes/CMarketSearchResult.js');
require('./classes/CSteamGroup.js');