mirror of
https://github.com/DoctorMcKay/node-steamcommunity.git
synced 2026-08-19 13:13:28 +08:00
74 lines
1.6 KiB
JavaScript
74 lines
1.6 KiB
JavaScript
var SteamCommunity = require('../index.js');
|
|
var Cheerio = require('cheerio');
|
|
|
|
SteamCommunity.PrivacyState = {
|
|
"Private": 1,
|
|
"FriendsOnly": 2,
|
|
"Public": 3
|
|
};
|
|
|
|
var CommentPrivacyState = {
|
|
"1": "commentselfonly",
|
|
"2": "commentfriendsonly",
|
|
"3": "commentanyone"
|
|
};
|
|
|
|
SteamCommunity.prototype.profileSettings = function(settings, callback) {
|
|
var self = this;
|
|
this._myProfile("edit/settings", null, function(err, response, body) {
|
|
if(err || response.statusCode != 200) {
|
|
callback(err || new Error("HTTP error " + response.statusCode));
|
|
return;
|
|
}
|
|
|
|
var $ = Cheerio.load(body);
|
|
var form = $('#editForm');
|
|
if(!form) {
|
|
callback(new Error("Malformed response"));
|
|
return;
|
|
}
|
|
|
|
var values = {};
|
|
form.serializeArray().forEach(function(item) {
|
|
values[item.name] = item.value;
|
|
});
|
|
|
|
for(var i in settings) {
|
|
if(!settings.hasOwnProperty(i)) {
|
|
continue;
|
|
}
|
|
|
|
switch(i) {
|
|
case 'profile':
|
|
values.privacySetting = settings[i];
|
|
break;
|
|
|
|
case 'comments':
|
|
values.commentSetting = CommentPrivacyState[settings[i]];
|
|
break;
|
|
|
|
case 'inventory':
|
|
values.inventoryPrivacySetting = settings[i];
|
|
break;
|
|
|
|
case 'inventoryGifts':
|
|
values.inventoryGiftPrivacy = settings[i] ? 1 : 0;
|
|
break;
|
|
|
|
case 'emailConfirmation':
|
|
values.tradeConfirmationSetting = settings[i] ? 1 : 0;
|
|
break;
|
|
}
|
|
}
|
|
|
|
self._myProfile("edit/settings", values, function(err, response, body) {
|
|
if(err || response.statusCode != 200) {
|
|
callback(err || new Error("HTTP error " + response.statusCode));
|
|
return;
|
|
}
|
|
|
|
callback(null);
|
|
});
|
|
});
|
|
};
|