mirror of
https://github.com/DoctorMcKay/node-steamcommunity.git
synced 2025-02-21 00:50:30 +08:00
Merge branch 'master' into v4
# Conflicts: # components/confirmations.js # components/groups.js # components/market.js # package.json
This commit is contained in:
commit
dfd0ccbbc7
2
.github/FUNDING.yml
vendored
Normal file
2
.github/FUNDING.yml
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
github: DoctorMcKay
|
||||
custom: 'https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=N36YVAT42CZ4G&item_name=node%2dsteamcommunity¤cy_code=USD'
|
@ -1,5 +1,5 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default (1)" />
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||
</state>
|
||||
</component>
|
@ -86,7 +86,11 @@ function CEconItem(item, description, contextID) {
|
||||
this.actions = [];
|
||||
}
|
||||
|
||||
delete this.currency;
|
||||
// One wouldn't think that we need this if statement, but apparently v8 has a weird bug/quirk where deleting a
|
||||
// property results in greatly increased memory usage. Because that makes sense.
|
||||
if (this.currency) {
|
||||
delete this.currency;
|
||||
}
|
||||
}
|
||||
|
||||
CEconItem.prototype.getImageURL = function() {
|
||||
|
@ -79,8 +79,8 @@ CSteamGroup.prototype.getAllAnnouncements = function(time, callback) {
|
||||
this._community.getAllGroupAnnouncements(this.steamID, time, callback);
|
||||
};
|
||||
|
||||
CSteamGroup.prototype.postAnnouncement = function(headline, content, callback) {
|
||||
this._community.postGroupAnnouncement(this.steamID, headline, content, callback);
|
||||
CSteamGroup.prototype.postAnnouncement = function(headline, content, hidden, callback) {
|
||||
this._community.postGroupAnnouncement(this.steamID, headline, content, hidden, callback);
|
||||
};
|
||||
|
||||
CSteamGroup.prototype.editAnnouncement = function(annoucementID, headline, content, callback) {
|
||||
|
@ -70,7 +70,13 @@ function CSteamUser(community, userData, customurl) {
|
||||
this.customURL = processItem('customURL', customurl);
|
||||
|
||||
if(this.visibilityState == 3) {
|
||||
this.memberSince = new Date(processItem('memberSince', '0').replace(/(\d{1,2})(st|nd|th)/, "$1"));
|
||||
let memberSinceValue = processItem('memberSince', '0').replace(/(\d{1,2})(st|nd|th)/, "$1");
|
||||
|
||||
if (memberSinceValue.indexOf(',') === -1) {
|
||||
memberSinceValue += ', ' + new Date().getFullYear();
|
||||
}
|
||||
|
||||
this.memberSince = new Date(memberSinceValue);
|
||||
this.location = processItem('location');
|
||||
this.realName = processItem('realname');
|
||||
this.summary = processItem('summary');
|
||||
@ -149,6 +155,14 @@ CSteamUser.prototype.comment = function(message, callback) {
|
||||
this._community.postUserComment(this.steamID, message, callback);
|
||||
};
|
||||
|
||||
CSteamUser.prototype.deleteComment = function(commentID, callback) {
|
||||
this._community.deleteUserComment(this.steamID, commentID, callback);
|
||||
};
|
||||
|
||||
CSteamUser.prototype.getComments = function(options, callback) {
|
||||
this._community.getUserComments(this.steamID, options, callback);
|
||||
};
|
||||
|
||||
CSteamUser.prototype.inviteToGroup = function(groupID, callback) {
|
||||
this._community.inviteUserToGroup(this.steamID, groupID, callback);
|
||||
};
|
||||
@ -178,10 +192,11 @@ CSteamUser.prototype.getInventory = function(appID, contextID, tradableOnly, cal
|
||||
* @param {int} appID - The Steam application ID of the game for which you want an inventory
|
||||
* @param {int} contextID - The ID of the "context" within the game you want to retrieve
|
||||
* @param {boolean} tradableOnly - true to get only tradable items and currencies
|
||||
* @param {string} [language] - The language of item descriptions to return. Omit for default (which may either be English or your account's chosen language)
|
||||
* @param callback
|
||||
*/
|
||||
CSteamUser.prototype.getInventoryContents = function(appID, contextID, tradableOnly, callback) {
|
||||
this._community.getUserInventoryContents(this.steamID, appID, contextID, tradableOnly, callback);
|
||||
CSteamUser.prototype.getInventoryContents = function(appID, contextID, tradableOnly, language, callback) {
|
||||
this._community.getUserInventoryContents(this.steamID, appID, contextID, tradableOnly, language, callback);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -199,7 +199,7 @@ SteamCommunity.prototype.acceptConfirmationForObject = function(identitySecret,
|
||||
setTimeout(() => {
|
||||
// Delete the saved time offset after 12 hours because why not
|
||||
delete this._timeOffset;
|
||||
}, 1000 * 60 * 60 * 12);
|
||||
}, 1000 * 60 * 60 * 12).unref();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -151,23 +151,34 @@ SteamCommunity.prototype.getAllGroupAnnouncements = function(gid, time, callback
|
||||
}, 'steamcommunity');
|
||||
};
|
||||
|
||||
SteamCommunity.prototype.postGroupAnnouncement = function(gid, headline, content, callback) {
|
||||
SteamCommunity.prototype.postGroupAnnouncement = function(gid, headline, content, hidden, callback) {
|
||||
if (typeof gid == 'string') {
|
||||
gid = new SteamID(gid);
|
||||
}
|
||||
|
||||
if (typeof hidden === 'function') {
|
||||
callback = hidden;
|
||||
hidden = false;
|
||||
}
|
||||
|
||||
let form = {
|
||||
"sessionID": this.getSessionID(),
|
||||
"action": "post",
|
||||
"headline": headline,
|
||||
"body": content,
|
||||
"languages[0][headline]": headline,
|
||||
"languages[0][body]": content
|
||||
};
|
||||
|
||||
if (hidden) {
|
||||
form.is_hidden = "is_hidden"
|
||||
}
|
||||
|
||||
this.httpRequestPost({
|
||||
"uri": "https://steamcommunity.com/gid/" + gid.getSteamID64() + "/announcements",
|
||||
"form": {
|
||||
"sessionID": this.getSessionID(),
|
||||
"action": "post",
|
||||
"headline": headline,
|
||||
"body": content,
|
||||
"languages[0][headline]": headline,
|
||||
"languages[0][body]": content
|
||||
}
|
||||
form
|
||||
}, (err, response, body) => {
|
||||
if (!callback) {
|
||||
if(!callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
69
components/help.js
Normal file
69
components/help.js
Normal file
@ -0,0 +1,69 @@
|
||||
const SteamCommunity = require('../index.js');
|
||||
|
||||
const Helpers = require('./helpers.js');
|
||||
|
||||
/**
|
||||
* Restore a previously removed steam package from your steam account.
|
||||
* @param {int|string} packageID
|
||||
* @param {function} callback
|
||||
*/
|
||||
SteamCommunity.prototype.restorePackage = function(packageID, callback) {
|
||||
this.httpRequestPost({
|
||||
"uri": "https://help.steampowered.com/wizard/AjaxDoPackageRestore",
|
||||
"form": {
|
||||
"packageid": packageID,
|
||||
"sessionid": this.getSessionID('https://help.steampowered.com'),
|
||||
"wizard_ajax": 1
|
||||
},
|
||||
"json": true
|
||||
}, (err, res, body) => {
|
||||
if (!callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!body.success) {
|
||||
callback(body.errorMsg ? new Error(body.errorMsg) : Helpers.eresultError(body.success));
|
||||
return;
|
||||
}
|
||||
|
||||
callback(null);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove a steam package from your steam account.
|
||||
* @param {int|string} packageID
|
||||
* @param {function} callback
|
||||
*/
|
||||
SteamCommunity.prototype.removePackage = function(packageID, callback) {
|
||||
this.httpRequestPost({
|
||||
"uri": "https://help.steampowered.com/wizard/AjaxDoPackageRemove",
|
||||
"form": {
|
||||
"packageid": packageID,
|
||||
"sessionid": this.getSessionID('https://help.steampowered.com'),
|
||||
"wizard_ajax": 1
|
||||
},
|
||||
"json": true
|
||||
}, (err, res, body) => {
|
||||
if (!callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!body.success) {
|
||||
callback(body.errorMsg ? new Error(body.errorMsg) : Helpers.eresultError(body.success));
|
||||
return;
|
||||
}
|
||||
|
||||
callback(null);
|
||||
});
|
||||
};
|
@ -1,6 +1,7 @@
|
||||
const Cheerio = require('cheerio');
|
||||
|
||||
const SteamCommunity = require('../index.js');
|
||||
const Helpers = require('./helpers.js');
|
||||
|
||||
/**
|
||||
* Get a list of all apps on the market
|
||||
@ -110,6 +111,43 @@ SteamCommunity.prototype.turnItemIntoGems = function(appid, assetid, expectedGem
|
||||
})
|
||||
};
|
||||
|
||||
/**
|
||||
* Open a booster pack.
|
||||
* @param {int} appid
|
||||
* @param {int|string} assetid
|
||||
* @param {function} callback
|
||||
*/
|
||||
SteamCommunity.prototype.openBoosterPack = function(appid, assetid, callback) {
|
||||
this._myProfile({
|
||||
"endpoint": "ajaxunpackbooster/",
|
||||
"json": true,
|
||||
"checkHttpError": false
|
||||
}, {
|
||||
"appid": appid,
|
||||
"communityitemid": assetid,
|
||||
"sessionid": this.getSessionID()
|
||||
}, (err, res, body) => {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
if (body.success && body.success != SteamCommunity.EResult.OK) {
|
||||
let err = new Error(body.message || SteamCommunity.EResult[body.success]);
|
||||
err.eresult = err.code = body.success;
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!body.rgItems) {
|
||||
callback(new Error("Malformed response"));
|
||||
return;
|
||||
}
|
||||
|
||||
callback(null, body.rgItems);
|
||||
})
|
||||
};
|
||||
|
||||
/**
|
||||
* Get details about a gift in your inventory.
|
||||
* @param {string} giftID
|
||||
@ -167,6 +205,7 @@ SteamCommunity.prototype.redeemGift = function(giftID, callback) {
|
||||
}
|
||||
|
||||
if (body.success && body.success != SteamCommunity.EResult.OK) {
|
||||
|
||||
let err = new Error(body.message || SteamCommunity.EResult[body.success]);
|
||||
err.eresult = err.code = body.success;
|
||||
callback(err);
|
||||
@ -176,3 +215,55 @@ SteamCommunity.prototype.redeemGift = function(giftID, callback) {
|
||||
callback(null);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {int|string} assetid
|
||||
* @param {int} denominationIn
|
||||
* @param {int} denominationOut
|
||||
* @param {int} quantityIn
|
||||
* @param {int} quantityOut
|
||||
* @param {function} callback
|
||||
* @private
|
||||
*/
|
||||
SteamCommunity.prototype._gemExchange = function(assetid, denominationIn, denominationOut, quantityIn, quantityOut, callback) {
|
||||
this._myProfile({
|
||||
endpoint: 'ajaxexchangegoo/',
|
||||
json: true,
|
||||
checkHttpError: false
|
||||
}, {
|
||||
appid: 753,
|
||||
assetid,
|
||||
goo_denomination_in: denominationIn,
|
||||
goo_amount_in: quantityIn,
|
||||
goo_denomination_out: denominationOut,
|
||||
goo_amount_out_expected: quantityOut,
|
||||
sessionid: this.getSessionID()
|
||||
}, (err, res, body) => {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
callback(Helpers.eresultError(body.success));
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Pack gems into sack of gems.
|
||||
* @param {int|string} assetid - ID of gem stack you want to pack into sacks
|
||||
* @param {int} desiredSackCount - How many sacks you want. You must have at least this amount * 1000 gems in the stack you're packing
|
||||
* @param {function} callback
|
||||
*/
|
||||
SteamCommunity.prototype.packGemSacks = function(assetid, desiredSackCount, callback) {
|
||||
this._gemExchange(assetid, 1, 1000, desiredSackCount * 1000, desiredSackCount, callback);
|
||||
};
|
||||
|
||||
/**
|
||||
* Unpack sack of gems into gems.
|
||||
* @param {int|string} assetid - ID of sack stack you want to unpack (say that 5 times fast)
|
||||
* @param {int} sacksToUnpack
|
||||
* @param {function} callback
|
||||
*/
|
||||
SteamCommunity.prototype.unpackGemSacks = function(assetid, sacksToUnpack, callback) {
|
||||
this._gemExchange(assetid, 1000, 1, sacksToUnpack, sacksToUnpack * 1000, callback);
|
||||
};
|
||||
|
@ -34,31 +34,45 @@ SteamCommunity.prototype.setupProfile = function(callback) {
|
||||
|
||||
SteamCommunity.prototype.editProfile = function(settings, callback) {
|
||||
var self = this;
|
||||
this._myProfile("edit", null, function(err, response, body) {
|
||||
if(err || response.statusCode != 200) {
|
||||
if(callback) {
|
||||
callback(err || new Error("HTTP error " + response.statusCode));
|
||||
this._myProfile('edit/info', null, function(err, response, body) {
|
||||
if (err || response.statusCode != 200) {
|
||||
if (callback) {
|
||||
callback(err || new Error('HTTP error ' + response.statusCode));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var $ = Cheerio.load(body);
|
||||
var form = $('#editForm');
|
||||
if(!form) {
|
||||
if(callback) {
|
||||
callback(new Error("Malformed response"));
|
||||
var existingSettings = $('#profile_edit_config').data('profile-edit');
|
||||
if (!existingSettings || !existingSettings.strPersonaName) {
|
||||
if (callback) {
|
||||
callback(new Error('Malformed response'));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var values = {};
|
||||
form.serializeArray().forEach(function(item) {
|
||||
values[item.name] = item.value;
|
||||
});
|
||||
var values = {
|
||||
sessionID: self.getSessionID(),
|
||||
type: 'profileSave',
|
||||
weblink_1_title: '',
|
||||
weblink_1_url: '',
|
||||
weblink_2_title: '',
|
||||
weblink_2_url: '',
|
||||
weblink_3_title: '',
|
||||
weblink_3_url: '',
|
||||
personaName: existingSettings.strPersonaName,
|
||||
real_name: existingSettings.strRealName,
|
||||
summary: existingSettings.strSummary,
|
||||
country: existingSettings.LocationData.locCountryCode,
|
||||
state: existingSettings.LocationData.locStateCode,
|
||||
city: existingSettings.LocationData.locCityCode,
|
||||
customURL: existingSettings.strCustomURL,
|
||||
json: 1
|
||||
};
|
||||
|
||||
for(var i in settings) {
|
||||
for (var i in settings) {
|
||||
if(!settings.hasOwnProperty(i)) {
|
||||
continue;
|
||||
}
|
||||
@ -92,6 +106,8 @@ SteamCommunity.prototype.editProfile = function(settings, callback) {
|
||||
values.customURL = settings[i];
|
||||
break;
|
||||
|
||||
// These don't work right now
|
||||
/*
|
||||
case 'background':
|
||||
// The assetid of our desired profile background
|
||||
values.profile_background = settings[i];
|
||||
@ -110,60 +126,55 @@ SteamCommunity.prototype.editProfile = function(settings, callback) {
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
*/
|
||||
// TODO: profile showcases
|
||||
}
|
||||
}
|
||||
|
||||
self._myProfile("edit", values, function(err, response, body) {
|
||||
self._myProfile('edit', values, function(err, response, body) {
|
||||
if (settings.customURL) {
|
||||
delete self._profileURL;
|
||||
}
|
||||
|
||||
if(err || response.statusCode != 200) {
|
||||
if(callback) {
|
||||
callback(err || new Error("HTTP error " + response.statusCode));
|
||||
}
|
||||
|
||||
if (!callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check for an error
|
||||
var $ = Cheerio.load(body);
|
||||
var error = $('#errorText .formRowFields');
|
||||
if(error) {
|
||||
error = error.text().trim();
|
||||
if(error) {
|
||||
if(callback) {
|
||||
callback(new Error(error));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
if (err || response.statusCode != 200) {
|
||||
callback(err || new Error('HTTP error ' + response.statusCode));
|
||||
return;
|
||||
}
|
||||
|
||||
if(callback) {
|
||||
try {
|
||||
var json = JSON.parse(body);
|
||||
if (!json.success || json.success != 1) {
|
||||
callback(new Error(json.errmsg || 'Request was not successful'));
|
||||
return;
|
||||
}
|
||||
|
||||
callback(null);
|
||||
} catch (ex) {
|
||||
callback(ex);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
SteamCommunity.prototype.profileSettings = function(settings, callback) {
|
||||
this._myProfile("edit/settings", null, (err, response, body) => {
|
||||
this._myProfile('edit/settings', null, (err, response, body) => {
|
||||
if (err || response.statusCode != 200) {
|
||||
if (callback) {
|
||||
callback(err || new Error("HTTP error " + response.statusCode));
|
||||
callback(err || new Error('HTTP error ' + response.statusCode));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var $ = Cheerio.load(body);
|
||||
var existingSettings = $('.ProfileReactRoot[data-privacysettings]').data('privacysettings');
|
||||
if (!existingSettings) {
|
||||
if(callback) {
|
||||
callback(new Error("Malformed response"));
|
||||
var existingSettings = $('#profile_edit_config').data('profile-edit');
|
||||
if (!existingSettings || !existingSettings.Privacy) {
|
||||
if (callback) {
|
||||
callback(new Error('Malformed response'));
|
||||
}
|
||||
|
||||
return;
|
||||
@ -171,8 +182,8 @@ SteamCommunity.prototype.profileSettings = function(settings, callback) {
|
||||
|
||||
// PrivacySettings => {PrivacyProfile, PrivacyInventory, PrivacyInventoryGifts, PrivacyOwnedGames, PrivacyPlaytime}
|
||||
// eCommentPermission
|
||||
var privacy = existingSettings.PrivacySettings;
|
||||
var commentPermission = existingSettings.eCommentPermission;
|
||||
var privacy = existingSettings.Privacy.PrivacySettings;
|
||||
var commentPermission = existingSettings.Privacy.eCommentPermission;
|
||||
|
||||
for (var i in settings) {
|
||||
if (!settings.hasOwnProperty(i)) {
|
||||
@ -211,18 +222,18 @@ SteamCommunity.prototype.profileSettings = function(settings, callback) {
|
||||
}
|
||||
|
||||
this._myProfile({
|
||||
"method": "POST",
|
||||
"endpoint": "ajaxsetprivacy/",
|
||||
"json": true,
|
||||
"formData": { // it's multipart because lolvalve
|
||||
"sessionid": this.getSessionID(),
|
||||
"Privacy": JSON.stringify(privacy),
|
||||
"eCommentPermission": commentPermission
|
||||
method: 'POST',
|
||||
endpoint: 'ajaxsetprivacy/',
|
||||
json: true,
|
||||
formData: { // it's multipart because lolvalve
|
||||
sessionid: this.getSessionID(),
|
||||
Privacy: JSON.stringify(privacy),
|
||||
eCommentPermission: commentPermission
|
||||
}
|
||||
}, null, function(err, response, body) {
|
||||
if (err || response.statusCode != 200) {
|
||||
if (callback) {
|
||||
callback(err || new Error("HTTP error " + response.statusCode));
|
||||
callback(err || new Error('HTTP error ' + response.statusCode));
|
||||
}
|
||||
|
||||
return;
|
||||
@ -230,7 +241,7 @@ SteamCommunity.prototype.profileSettings = function(settings, callback) {
|
||||
|
||||
if (body.success != 1) {
|
||||
if (callback) {
|
||||
callback(new Error(body.success ? "Error " + body.success : "Request was not successful"));
|
||||
callback(new Error(body.success ? 'Error ' + body.success : 'Request was not successful'));
|
||||
}
|
||||
|
||||
return;
|
||||
|
@ -136,7 +136,7 @@ SteamCommunity.prototype.postUserComment = function(userID, message, callback) {
|
||||
"uri": "https://steamcommunity.com/comment/Profile/post/" + userID.toString() + "/-1",
|
||||
"form": {
|
||||
"comment": message,
|
||||
"count": 6,
|
||||
"count": 1,
|
||||
"sessionid": this.getSessionID()
|
||||
},
|
||||
"json": true
|
||||
@ -151,9 +151,109 @@ SteamCommunity.prototype.postUserComment = function(userID, message, callback) {
|
||||
}
|
||||
|
||||
if(body.success) {
|
||||
const $ = Cheerio.load(body.comments_html);
|
||||
const commentID = $('.commentthread_comment').attr('id').split('_')[1];
|
||||
|
||||
callback(null, commentID);
|
||||
} else if(body.error) {
|
||||
callback(new Error(body.error));
|
||||
} else {
|
||||
callback(new Error("Unknown error"));
|
||||
}
|
||||
}, "steamcommunity");
|
||||
};
|
||||
|
||||
SteamCommunity.prototype.deleteUserComment = function(userID, commentID, callback) {
|
||||
if(typeof userID === 'string') {
|
||||
userID = new SteamID(userID);
|
||||
}
|
||||
|
||||
var self = this;
|
||||
this.httpRequestPost({
|
||||
"uri": "https://steamcommunity.com/comment/Profile/delete/" + userID.toString() + "/-1",
|
||||
"form": {
|
||||
"gidcomment": commentID,
|
||||
"start": 0,
|
||||
"count": 1,
|
||||
"sessionid": this.getSessionID(),
|
||||
"feature2": -1
|
||||
},
|
||||
"json": true
|
||||
}, function(err, response, body) {
|
||||
if(!callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
if(body.success && !body.comments_html.includes(commentID)) {
|
||||
callback(null);
|
||||
} else if(body.error) {
|
||||
callback(new Error(body.error));
|
||||
} else if(body.comments_html.includes(commentID)) {
|
||||
callback(new Error("Failed to delete comment"));
|
||||
} else {
|
||||
callback(new Error("Unknown error"));
|
||||
}
|
||||
}, "steamcommunity");
|
||||
};
|
||||
|
||||
SteamCommunity.prototype.getUserComments = function(userID, options, callback) {
|
||||
if(typeof userID === 'string') {
|
||||
userID = new SteamID(userID);
|
||||
}
|
||||
|
||||
if (typeof options === 'function') {
|
||||
callback = options;
|
||||
options = {};
|
||||
}
|
||||
|
||||
var form = Object.assign({
|
||||
"start": 0,
|
||||
"count": 0,
|
||||
"feature2": -1,
|
||||
"sessionid": this.getSessionID()
|
||||
}, options);
|
||||
|
||||
this.httpRequestPost({
|
||||
"uri": "https://steamcommunity.com/comment/Profile/render/" + userID.toString() + "/-1",
|
||||
"form": form,
|
||||
"json": true
|
||||
}, function(err, response, body) {
|
||||
if(!callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
if(body.success) {
|
||||
const $ = Cheerio.load(body.comments_html);
|
||||
const comments = $(".commentthread_comment.responsive_body_text[id]").map((i, elem) => {
|
||||
var $elem = $(elem),
|
||||
$commentContent = $elem.find(".commentthread_comment_text");
|
||||
return {
|
||||
id: $elem.attr("id").split("_")[1],
|
||||
author: {
|
||||
steamID: new SteamID("[U:1:" + $elem.find("[data-miniprofile]").data("miniprofile") + "]"),
|
||||
name: $elem.find("bdi").text(),
|
||||
avatar: $elem.find(".playerAvatar img[src]").attr("src"),
|
||||
state: $elem.find(".playerAvatar").attr("class").split(" ").pop()
|
||||
},
|
||||
date: new Date($elem.find(".commentthread_comment_timestamp").data("timestamp") * 1000),
|
||||
text: $commentContent.text().trim(),
|
||||
html: $commentContent.html().trim()
|
||||
}
|
||||
}).get();
|
||||
|
||||
callback(null, comments, body.total_count);
|
||||
} else if(body.error) {
|
||||
callback(new Error(body.error));
|
||||
} else {
|
||||
callback(new Error("Unknown error"));
|
||||
}
|
||||
@ -552,6 +652,8 @@ SteamCommunity.prototype.sendImageToUser = function(userID, imageContentsBuffer,
|
||||
imageHash.update(imageContentsBuffer);
|
||||
imageHash = imageHash.digest('hex');
|
||||
|
||||
var filename = Date.now() + '_image.' + imageDetails.type;
|
||||
|
||||
this.httpRequestPost({
|
||||
uri: 'https://steamcommunity.com/chat/beginfileupload/?l=english',
|
||||
headers: {
|
||||
@ -561,7 +663,7 @@ SteamCommunity.prototype.sendImageToUser = function(userID, imageContentsBuffer,
|
||||
sessionid: this.getSessionID(),
|
||||
l: 'english',
|
||||
file_size: imageContentsBuffer.length,
|
||||
file_name: 'image.' + imageDetails.type,
|
||||
file_name: filename,
|
||||
file_sha: imageHash,
|
||||
file_image_width: imageDetails.width,
|
||||
file_image_height: imageDetails.height,
|
||||
@ -623,7 +725,7 @@ SteamCommunity.prototype.sendImageToUser = function(userID, imageContentsBuffer,
|
||||
formData: { // it's multipart again
|
||||
sessionid: this.getSessionID(),
|
||||
l: 'english',
|
||||
file_name: 'image.' + imageDetails.type,
|
||||
file_name: filename,
|
||||
file_sha: imageHash,
|
||||
success: '1',
|
||||
ugcid: startResult.ugcid,
|
||||
|
@ -49,25 +49,9 @@ SteamCommunity.prototype.getWebApiKey = function(domain, callback) {
|
||||
* @param {function} callback
|
||||
*/
|
||||
SteamCommunity.prototype.getWebApiOauthToken = function(callback) {
|
||||
var self = this;
|
||||
|
||||
if( this.oAuthToken ) {
|
||||
return callback( null, this.oAuthToken );
|
||||
if (this.oAuthToken) {
|
||||
return callback(null, this.oAuthToken);
|
||||
}
|
||||
|
||||
// Pull an oauth token from the webchat UI
|
||||
this.httpRequest("https://steamcommunity.com/chat", function(err, response, body) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
var match = body.match(/"([0-9a-f]{32})"/);
|
||||
if (!match) {
|
||||
callback(new Error("Malformed response"));
|
||||
return;
|
||||
}
|
||||
|
||||
callback(null, match[1]);
|
||||
}, "steamcommunity");
|
||||
callback(new Error('This operation requires an OAuth token, which can only be obtained from node-steamcommunity\'s `login` method.'));
|
||||
};
|
||||
|
@ -1,18 +1,19 @@
|
||||
var SteamCommunity = require('../index.js');
|
||||
var ReadLine = require('readline');
|
||||
var fs = require('fs');
|
||||
// If you aren't running this script inside of the repository, replace the following line with:
|
||||
// const SteamCommunity = require('steamcommunity');
|
||||
const SteamCommunity = require('../index.js');
|
||||
const ReadLine = require('readline');
|
||||
|
||||
var community = new SteamCommunity();
|
||||
var rl = ReadLine.createInterface({
|
||||
"input": process.stdin,
|
||||
"output": process.stdout
|
||||
let community = new SteamCommunity();
|
||||
let rl = ReadLine.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout
|
||||
});
|
||||
|
||||
rl.question("Username: ", function(accountName) {
|
||||
rl.question("Password: ", function(password) {
|
||||
rl.question("Two-Factor Auth Code: ", function(authCode) {
|
||||
rl.question("Revocation Code: R", function(rCode) {
|
||||
doLogin(accountName, password, authCode, "", rCode);
|
||||
rl.question('Username: ', (accountName) => {
|
||||
rl.question('Password: ', (password) => {
|
||||
rl.question('Two-Factor Auth Code: ', (authCode) =>{
|
||||
rl.question('Revocation Code: R', (rCode) => {
|
||||
doLogin(accountName, password, authCode, '', rCode);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -20,21 +21,21 @@ rl.question("Username: ", function(accountName) {
|
||||
|
||||
function doLogin(accountName, password, authCode, captcha, rCode) {
|
||||
community.login({
|
||||
"accountName": accountName,
|
||||
"password": password,
|
||||
"twoFactorCode": authCode,
|
||||
"captcha": captcha
|
||||
}, function(err, sessionID, cookies, steamguard) {
|
||||
if(err) {
|
||||
if(err.message == 'SteamGuard') {
|
||||
console.log("This account does not have two-factor authentication enabled.");
|
||||
accountName: accountName,
|
||||
password: password,
|
||||
twoFactorCode: authCode,
|
||||
captcha: captcha
|
||||
}, (err, sessionID, cookies, steamguard) => {
|
||||
if (err) {
|
||||
if (err.message == 'SteamGuard') {
|
||||
console.log('This account does not have two-factor authentication enabled.');
|
||||
process.exit();
|
||||
return;
|
||||
}
|
||||
|
||||
if(err.message == 'CAPTCHA') {
|
||||
if (err.message == 'CAPTCHA') {
|
||||
console.log(err.captchaurl);
|
||||
rl.question("CAPTCHA: ", function(captchaInput) {
|
||||
rl.question('CAPTCHA: ', (captchaInput) => {
|
||||
doLogin(accountName, password, authCode, captchaInput);
|
||||
});
|
||||
|
||||
@ -46,15 +47,15 @@ function doLogin(accountName, password, authCode, captcha, rCode) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("Logged on!");
|
||||
community.disableTwoFactor("R" + rCode, function(err) {
|
||||
if(err) {
|
||||
console.log('Logged on!');
|
||||
community.disableTwoFactor('R' + rCode, (err) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
process.exit();
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("Two-factor authentication disabled!");
|
||||
console.log('Two-factor authentication disabled!');
|
||||
process.exit();
|
||||
});
|
||||
});
|
||||
|
@ -1,45 +1,49 @@
|
||||
var SteamCommunity = require('../index.js');
|
||||
var ReadLine = require('readline');
|
||||
var fs = require('fs');
|
||||
// If you aren't running this script inside of the repository, replace the following line with:
|
||||
// const SteamCommunity = require('steamcommunity');
|
||||
const SteamCommunity = require('../index.js');
|
||||
const ReadLine = require('readline');
|
||||
const FS = require('fs');
|
||||
|
||||
var community = new SteamCommunity();
|
||||
var rl = ReadLine.createInterface({
|
||||
"input": process.stdin,
|
||||
"output": process.stdout
|
||||
const EResult = SteamCommunity.EResult;
|
||||
|
||||
let community = new SteamCommunity();
|
||||
let rl = ReadLine.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout
|
||||
});
|
||||
|
||||
rl.question("Username: ", function(accountName) {
|
||||
rl.question("Password: ", function(password) {
|
||||
rl.question('Username: ', (accountName) => {
|
||||
rl.question('Password: ', (password) => {
|
||||
doLogin(accountName, password);
|
||||
});
|
||||
});
|
||||
|
||||
function doLogin(accountName, password, authCode, captcha) {
|
||||
community.login({
|
||||
"accountName": accountName,
|
||||
"password": password,
|
||||
"authCode": authCode,
|
||||
"captcha": captcha
|
||||
}, function(err, sessionID, cookies, steamguard) {
|
||||
if(err) {
|
||||
if(err.message == 'SteamGuardMobile') {
|
||||
console.log("This account already has two-factor authentication enabled.");
|
||||
accountName: accountName,
|
||||
password: password,
|
||||
authCode: authCode,
|
||||
captcha: captcha
|
||||
}, (err, sessionID, cookies, steamguard) => {
|
||||
if (err) {
|
||||
if (err.message == 'SteamGuardMobile') {
|
||||
console.log('This account already has two-factor authentication enabled.');
|
||||
process.exit();
|
||||
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) {
|
||||
if (err.message == 'SteamGuard') {
|
||||
console.log(`An email has been sent to your address at ${err.emaildomain}`);
|
||||
rl.question('Steam Guard Code: ', (code) => {
|
||||
doLogin(accountName, password, code);
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(err.message == 'CAPTCHA') {
|
||||
if (err.message == 'CAPTCHA') {
|
||||
console.log(err.captchaurl);
|
||||
rl.question("CAPTCHA: ", function(captchaInput) {
|
||||
rl.question('CAPTCHA: ', (captchaInput) => {
|
||||
doLogin(accountName, password, authCode, captchaInput);
|
||||
});
|
||||
|
||||
@ -51,17 +55,17 @@ function doLogin(accountName, password, authCode, captcha) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("Logged on!");
|
||||
community.enableTwoFactor(function(err, response) {
|
||||
if(err) {
|
||||
if(err.eresult == 2) {
|
||||
console.log("Error: Failed to enable two-factor authentication. Do you have a phone number attached to your account?");
|
||||
console.log('Logged on!');
|
||||
community.enableTwoFactor((err, response) => {
|
||||
if (err) {
|
||||
if (err.eresult == EResult.Fail) {
|
||||
console.log('Error: Failed to enable two-factor authentication. Do you have a phone number attached to your account?');
|
||||
process.exit();
|
||||
return;
|
||||
}
|
||||
|
||||
if(err.eresult == 84) {
|
||||
console.log("Error: RateLimitExceeded. Try again later.");
|
||||
if (err.eresult == EResult.RateLimitExceeded) {
|
||||
console.log('Error: RateLimitExceeded. Try again later.');
|
||||
process.exit();
|
||||
return;
|
||||
}
|
||||
@ -71,15 +75,16 @@ function doLogin(accountName, password, authCode, captcha) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(response.status != 1) {
|
||||
console.log("Error: Status " + response.status);
|
||||
if (response.status != EResult.OK) {
|
||||
console.log(`Error: Status ${response.status}`);
|
||||
process.exit();
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("Writing secrets to twofactor_" + community.steamID.getSteamID64() + ".json");
|
||||
console.log("Revocation code: " + response.revocation_code);
|
||||
fs.writeFileSync("twofactor_" + community.steamID.getSteamID64() + ".json", JSON.stringify(response, null, "\t"));
|
||||
let filename = `twofactor_${community.steamID.getSteamID64()}.json`;
|
||||
console.log(`Writing secrets to ${filename}`);
|
||||
console.log(`Revocation code: ${response.revocation_code}`);
|
||||
FS.writeFileSync(filename, JSON.stringify(response, null, '\t'));
|
||||
|
||||
promptActivationCode(response);
|
||||
});
|
||||
@ -87,10 +92,10 @@ function doLogin(accountName, password, authCode, captcha) {
|
||||
}
|
||||
|
||||
function promptActivationCode(response) {
|
||||
rl.question("SMS Code: ", function(smsCode) {
|
||||
community.finalizeTwoFactor(response.shared_secret, smsCode, function(err) {
|
||||
if(err) {
|
||||
if(err.message == "Invalid activation code") {
|
||||
rl.question('SMS Code: ', (smsCode) => {
|
||||
community.finalizeTwoFactor(response.shared_secret, smsCode, (err) => {
|
||||
if (err) {
|
||||
if (err.message == 'Invalid activation code') {
|
||||
console.log(err);
|
||||
promptActivationCode(response);
|
||||
return;
|
||||
@ -98,7 +103,7 @@ function promptActivationCode(response) {
|
||||
|
||||
console.log(err);
|
||||
} else {
|
||||
console.log("Two-factor authentication enabled!");
|
||||
console.log('Two-factor authentication enabled!');
|
||||
}
|
||||
|
||||
process.exit();
|
||||
|
41
index.js
41
index.js
@ -16,6 +16,7 @@ module.exports = SteamCommunity;
|
||||
SteamCommunity.SteamID = SteamID;
|
||||
SteamCommunity.ConfirmationType = require('./resources/EConfirmationType.js');
|
||||
SteamCommunity.EResult = require('./resources/EResult.js');
|
||||
SteamCommunity.EFriendRelationship = require('./resources/EFriendRelationship.js');
|
||||
|
||||
|
||||
function SteamCommunity(options) {
|
||||
@ -305,8 +306,8 @@ SteamCommunity.prototype.setCookies = function(cookies) {
|
||||
});
|
||||
};
|
||||
|
||||
SteamCommunity.prototype.getSessionID = function() {
|
||||
var cookies = this._jar.getCookieString("http://steamcommunity.com").split(';');
|
||||
SteamCommunity.prototype.getSessionID = function(host = "http://steamcommunity.com") {
|
||||
var cookies = this._jar.getCookieString(host).split(';');
|
||||
for(var i = 0; i < cookies.length; i++) {
|
||||
var match = cookies[i].trim().match(/([^=]+)=(.+)/);
|
||||
if(match[1] == 'sessionid') {
|
||||
@ -325,11 +326,13 @@ function generateSessionID() {
|
||||
|
||||
SteamCommunity.prototype.parentalUnlock = function(pin, callback) {
|
||||
var self = this;
|
||||
var sessionID = self.getSessionID();
|
||||
|
||||
this.httpRequestPost("https://steamcommunity.com/parental/ajaxunlock", {
|
||||
"json": true,
|
||||
"form": {
|
||||
"pin": pin
|
||||
"pin": pin,
|
||||
"sessionid": sessionID
|
||||
}
|
||||
}, function(err, response, body) {
|
||||
if(!callback) {
|
||||
@ -535,6 +538,37 @@ SteamCommunity.prototype._myProfile = function(endpoint, form, callback) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns an object whose keys are 64-bit SteamIDs, and whose values are values from the EFriendRelationship enum.
|
||||
* Therefore, you can deduce your friends or blocked list from this object.
|
||||
* @param {function} callback
|
||||
*/
|
||||
SteamCommunity.prototype.getFriendsList = function(callback) {
|
||||
this.httpRequestGet({
|
||||
"uri": "https://steamcommunity.com/textfilter/ajaxgetfriendslist",
|
||||
"json": true
|
||||
}, (err, res, body) => {
|
||||
if (err) {
|
||||
callback(err ? err : new Error('HTTP error ' + res.statusCode));
|
||||
return;
|
||||
}
|
||||
|
||||
if (body.success != 1) {
|
||||
callback(Helpers.eresultError(body.success));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!body.friendslist || !body.friendslist.friends) {
|
||||
callback(new Error('Malformed response'));
|
||||
return;
|
||||
}
|
||||
|
||||
const friends = {};
|
||||
body.friendslist.friends.forEach(friend => (friends[friend.ulfriendid] = friend.efriendrelationship));
|
||||
callback(null, friends);
|
||||
});
|
||||
};
|
||||
|
||||
require('./components/http.js');
|
||||
require('./components/chat.js');
|
||||
require('./components/profile.js');
|
||||
@ -544,6 +578,7 @@ require('./components/users.js');
|
||||
require('./components/webapi.js');
|
||||
require('./components/twofactor.js');
|
||||
require('./components/confirmations.js');
|
||||
require('./components/help.js');
|
||||
require('./classes/CMarketItem.js');
|
||||
require('./classes/CMarketSearchResult.js');
|
||||
require('./classes/CSteamGroup.js');
|
||||
|
23
resources/EFriendRelationship.js
Normal file
23
resources/EFriendRelationship.js
Normal file
@ -0,0 +1,23 @@
|
||||
/**
|
||||
* @enum EFriendRelationship
|
||||
*/
|
||||
module.exports = {
|
||||
"None": 0,
|
||||
"Blocked": 1,
|
||||
"RequestRecipient": 2,
|
||||
"Friend": 3,
|
||||
"RequestInitiator": 4,
|
||||
"Ignored": 5,
|
||||
"IgnoredFriend": 6,
|
||||
"SuggestedFriend": 7, // removed "was used by the original implementation of the facebook linking feature; but now unused."
|
||||
|
||||
// Value-to-name mapping for convenience
|
||||
"0": "None",
|
||||
"1": "Blocked",
|
||||
"2": "RequestRecipient",
|
||||
"3": "Friend",
|
||||
"4": "RequestInitiator",
|
||||
"5": "Ignored",
|
||||
"6": "IgnoredFriend",
|
||||
"7": "SuggestedFriend",
|
||||
};
|
@ -9,7 +9,7 @@ module.exports = {
|
||||
"Snooze": 4,
|
||||
"LookingToTrade": 5,
|
||||
"LookingToPlay": 6,
|
||||
"Max": 7,
|
||||
"Invisible": 7,
|
||||
|
||||
// Value-to-name mapping for convenience
|
||||
"0": "Offline",
|
||||
@ -19,5 +19,5 @@ module.exports = {
|
||||
"4": "Snooze",
|
||||
"5": "LookingToTrade",
|
||||
"6": "LookingToPlay",
|
||||
"7": "Max",
|
||||
"7": "Invisible",
|
||||
};
|
||||
|
@ -4,7 +4,8 @@
|
||||
module.exports = {
|
||||
"HasRichPresence": 1,
|
||||
"InJoinableGame": 2,
|
||||
"Golden": 4, // removed "no longer has any effect"
|
||||
"Golden": 4,
|
||||
"RemotePlayTogether": 8,
|
||||
"OnlineUsingWeb": 256, // removed "renamed to ClientTypeWeb"
|
||||
"ClientTypeWeb": 256,
|
||||
"OnlineUsingMobile": 512, // removed "renamed to ClientTypeMobile"
|
||||
@ -14,14 +15,18 @@ module.exports = {
|
||||
"OnlineUsingVR": 2048, // removed "renamed to ClientTypeVR"
|
||||
"ClientTypeVR": 2048,
|
||||
"LaunchTypeGamepad": 4096,
|
||||
"LaunchTypeCompatTool": 8192,
|
||||
|
||||
// Value-to-name mapping for convenience
|
||||
"1": "HasRichPresence",
|
||||
"2": "InJoinableGame",
|
||||
"4": "Golden",
|
||||
"8": "RemotePlayTogether",
|
||||
"256": "ClientTypeWeb",
|
||||
"512": "ClientTypeMobile",
|
||||
"1024": "ClientTypeTenfoot",
|
||||
"2048": "ClientTypeVR",
|
||||
"4096": "LaunchTypeGamepad",
|
||||
"8192": "LaunchTypeCompatTool",
|
||||
};
|
||||
|
||||
|
@ -123,6 +123,13 @@ module.exports = {
|
||||
"WGNetworkSendExceeded": 110,
|
||||
"AccountNotFriends": 111,
|
||||
"LimitedUserAccount": 112,
|
||||
"CantRemoveItem": 113,
|
||||
"AccountHasBeenDeleted": 114,
|
||||
"AccountHasAnExistingUserCancelledLicense": 115,
|
||||
"DeniedDueToCommunityCooldown": 116,
|
||||
"NoLauncherSpecified": 117,
|
||||
"MustAgreeToSSA": 118,
|
||||
"ClientNoLongerSupported": 119,
|
||||
|
||||
// Value-to-name mapping for convenience
|
||||
"0": "Invalid",
|
||||
@ -237,4 +244,11 @@ module.exports = {
|
||||
"110": "WGNetworkSendExceeded",
|
||||
"111": "AccountNotFriends",
|
||||
"112": "LimitedUserAccount",
|
||||
"113": "CantRemoveItem",
|
||||
"114": "AccountHasBeenDeleted",
|
||||
"115": "AccountHasAnExistingUserCancelledLicense",
|
||||
"116": "DeniedDueToCommunityCooldown",
|
||||
"117": "NoLauncherSpecified",
|
||||
"118": "MustAgreeToSSA",
|
||||
"119": "ClientNoLongerSupported",
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user