mirror of
https://github.com/DoctorMcKay/node-steamcommunity.git
synced 2026-08-19 13:13:28 +08:00
Compare commits
126 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2abc547f49 | ||
|
|
b2bffddfbe | ||
|
|
ab9baeafc6 | ||
|
|
788f34ba7a | ||
|
|
bde2cafaf4 | ||
|
|
36e8c79d87 | ||
|
|
4ca0fc83aa | ||
|
|
2dd5bb490e | ||
|
|
d0da148d6b | ||
|
|
7605dc8a41 | ||
|
|
5f46aee9fc | ||
|
|
02cc5daafe | ||
|
|
e76d34891a | ||
|
|
20ad260d68 | ||
|
|
76f2c55a73 | ||
|
|
77c2811e7e | ||
|
|
37bac4d240 | ||
|
|
d23d7e22c0 | ||
|
|
6e19ffd93b | ||
|
|
e5fbddc00c | ||
|
|
3531560083 | ||
|
|
6fa6a073a8 | ||
|
|
fd872490c8 | ||
|
|
be528d1a19 | ||
|
|
440b2f9ba9 | ||
|
|
e23fa02c91 | ||
|
|
33bc8d83c9 | ||
|
|
f96d25ad52 | ||
|
|
f7d7cf0660 | ||
|
|
27d2daac61 | ||
|
|
4723bd93a6 | ||
|
|
897ad16154 | ||
|
|
81d8dc2a5c | ||
|
|
8538589fef | ||
|
|
c0be17cd61 | ||
|
|
350f6288e4 | ||
|
|
ba2782066d | ||
|
|
d6b0fbd5d0 | ||
|
|
9ec5dcd7b0 | ||
|
|
c8642865a1 | ||
|
|
c92801d25e | ||
|
|
b55516f67f | ||
|
|
f09adc84a4 | ||
|
|
d807f10653 | ||
|
|
18011b3fac | ||
|
|
6f97370710 | ||
|
|
3bcaf40850 | ||
|
|
0ccac69bea | ||
|
|
48d63857e2 | ||
|
|
b11734cd9b | ||
|
|
5c37c38dda | ||
|
|
260bfaa0ad | ||
|
|
1031a4dbd7 | ||
|
|
e28fe5ca05 | ||
|
|
90a9ee1aa9 | ||
|
|
9a069e80fb | ||
|
|
640c47b933 | ||
|
|
f5d65a9ad4 | ||
|
|
7ae8a97a0f | ||
|
|
ec1284e961 | ||
|
|
dc4bb1b554 | ||
|
|
cd90d7a563 | ||
|
|
851c14bd93 | ||
|
|
24a42e9658 | ||
|
|
8ec671d952 | ||
|
|
2821a5900c | ||
|
|
2da6725283 | ||
|
|
23a7940064 | ||
|
|
165c963b1a | ||
|
|
429a76edcc | ||
|
|
3a224ff45f | ||
|
|
dfad525e4e | ||
|
|
81877f4bb7 | ||
|
|
f6a3186865 | ||
|
|
e0687f8828 | ||
|
|
d54dd2c892 | ||
|
|
b4818d6d67 | ||
|
|
d8eb07f046 | ||
|
|
e6995e337e | ||
|
|
2bbdbf36ad | ||
|
|
e6311c0fcb | ||
|
|
2fc8d1f4aa | ||
|
|
b00b871a5b | ||
|
|
15079621d2 | ||
|
|
d91c600eae | ||
|
|
0f98403c16 | ||
|
|
d9b6b55efc | ||
|
|
0fc62d2966 | ||
|
|
5daf5f712a | ||
|
|
737aa9dc41 | ||
|
|
07fb26047b | ||
|
|
2f9b24c447 | ||
|
|
211c625da0 | ||
|
|
2e61a6ed70 | ||
|
|
f0a3cb27f8 | ||
|
|
6ed33a100e | ||
|
|
d41a52638b | ||
|
|
58516d4ed1 | ||
|
|
3f99c718d4 | ||
|
|
b92c5d852d | ||
|
|
f5da011cde | ||
|
|
3633ab032c | ||
|
|
76df74d724 | ||
|
|
8b5cd59021 | ||
|
|
25adcb101b | ||
|
|
d7ecad670d | ||
|
|
8225ea5127 | ||
|
|
59bf4f1e92 | ||
|
|
a3468bf99b | ||
|
|
e299623452 | ||
|
|
29b31009ce | ||
|
|
d4d0d7da26 | ||
|
|
3c8488d441 | ||
|
|
3ea0995415 | ||
|
|
21c4ba3e27 | ||
|
|
4d4df7c2a5 | ||
|
|
aa0d4d32b7 | ||
|
|
444a6d238d | ||
|
|
98373708e5 | ||
|
|
9ed377e843 | ||
|
|
868ce9cdb4 | ||
|
|
8edc5020e1 | ||
|
|
f2be027a63 | ||
|
|
fbfff1398b | ||
|
|
6cd06c3adf | ||
|
|
d35e3c107c |
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'
|
||||
3
.idea/codeStyles/Project.xml
generated
3
.idea/codeStyles/Project.xml
generated
@@ -1,8 +1,5 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<XML>
|
||||
<option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" />
|
||||
</XML>
|
||||
<codeStyleSettings language="JSON">
|
||||
<indentOptions>
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
|
||||
3
.idea/codeStyles/codeStyleConfig.xml
generated
3
.idea/codeStyles/codeStyleConfig.xml
generated
@@ -1,5 +1,6 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default (1)" />
|
||||
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||
</state>
|
||||
</component>
|
||||
3
.idea/modules.xml
generated
3
.idea/modules.xml
generated
@@ -3,6 +3,7 @@
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/steamcommunity.iml" filepath="$PROJECT_DIR$/.idea/steamcommunity.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/../steamcommunity Wiki/.idea/steamcommunity Wiki.iml" filepath="$PROJECT_DIR$/../steamcommunity Wiki/.idea/steamcommunity Wiki.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
</project>
|
||||
|
||||
5
.idea/steamcommunity.iml
generated
5
.idea/steamcommunity.iml
generated
@@ -1,9 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="steamcommunity Wiki" />
|
||||
</component>
|
||||
</module>
|
||||
</module>
|
||||
|
||||
1
.idea/vcs.xml
generated
1
.idea/vcs.xml
generated
@@ -2,5 +2,6 @@
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/../steamcommunity Wiki" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -1,7 +1,6 @@
|
||||
# Steam Community for Node.js
|
||||
[](https://npmjs.com/package/steamcommunity)
|
||||
[](https://npmjs.com/package/steamcommunity)
|
||||
[](https://david-dm.org/DoctorMcKay/node-steamcommunity)
|
||||
[](https://github.com/DoctorMcKay/node-steamcommunity/blob/master/LICENSE)
|
||||
[](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=N36YVAT42CZ4G&item_name=node%2dsteamcommunity¤cy_code=USD)
|
||||
|
||||
@@ -9,8 +8,6 @@ This module provides an easy interface for the Steam Community website. This mod
|
||||
|
||||
It supports Steam Guard and CAPTCHAs.
|
||||
|
||||
This reports anonymous usage statistics to the author. [See here](https://github.com/DoctorMcKay/node-stats-reporter) for more information.
|
||||
|
||||
**Have a question about the module or coding in general? *Do not create a GitHub issue.* GitHub issues are for feature
|
||||
requests and bug reports. Instead, post in the [dedicated forum](https://dev.doctormckay.com/forum/8-node-steamcommunity/).
|
||||
Such issues may be ignored!**
|
||||
|
||||
@@ -3,15 +3,17 @@ var SteamCommunity = require('../index.js');
|
||||
module.exports = CConfirmation;
|
||||
|
||||
function CConfirmation(community, data) {
|
||||
Object.defineProperty(this, "_community", {"value": community});
|
||||
Object.defineProperty(this, '_community', {value: community});
|
||||
|
||||
this.id = data.id;
|
||||
this.id = data.id.toString();
|
||||
this.type = data.type;
|
||||
this.creator = data.creator;
|
||||
this.creator = data.creator.toString();
|
||||
this.key = data.key;
|
||||
this.title = data.title;
|
||||
this.receiving = data.receiving;
|
||||
this.sending = data.sending;
|
||||
this.time = data.time;
|
||||
this.timestamp = data.timestamp;
|
||||
this.icon = data.icon;
|
||||
this.offerID = this.type == SteamCommunity.ConfirmationType.Trade ? this.creator : null;
|
||||
}
|
||||
@@ -19,7 +21,7 @@ function CConfirmation(community, data) {
|
||||
CConfirmation.prototype.getOfferID = function(time, key, callback) {
|
||||
if (this.type && this.creator) {
|
||||
if (this.type != SteamCommunity.ConfirmationType.Trade) {
|
||||
callback(new Error("Not a trade confirmation"));
|
||||
callback(new Error('Not a trade confirmation'));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -66,11 +66,31 @@ function CEconItem(item, description, contextID) {
|
||||
this.market_fee_app = parseInt(match[1], 10);
|
||||
}
|
||||
|
||||
// Restore cache_expiration, if we can (for CS:GO items)
|
||||
if (this.appid == 730 && this.contextid == 2 && this.owner_descriptions) {
|
||||
let description = this.owner_descriptions.find(d => d.value && d.value.indexOf('Tradable After ') == 0);
|
||||
if (description) {
|
||||
let date = new Date(description.value.substring(15).replace(/[,()]/g, ''));
|
||||
if (date) {
|
||||
this.cache_expiration = date.toISOString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If we have item_expiration, also set cache_expiration to the same value
|
||||
if (this.item_expiration) {
|
||||
this.cache_expiration = this.item_expiration;
|
||||
}
|
||||
|
||||
if (this.actions === "") {
|
||||
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() {
|
||||
|
||||
@@ -78,8 +78,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) {
|
||||
|
||||
221
classes/CSteamSharedFile.js
Normal file
221
classes/CSteamSharedFile.js
Normal file
@@ -0,0 +1,221 @@
|
||||
const Cheerio = require('cheerio');
|
||||
const SteamID = require('steamid');
|
||||
|
||||
const SteamCommunity = require('../index.js');
|
||||
const Helpers = require('../components/helpers.js');
|
||||
|
||||
const ESharedFileType = require('../resources/ESharedFileType.js');
|
||||
|
||||
|
||||
/**
|
||||
* Scrape a sharedfile's DOM to get all available information
|
||||
* @param {string} sharedFileId - ID of the sharedfile
|
||||
* @param {function} callback - First argument is null/Error, second is object containing all available information
|
||||
*/
|
||||
SteamCommunity.prototype.getSteamSharedFile = function(sharedFileId, callback) {
|
||||
// Construct object holding all the data we can scrape
|
||||
let sharedfile = {
|
||||
id: sharedFileId,
|
||||
type: null,
|
||||
appID: null,
|
||||
owner: null,
|
||||
fileSize: null,
|
||||
postDate: null,
|
||||
resolution: null,
|
||||
uniqueVisitorsCount: null,
|
||||
favoritesCount: null,
|
||||
upvoteCount: null,
|
||||
guideNumRatings: null,
|
||||
isUpvoted: null,
|
||||
isDownvoted: null
|
||||
};
|
||||
|
||||
// Get DOM of sharedfile
|
||||
this.httpRequestGet(`https://steamcommunity.com/sharedfiles/filedetails/?id=${sharedFileId}`, (err, res, body) => {
|
||||
try {
|
||||
|
||||
/* --------------------- Preprocess output --------------------- */
|
||||
|
||||
// Load output into cheerio to make parsing easier
|
||||
let $ = Cheerio.load(body);
|
||||
|
||||
// Dynamically map detailsStatsContainerLeft to detailsStatsContainerRight in an object to make readout easier. It holds size, post date and resolution.
|
||||
let detailsStatsObj = {};
|
||||
let detailsLeft = $(".detailsStatsContainerLeft").children();
|
||||
let detailsRight = $(".detailsStatsContainerRight").children();
|
||||
|
||||
Object.keys(detailsLeft).forEach((e) => { // Dynamically get all details. Don't hardcore so that this also works for guides.
|
||||
if (isNaN(e)) {
|
||||
return; // Ignore invalid entries
|
||||
}
|
||||
|
||||
detailsStatsObj[detailsLeft[e].children[0].data.trim()] = detailsRight[e].children[0].data;
|
||||
});
|
||||
|
||||
// Dynamically map stats_table descriptions to values. This holds Unique Visitors and Current Favorites
|
||||
let statsTableObj = {};
|
||||
let statsTable = $(".stats_table").children();
|
||||
|
||||
Object.keys(statsTable).forEach((e) => {
|
||||
if (isNaN(e)) {
|
||||
return; // Ignore invalid entries
|
||||
}
|
||||
|
||||
// Value description is at index 3, value data at index 1
|
||||
statsTableObj[statsTable[e].children[3].children[0].data] = statsTable[e].children[1].children[0].data.replace(/,/g, ""); // Remove commas from 1k+ values
|
||||
});
|
||||
|
||||
|
||||
/* --------------------- Find and map values --------------------- */
|
||||
|
||||
// Find appID in share button onclick event
|
||||
sharedfile.appID = Number($("#ShareItemBtn").attr()["onclick"].replace(`ShowSharePublishedFilePopup( '${sharedFileId}', '`, "").replace("' );", ""));
|
||||
|
||||
|
||||
// Find fileSize if not guide
|
||||
sharedfile.fileSize = detailsStatsObj["File Size"] || null; // TODO: Convert to bytes? It seems like to always be MB but no guarantee
|
||||
|
||||
|
||||
// Find postDate and convert to timestamp
|
||||
let posted = detailsStatsObj["Posted"].trim();
|
||||
|
||||
sharedfile.postDate = Helpers.decodeSteamTime(posted);
|
||||
|
||||
|
||||
// Find resolution if artwork or screenshot
|
||||
sharedfile.resolution = detailsStatsObj["Size"] || null;
|
||||
|
||||
|
||||
// Find uniqueVisitorsCount. We can't use ' || null' here as Number("0") casts to false
|
||||
if (statsTableObj["Unique Visitors"]) {
|
||||
sharedfile.uniqueVisitorsCount = Number(statsTableObj["Unique Visitors"]);
|
||||
}
|
||||
|
||||
|
||||
// Find favoritesCount. We can't use ' || null' here as Number("0") casts to false
|
||||
if (statsTableObj["Current Favorites"]) {
|
||||
sharedfile.favoritesCount = Number(statsTableObj["Current Favorites"]);
|
||||
}
|
||||
|
||||
|
||||
// Find upvoteCount. We can't use ' || null' here as Number("0") casts to false
|
||||
let upvoteCount = $("#VotesUpCountContainer > #VotesUpCount").text();
|
||||
|
||||
if (upvoteCount) {
|
||||
sharedfile.upvoteCount = Number(upvoteCount);
|
||||
}
|
||||
|
||||
|
||||
// Find numRatings if this is a guide as they use a different voting system
|
||||
let numRatings = $(".ratingSection > .numRatings").text().replace(" ratings", "");
|
||||
|
||||
sharedfile.guideNumRatings = Number(numRatings) || null; // Set to null if not a guide or if the guide does not have enough ratings to show a value
|
||||
|
||||
|
||||
// Determine if this account has already voted on this sharedfile
|
||||
sharedfile.isUpvoted = String($(".workshopItemControlCtn > #VoteUpBtn")[0].attribs["class"]).includes("toggled"); // Check if upvote btn class contains "toggled"
|
||||
sharedfile.isDownvoted = String($(".workshopItemControlCtn > #VoteDownBtn")[0].attribs["class"]).includes("toggled"); // Check if downvote btn class contains "toggled"
|
||||
|
||||
|
||||
// Determine type by looking at the second breadcrumb. Find the first separator as it has a unique name and go to the next element which holds our value of interest
|
||||
let breadcrumb = $(".breadcrumbs > .breadcrumb_separator").next().get(0).children[0].data || "";
|
||||
|
||||
if (breadcrumb.includes("Screenshot")) {
|
||||
sharedfile.type = ESharedFileType.Screenshot;
|
||||
}
|
||||
|
||||
if (breadcrumb.includes("Artwork")) {
|
||||
sharedfile.type = ESharedFileType.Artwork;
|
||||
}
|
||||
|
||||
if (breadcrumb.includes("Guide")) {
|
||||
sharedfile.type = ESharedFileType.Guide;
|
||||
}
|
||||
|
||||
|
||||
// Find owner profile link, convert to steamID64 using SteamIdResolver lib and create a SteamID object
|
||||
let ownerHref = $(".friendBlockLinkOverlay").attr()["href"];
|
||||
|
||||
Helpers.resolveVanityURL(ownerHref, (err, data) => { // This request takes <1 sec
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
sharedfile.owner = new SteamID(data.steamID);
|
||||
|
||||
// Make callback when ID was resolved as otherwise owner will always be null
|
||||
callback(null, new CSteamSharedFile(this, sharedfile));
|
||||
});
|
||||
|
||||
} catch (err) {
|
||||
callback(err, null);
|
||||
}
|
||||
}, "steamcommunity");
|
||||
};
|
||||
|
||||
/**
|
||||
* Constructor - Creates a new SharedFile object
|
||||
* @class
|
||||
* @param {SteamCommunity} community
|
||||
* @param {{ id: string, type: ESharedFileType, appID: number, owner: SteamID|null, fileSize: string|null, postDate: number, resolution: string|null, uniqueVisitorsCount: number, favoritesCount: number, upvoteCount: number|null, guideNumRatings: Number|null, isUpvoted: boolean, isDownvoted: boolean }} data
|
||||
*/
|
||||
function CSteamSharedFile(community, data) {
|
||||
/**
|
||||
* @type {SteamCommunity}
|
||||
*/
|
||||
this._community = community;
|
||||
|
||||
// Clone all the data we received
|
||||
Object.assign(this, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a comment from this sharedfile's comment section
|
||||
* @param {String} cid - ID of the comment to delete
|
||||
* @param {function} callback - Takes only an Error object/null as the first argument
|
||||
*/
|
||||
CSteamSharedFile.prototype.deleteComment = function(cid, callback) {
|
||||
this._community.deleteSharedFileComment(this.owner, this.id, cid, callback);
|
||||
};
|
||||
|
||||
/**
|
||||
* Favorites this sharedfile
|
||||
* @param {function} callback - Takes only an Error object/null as the first argument
|
||||
*/
|
||||
CSteamSharedFile.prototype.favorite = function(callback) {
|
||||
this._community.favoriteSharedFile(this.id, this.appID, callback);
|
||||
};
|
||||
|
||||
/**
|
||||
* Posts a comment to this sharedfile
|
||||
* @param {String} message - Content of the comment to post
|
||||
* @param {function} callback - Takes only an Error object/null as the first argument
|
||||
*/
|
||||
CSteamSharedFile.prototype.comment = function(message, callback) {
|
||||
this._community.postSharedFileComment(this.owner, this.id, message, callback);
|
||||
};
|
||||
|
||||
/**
|
||||
* Subscribes to this sharedfile's comment section. Note: Checkbox on webpage does not update
|
||||
* @param {function} callback - Takes only an Error object/null as the first argument
|
||||
*/
|
||||
CSteamSharedFile.prototype.subscribe = function(callback) {
|
||||
this._community.subscribeSharedFileComments(this.owner, this.id, callback);
|
||||
};
|
||||
|
||||
/**
|
||||
* Unfavorites this sharedfile
|
||||
* @param {function} callback - Takes only an Error object/null as the first argument
|
||||
*/
|
||||
CSteamSharedFile.prototype.unfavorite = function(callback) {
|
||||
this._community.unfavoriteSharedFile(this.id, this.appID, callback);
|
||||
};
|
||||
|
||||
/**
|
||||
* Unsubscribes from this sharedfile's comment section. Note: Checkbox on webpage does not update
|
||||
* @param {function} callback - Takes only an Error object/null as the first argument
|
||||
*/
|
||||
CSteamSharedFile.prototype.unsubscribe = function(callback) {
|
||||
this._community.unsubscribeSharedFileComments(this.owner, this.id, callback);
|
||||
};
|
||||
@@ -69,7 +69,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');
|
||||
@@ -148,6 +154,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);
|
||||
};
|
||||
@@ -177,10 +191,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);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -190,3 +205,13 @@ CSteamUser.prototype.getInventoryContents = function(appID, contextID, tradableO
|
||||
CSteamUser.prototype.getProfileBackground = function(callback) {
|
||||
this._community.getUserProfileBackground(this.steamID, callback);
|
||||
};
|
||||
|
||||
/**
|
||||
* Upload an image to Steam and send it to the target user over chat.
|
||||
* @param {Buffer} imageContentsBuffer - The image contents, as a Buffer
|
||||
* @param {{spoiler?: boolean}} [options]
|
||||
* @param {function} callback
|
||||
*/
|
||||
CSteamUser.prototype.sendImage = function(imageContentsBuffer, options, callback) {
|
||||
this._community.sendImageToUser(this.steamID, imageContentsBuffer, options, callback);
|
||||
};
|
||||
|
||||
@@ -4,63 +4,55 @@ var SteamTotp = require('steam-totp');
|
||||
var Async = require('async');
|
||||
|
||||
var CConfirmation = require('../classes/CConfirmation.js');
|
||||
var EConfirmationType = require('../resources/EConfirmationType.js');
|
||||
|
||||
/**
|
||||
* Get a list of your account's currently outstanding confirmations.
|
||||
* @param {int} time - The unix timestamp with which the following key was generated
|
||||
* @param {string} key - The confirmation key that was generated using the preceeding time and the tag "conf" (this key can be reused)
|
||||
* @param {string} key - The confirmation key that was generated using the preceeding time and the tag 'conf' (this key can be reused)
|
||||
* @param {SteamCommunity~getConfirmations} callback - Called when the list of confirmations is received
|
||||
*/
|
||||
SteamCommunity.prototype.getConfirmations = function(time, key, callback) {
|
||||
var self = this;
|
||||
|
||||
request(this, "conf", key, time, "conf", null, false, function(err, body) {
|
||||
if(err) {
|
||||
if (err.message == "Invalid protocol: steammobile:") {
|
||||
err.message = "Not Logged In";
|
||||
self._notifySessionExpired(err);
|
||||
}
|
||||
// Ugly hack to maintain backward compatibility
|
||||
var tag = 'conf';
|
||||
if (typeof key == 'object') {
|
||||
tag = key.tag;
|
||||
key = key.key;
|
||||
}
|
||||
|
||||
// The official Steam app uses the tag 'list', but 'conf' still works so let's use that for backward compatibility.
|
||||
request(this, 'getlist', key, time, tag, null, true, function(err, body) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
var $ = Cheerio.load(body);
|
||||
var empty = $('#mobileconf_empty');
|
||||
if(empty.length > 0) {
|
||||
if(!$(empty).hasClass('mobileconf_done')) {
|
||||
// An error occurred
|
||||
callback(new Error(empty.find('div:nth-of-type(2)').text()));
|
||||
} else {
|
||||
callback(null, []);
|
||||
if (!body.success) {
|
||||
if (body.needauth) {
|
||||
var err = new Error('Not Logged In');
|
||||
self._notifySessionExpired(err);
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
callback(new Error(body.message || body.detail || 'Failed to get confirmation list'));
|
||||
return;
|
||||
}
|
||||
|
||||
// We have something to confirm
|
||||
var confirmations = $('#mobileconf_list');
|
||||
if(!confirmations) {
|
||||
callback(new Error("Malformed response"));
|
||||
return;
|
||||
}
|
||||
|
||||
var confs = [];
|
||||
Array.prototype.forEach.call(confirmations.find('.mobileconf_list_entry'), function(conf) {
|
||||
conf = $(conf);
|
||||
|
||||
var img = conf.find('.mobileconf_list_entry_icon img');
|
||||
confs.push(new CConfirmation(self, {
|
||||
"id": conf.data('confid'),
|
||||
"type": conf.data('type'),
|
||||
"creator": conf.data('creator'),
|
||||
"key": conf.data('key'),
|
||||
"title": conf.find('.mobileconf_list_entry_description>div:nth-of-type(1)').text().trim(),
|
||||
"receiving": conf.find('.mobileconf_list_entry_description>div:nth-of-type(2)').text().trim(),
|
||||
"time": conf.find('.mobileconf_list_entry_description>div:nth-of-type(3)').text().trim(),
|
||||
"icon": img.length < 1 ? '' : $(img).attr('src')
|
||||
}));
|
||||
});
|
||||
var confs = (body.conf || []).map(conf => new CConfirmation(self, {
|
||||
id: conf.id,
|
||||
type: conf.type,
|
||||
creator: conf.creator_id,
|
||||
key: conf.nonce,
|
||||
title: `${conf.type_name || 'Confirm'} - ${conf.headline || ''}`,
|
||||
receiving: conf.type == EConfirmationType.Trade ? ((conf.summary || [])[1] || '') : '',
|
||||
sending: (conf.summary || [])[0] || '',
|
||||
time: (new Date(conf.creation_time * 1000)).toISOString(), // for backward compatibility
|
||||
timestamp: new Date(conf.creation_time * 1000),
|
||||
icon: conf.icon || ''
|
||||
}));
|
||||
|
||||
callback(null, confs);
|
||||
});
|
||||
@@ -76,22 +68,23 @@ SteamCommunity.prototype.getConfirmations = function(time, key, callback) {
|
||||
* Get the trade offer ID associated with a particular confirmation
|
||||
* @param {int} confID - The ID of the confirmation in question
|
||||
* @param {int} time - The unix timestamp with which the following key was generated
|
||||
* @param {string} key - The confirmation key that was generated using the preceeding time and the tag "details" (this key can be reused)
|
||||
* @param {string} key - The confirmation key that was generated using the preceeding time and the tag "detail" (this key can be reused)
|
||||
* @param {SteamCommunity~getConfirmationOfferID} callback
|
||||
*/
|
||||
SteamCommunity.prototype.getConfirmationOfferID = function(confID, time, key, callback) {
|
||||
request(this, "details/" + confID, key, time, "details", null, true, function(err, body) {
|
||||
if(err) {
|
||||
// The official Steam app uses the tag 'detail', but 'details' still works so let's use that for backward compatibility
|
||||
request(this, 'detailspage/' + confID, key, time, 'details', null, false, function(err, body) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!body.success) {
|
||||
if (typeof body != 'string') {
|
||||
callback(new Error("Cannot load confirmation details"));
|
||||
return;
|
||||
}
|
||||
|
||||
var $ = Cheerio.load(body.html);
|
||||
var $ = Cheerio.load(body);
|
||||
var offer = $('.tradeoffer');
|
||||
if(offer.length < 1) {
|
||||
callback(null, null);
|
||||
@@ -118,31 +111,39 @@ SteamCommunity.prototype.getConfirmationOfferID = function(confID, time, key, ca
|
||||
* @param {SteamCommunity~genericErrorCallback} callback - Called when the request is complete
|
||||
*/
|
||||
SteamCommunity.prototype.respondToConfirmation = function(confID, confKey, time, key, accept, callback) {
|
||||
request(this, (confID instanceof Array) ? "multiajaxop" : "ajaxop", key, time, accept ? "allow" : "cancel", {
|
||||
"op": accept ? "allow" : "cancel",
|
||||
"cid": confID,
|
||||
"ck": confKey
|
||||
// Ugly hack to maintain backward compatibility
|
||||
var tag = accept ? 'allow' : 'cancel';
|
||||
if (typeof key == 'object') {
|
||||
tag = key.tag;
|
||||
key = key.key;
|
||||
}
|
||||
|
||||
// The official app uses tags reject/accept, but cancel/allow still works so use these for backward compatibility
|
||||
request(this, (confID instanceof Array) ? 'multiajaxop' : 'ajaxop', key, time, tag, {
|
||||
op: accept ? 'allow' : 'cancel',
|
||||
cid: confID,
|
||||
ck: confKey
|
||||
}, true, function(err, body) {
|
||||
if(!callback) {
|
||||
if (!callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(err) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
if(body.success) {
|
||||
if (body.success) {
|
||||
callback(null);
|
||||
return;
|
||||
}
|
||||
|
||||
if(body.message) {
|
||||
if (body.message) {
|
||||
callback(new Error(body.message));
|
||||
return;
|
||||
}
|
||||
|
||||
callback(new Error("Could not act on confirmation"));
|
||||
callback(new Error('Could not act on confirmation'));
|
||||
});
|
||||
};
|
||||
|
||||
@@ -172,14 +173,15 @@ SteamCommunity.prototype.acceptConfirmationForObject = function(identitySecret,
|
||||
setTimeout(function() {
|
||||
// Delete the saved time offset after 12 hours because why not
|
||||
delete self._timeOffset;
|
||||
}, 1000 * 60 * 60 * 12);
|
||||
}, 1000 * 60 * 60 * 12).unref();
|
||||
});
|
||||
}
|
||||
|
||||
function doConfirmation() {
|
||||
var offset = self._timeOffset;
|
||||
var time = SteamTotp.time(offset);
|
||||
self.getConfirmations(time, SteamTotp.getConfirmationKey(identitySecret, time, "conf"), function(err, confs) {
|
||||
var confKey = SteamTotp.getConfirmationKey(identitySecret, time, 'list');
|
||||
self.getConfirmations(time, {tag: 'list', key: confKey}, function(err, confs) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
@@ -187,7 +189,7 @@ SteamCommunity.prototype.acceptConfirmationForObject = function(identitySecret,
|
||||
|
||||
var conf = confs.filter(function(conf) { return conf.creator == objectID; });
|
||||
if (conf.length == 0) {
|
||||
callback(new Error("Could not find confirmation for object " + objectID));
|
||||
callback(new Error('Could not find confirmation for object ' + objectID));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -204,7 +206,8 @@ SteamCommunity.prototype.acceptConfirmationForObject = function(identitySecret,
|
||||
self._usedConfTimes.splice(0, self._usedConfTimes.length - 60); // we don't need to save more than 60 entries
|
||||
}
|
||||
|
||||
conf.respond(time, SteamTotp.getConfirmationKey(identitySecret, time, "allow"), true, callback);
|
||||
confKey = SteamTotp.getConfirmationKey(identitySecret, time, 'accept');
|
||||
conf.respond(time, {tag: 'accept', key: confKey}, true, callback);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -244,7 +247,7 @@ SteamCommunity.prototype.acceptAllConfirmations = function(time, confKey, allowK
|
||||
|
||||
function request(community, url, key, time, tag, params, json, callback) {
|
||||
if (!community.steamID) {
|
||||
throw new Error("Must be logged in before trying to do anything with confirmations");
|
||||
throw new Error('Must be logged in before trying to do anything with confirmations');
|
||||
}
|
||||
|
||||
params = params || {};
|
||||
@@ -252,16 +255,16 @@ function request(community, url, key, time, tag, params, json, callback) {
|
||||
params.a = community.steamID.getSteamID64();
|
||||
params.k = key;
|
||||
params.t = time;
|
||||
params.m = "android";
|
||||
params.m = 'react';
|
||||
params.tag = tag;
|
||||
|
||||
var req = {
|
||||
"method": url == 'multiajaxop' ? 'POST' : 'GET',
|
||||
"uri": "https://steamcommunity.com/mobileconf/" + url,
|
||||
"json": !!json
|
||||
method: url == 'multiajaxop' ? 'POST' : 'GET',
|
||||
uri: 'https://steamcommunity.com/mobileconf/' + url,
|
||||
json: !!json
|
||||
};
|
||||
|
||||
if (req.method == "GET") {
|
||||
if (req.method == 'GET') {
|
||||
req.qs = params;
|
||||
} else {
|
||||
req.form = params;
|
||||
@@ -274,7 +277,7 @@ function request(community, url, key, time, tag, params, json, callback) {
|
||||
}
|
||||
|
||||
callback(null, body);
|
||||
}, "steamcommunity");
|
||||
}, 'steamcommunity');
|
||||
}
|
||||
|
||||
// Confirmation checker
|
||||
|
||||
@@ -156,22 +156,33 @@ 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;
|
||||
}
|
||||
|
||||
var self = this;
|
||||
var 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
|
||||
}, function(err, response, body) {
|
||||
if(!callback) {
|
||||
return;
|
||||
|
||||
64
components/help.js
Normal file
64
components/help.js
Normal file
@@ -0,0 +1,64 @@
|
||||
const SteamCommunity = require('../index.js');
|
||||
|
||||
const Helpers = require('./helpers.js');
|
||||
|
||||
const HELP_SITE_DOMAIN = 'https://help.steampowered.com';
|
||||
|
||||
/**
|
||||
* 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: HELP_SITE_DOMAIN + '/wizard/AjaxDoPackageRestore',
|
||||
form: {
|
||||
packageid: packageID,
|
||||
sessionid: this.getSessionID(HELP_SITE_DOMAIN),
|
||||
wizard_ajax: 1
|
||||
},
|
||||
json: true
|
||||
}, wizardAjaxHandler(callback));
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove a steam package from your steam account.
|
||||
* @param {int|string} packageID
|
||||
* @param {function} callback
|
||||
*/
|
||||
SteamCommunity.prototype.removePackage = function(packageID, callback) {
|
||||
this.httpRequestPost({
|
||||
uri: HELP_SITE_DOMAIN + '/wizard/AjaxDoPackageRemove',
|
||||
form: {
|
||||
packageid: packageID,
|
||||
sessionid: this.getSessionID(HELP_SITE_DOMAIN),
|
||||
wizard_ajax: 1
|
||||
},
|
||||
json: true
|
||||
}, wizardAjaxHandler(callback));
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a handler for wizard ajax HTTP requests.
|
||||
* @param {function} callback
|
||||
* @returns {(function(*=, *, *): void)|*}
|
||||
*/
|
||||
function wizardAjaxHandler(callback) {
|
||||
return (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,4 +1,6 @@
|
||||
const EResult = require('../resources/EResult.js');
|
||||
const request = require('request');
|
||||
const xml2js = require('xml2js');
|
||||
|
||||
exports.isSteamID = function(input) {
|
||||
var keys = Object.keys(input);
|
||||
@@ -54,3 +56,53 @@ exports.eresultError = function(eresult) {
|
||||
err.eresult = eresult;
|
||||
return err;
|
||||
};
|
||||
|
||||
exports.decodeJwt = function(jwt) {
|
||||
let parts = jwt.split('.');
|
||||
if (parts.length != 3) {
|
||||
throw new Error('Invalid JWT');
|
||||
}
|
||||
|
||||
let standardBase64 = parts[1].replace(/-/g, '+')
|
||||
.replace(/_/g, '/');
|
||||
|
||||
return JSON.parse(Buffer.from(standardBase64, 'base64').toString('utf8'));
|
||||
};
|
||||
|
||||
/**
|
||||
* Resolves a Steam profile URL to get steamID64 and vanityURL
|
||||
* @param {String} url - Full steamcommunity profile URL or only the vanity part.
|
||||
* @param {Object} callback - First argument is null/Error, second is object containing vanityURL (String) and steamID (String)
|
||||
*/
|
||||
exports.resolveVanityURL = function(url, callback) {
|
||||
// Precede url param if only the vanity was provided
|
||||
if (!url.includes("steamcommunity.com")) {
|
||||
url = "https://steamcommunity.com/id/" + url;
|
||||
}
|
||||
|
||||
// Make request to get XML data
|
||||
request(url + "/?xml=1", function(err, response, body) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
// Parse XML data returned from Steam into an object
|
||||
new xml2js.Parser().parseString(body, (err, parsed) => {
|
||||
if (err) {
|
||||
callback(new Error("Couldn't parse XML response"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (parsed.response && parsed.response.error) {
|
||||
callback(new Error("Couldn't find Steam ID"));
|
||||
return;
|
||||
}
|
||||
|
||||
let steamID64 = parsed.profile.steamID64;
|
||||
let vanityURL = parsed.profile.customURL;
|
||||
|
||||
callback(null, {"vanityURL": vanityURL, "steamID": steamID64});
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -124,7 +124,7 @@ SteamCommunity.prototype._checkCommunityError = function(html, callback) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if (typeof html === 'string' && html.match(/g_steamID = false;/) && html.match(/<h1>Sign In<\/h1>/)) {
|
||||
if (typeof html === 'string' && html.indexOf('g_steamID = false;') > -1 && html.indexOf('<title>Sign In</title>') > -1) {
|
||||
err = new Error("Not Logged In");
|
||||
callback(err);
|
||||
this._notifySessionExpired(err);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
var SteamCommunity = require('../index.js');
|
||||
var CEconItem = require('../classes/CEconItem.js');
|
||||
var Helpers = require('./helpers.js');
|
||||
var SteamID = require('steamid');
|
||||
var request = require('request');
|
||||
var Cheerio = require('cheerio');
|
||||
@@ -142,7 +143,7 @@ SteamCommunity.prototype.getInventoryHistory = function(options, callback) {
|
||||
}
|
||||
|
||||
if (options.resolveVanityURLs) {
|
||||
Async.map(vanityURLs, resolveVanityURL, function(err, results) {
|
||||
Async.map(vanityURLs, Helpers.resolveVanityURL, function(err, results) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
@@ -170,19 +171,3 @@ SteamCommunity.prototype.getInventoryHistory = function(options, callback) {
|
||||
}, "steamcommunity");
|
||||
};
|
||||
|
||||
function resolveVanityURL(vanityURL, callback) {
|
||||
request("https://steamcommunity.com/id/" + vanityURL + "/?xml=1", function(err, response, body) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
var match = body.match(/<steamID64>(\d+)<\/steamID64>/);
|
||||
if (!match || !match[1]) {
|
||||
callback(new Error("Couldn't find Steam ID"));
|
||||
return;
|
||||
}
|
||||
|
||||
callback(null, {"vanityURL": vanityURL, "steamID": match[1]});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
var SteamCommunity = require('../index.js');
|
||||
var Cheerio = require('cheerio');
|
||||
const SteamCommunity = require('../index.js');
|
||||
const Cheerio = require('cheerio');
|
||||
|
||||
const Helpers = require('./helpers.js');
|
||||
|
||||
/**
|
||||
* Get a list of all apps on the market
|
||||
@@ -109,6 +111,161 @@ 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 the booster pack catalog to see what booster packs you can create
|
||||
* @param {function} callback
|
||||
*/
|
||||
SteamCommunity.prototype.getBoosterPackCatalog = function(callback) {
|
||||
this.httpRequestGet('https://steamcommunity.com/tradingcards/boostercreator/', (err, res, body) => {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
let idx = body.indexOf('CBoosterCreatorPage.Init(');
|
||||
if (idx == -1) {
|
||||
callback(new Error('Malformed response'));
|
||||
return;
|
||||
}
|
||||
|
||||
let lines = body.slice(idx).split('\n').map(l => l.trim());
|
||||
|
||||
for (let i = 1; i <= 4; i++) {
|
||||
if (typeof lines[i] != 'string' || !lines[i].match(/,$/)) {
|
||||
let err = new Error('Malformed response');
|
||||
err.line = i;
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
lines[i] = lines[i].replace(/,$/, '');
|
||||
}
|
||||
|
||||
let boosterPackCatalog, totalGems, tradableGems, untradableGems;
|
||||
try {
|
||||
boosterPackCatalog = JSON.parse(lines[1]);
|
||||
totalGems = parseInt(lines[2].match(/\d+/)[0], 10);
|
||||
tradableGems = parseInt(lines[3].match(/\d+/)[0], 10);
|
||||
untradableGems = parseInt(lines[4].match(/\d+/)[0], 10);
|
||||
} catch (ex) {
|
||||
let err = new Error('Malformed response');
|
||||
err.inner = ex;
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
let keyedCatalog = {};
|
||||
boosterPackCatalog.forEach((app) => {
|
||||
app.price = parseInt(app.price, 10);
|
||||
app.unavailable = app.unavailable || false;
|
||||
app.availableAtTime = app.available_at_time || null;
|
||||
|
||||
if (typeof app.availableAtTime == 'string') {
|
||||
app.availableAtTime = Helpers.decodeSteamTime(app.availableAtTime);
|
||||
}
|
||||
|
||||
delete app.available_at_time;
|
||||
|
||||
keyedCatalog[app.appid] = app;
|
||||
});
|
||||
|
||||
callback(null, {
|
||||
totalGems,
|
||||
tradableGems,
|
||||
untradableGems,
|
||||
catalog: keyedCatalog
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a booster pack using gems.
|
||||
* @param {int} appid
|
||||
* @param {boolean} [useUntradableGems=false]
|
||||
* @param callback
|
||||
*/
|
||||
SteamCommunity.prototype.createBoosterPack = function(appid, useUntradableGems, callback) {
|
||||
if (typeof useUntradableGems == 'function') {
|
||||
callback = useUntradableGems;
|
||||
useUntradableGems = false;
|
||||
}
|
||||
|
||||
this.httpRequestPost({
|
||||
uri: 'https://steamcommunity.com/tradingcards/ajaxcreatebooster/',
|
||||
form: {
|
||||
sessionid: this.getSessionID(),
|
||||
appid,
|
||||
series: 1,
|
||||
// tradability_preference can be a value 1-3
|
||||
// 1: Prefer using tradable gems, but use untradable if necessary
|
||||
// 2: Only use tradable gems
|
||||
// 3: Prefer using untradable gems, but use tradable if necessary
|
||||
tradability_preference: useUntradableGems ? 3 : 2
|
||||
},
|
||||
json: true,
|
||||
checkHttpError: false
|
||||
}, (err, res, body) => {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
if (body.purchase_eresult && body.purchase_eresult != 1) {
|
||||
callback(Helpers.eresultError(body.purchase_eresult));
|
||||
return;
|
||||
}
|
||||
|
||||
// We can now check HTTP status codes
|
||||
if (this._checkHttpError(err, res, callback, body)) {
|
||||
return;
|
||||
}
|
||||
|
||||
callback(null, {
|
||||
totalGems: parseInt(body.goo_amount, 10),
|
||||
tradableGems: parseInt(body.tradable_goo_amount, 10),
|
||||
untradableGems: parseInt(body.untradable_goo_amount, 10),
|
||||
resultItem: body.purchase_result
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Get details about a gift in your inventory.
|
||||
* @param {string} giftID
|
||||
@@ -166,6 +323,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);
|
||||
@@ -175,3 +333,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;
|
||||
|
||||
158
components/sharedfiles.js
Normal file
158
components/sharedfiles.js
Normal file
@@ -0,0 +1,158 @@
|
||||
var SteamID = require('steamid');
|
||||
|
||||
var SteamCommunity = require('../index.js');
|
||||
|
||||
|
||||
/**
|
||||
* Deletes a comment from a sharedfile's comment section
|
||||
* @param {SteamID | String} userID - ID of the user associated to this sharedfile
|
||||
* @param {String} sharedFileId - ID of the sharedfile
|
||||
* @param {String} cid - ID of the comment to delete
|
||||
* @param {function} callback - Takes only an Error object/null as the first argument
|
||||
*/
|
||||
SteamCommunity.prototype.deleteSharedFileComment = function(userID, sharedFileId, cid, callback) {
|
||||
if (typeof userID === "string") {
|
||||
userID = new SteamID(userID);
|
||||
}
|
||||
|
||||
this.httpRequestPost({
|
||||
"uri": `https://steamcommunity.com/comment/PublishedFile_Public/delete/${userID.toString()}/${sharedFileId}/`,
|
||||
"form": {
|
||||
"gidcomment": cid,
|
||||
"count": 10,
|
||||
"sessionid": this.getSessionID()
|
||||
}
|
||||
}, function(err, response, body) {
|
||||
if (!callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
callback(err);
|
||||
}, "steamcommunity");
|
||||
};
|
||||
|
||||
/**
|
||||
* Favorites a sharedfile
|
||||
* @param {String} sharedFileId - ID of the sharedfile
|
||||
* @param {String} appid - ID of the app associated to this sharedfile
|
||||
* @param {function} callback - Takes only an Error object/null as the first argument
|
||||
*/
|
||||
SteamCommunity.prototype.favoriteSharedFile = function(sharedFileId, appid, callback) {
|
||||
this.httpRequestPost({
|
||||
"uri": "https://steamcommunity.com/sharedfiles/favorite",
|
||||
"form": {
|
||||
"id": sharedFileId,
|
||||
"appid": appid,
|
||||
"sessionid": this.getSessionID()
|
||||
}
|
||||
}, function(err, response, body) {
|
||||
if (!callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
callback(err);
|
||||
}, "steamcommunity");
|
||||
};
|
||||
|
||||
/**
|
||||
* Posts a comment to a sharedfile
|
||||
* @param {SteamID | String} userID - ID of the user associated to this sharedfile
|
||||
* @param {String} sharedFileId - ID of the sharedfile
|
||||
* @param {String} message - Content of the comment to post
|
||||
* @param {function} callback - Takes only an Error object/null as the first argument
|
||||
*/
|
||||
SteamCommunity.prototype.postSharedFileComment = function(userID, sharedFileId, message, callback) {
|
||||
if (typeof userID === "string") {
|
||||
userID = new SteamID(userID);
|
||||
}
|
||||
|
||||
this.httpRequestPost({
|
||||
"uri": `https://steamcommunity.com/comment/PublishedFile_Public/post/${userID.toString()}/${sharedFileId}/`,
|
||||
"form": {
|
||||
"comment": message,
|
||||
"count": 10,
|
||||
"sessionid": this.getSessionID()
|
||||
}
|
||||
}, function(err, response, body) {
|
||||
if (!callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
callback(err);
|
||||
}, "steamcommunity");
|
||||
};
|
||||
|
||||
/**
|
||||
* Subscribes to a sharedfile's comment section. Note: Checkbox on webpage does not update
|
||||
* @param {SteamID | String} userID ID of the user associated to this sharedfile
|
||||
* @param {String} sharedFileId ID of the sharedfile
|
||||
* @param {function} callback - Takes only an Error object/null as the first argument
|
||||
*/
|
||||
SteamCommunity.prototype.subscribeSharedFileComments = function(userID, sharedFileId, callback) {
|
||||
if (typeof userID === "string") {
|
||||
userID = new SteamID(userID);
|
||||
}
|
||||
|
||||
this.httpRequestPost({
|
||||
"uri": `https://steamcommunity.com/comment/PublishedFile_Public/subscribe/${userID.toString()}/${sharedFileId}/`,
|
||||
"form": {
|
||||
"count": 10,
|
||||
"sessionid": this.getSessionID()
|
||||
}
|
||||
}, function(err, response, body) { // eslint-disable-line
|
||||
if (!callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
callback(err);
|
||||
}, "steamcommunity");
|
||||
};
|
||||
|
||||
/**
|
||||
* Unfavorites a sharedfile
|
||||
* @param {String} sharedFileId - ID of the sharedfile
|
||||
* @param {String} appid - ID of the app associated to this sharedfile
|
||||
* @param {function} callback - Takes only an Error object/null as the first argument
|
||||
*/
|
||||
SteamCommunity.prototype.unfavoriteSharedFile = function(sharedFileId, appid, callback) {
|
||||
this.httpRequestPost({
|
||||
"uri": "https://steamcommunity.com/sharedfiles/unfavorite",
|
||||
"form": {
|
||||
"id": sharedFileId,
|
||||
"appid": appid,
|
||||
"sessionid": this.getSessionID()
|
||||
}
|
||||
}, function(err, response, body) {
|
||||
if (!callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
callback(err);
|
||||
}, "steamcommunity");
|
||||
};
|
||||
|
||||
/**
|
||||
* Unsubscribes from a sharedfile's comment section. Note: Checkbox on webpage does not update
|
||||
* @param {SteamID | String} userID - ID of the user associated to this sharedfile
|
||||
* @param {String} sharedFileId - ID of the sharedfile
|
||||
* @param {function} callback - Takes only an Error object/null as the first argument
|
||||
*/
|
||||
SteamCommunity.prototype.unsubscribeSharedFileComments = function(userID, sharedFileId, callback) {
|
||||
if (typeof userID === "string") {
|
||||
userID = new SteamID(userID);
|
||||
}
|
||||
|
||||
this.httpRequestPost({
|
||||
"uri": `https://steamcommunity.com/comment/PublishedFile_Public/unsubscribe/${userID.toString()}/${sharedFileId}/`,
|
||||
"form": {
|
||||
"count": 10,
|
||||
"sessionid": this.getSessionID()
|
||||
}
|
||||
}, function(err, response, body) { // eslint-disable-line
|
||||
if (!callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
callback(err);
|
||||
}, "steamcommunity");
|
||||
};
|
||||
@@ -2,158 +2,151 @@ var SteamTotp = require('steam-totp');
|
||||
var SteamCommunity = require('../index.js');
|
||||
|
||||
var ETwoFactorTokenType = {
|
||||
"None": 0, // No token-based two-factor authentication
|
||||
"ValveMobileApp": 1, // Tokens generated using Valve's special charset (5 digits, alphanumeric)
|
||||
"ThirdParty": 2 // Tokens generated using literally everyone else's standard charset (6 digits, numeric). This is disabled.
|
||||
None: 0, // No token-based two-factor authentication
|
||||
ValveMobileApp: 1, // Tokens generated using Valve's special charset (5 digits, alphanumeric)
|
||||
ThirdParty: 2 // Tokens generated using literally everyone else's standard charset (6 digits, numeric). This is disabled.
|
||||
};
|
||||
|
||||
SteamCommunity.prototype.enableTwoFactor = function(callback) {
|
||||
var self = this;
|
||||
this._verifyMobileAccessToken();
|
||||
|
||||
this.getWebApiOauthToken(function(err, token) {
|
||||
if(err) {
|
||||
if (!this.mobileAccessToken) {
|
||||
callback(new Error('No mobile access token available. Provide one by calling setMobileAppAccessToken()'));
|
||||
return;
|
||||
}
|
||||
|
||||
this.httpRequestPost({
|
||||
uri: "https://api.steampowered.com/ITwoFactorService/AddAuthenticator/v1/?access_token=" + this.mobileAccessToken,
|
||||
// TODO: Send this as protobuf to more closely mimic official app behavior
|
||||
form: {
|
||||
steamid: this.steamID.getSteamID64(),
|
||||
authenticator_time: Math.floor(Date.now() / 1000),
|
||||
authenticator_type: ETwoFactorTokenType.ValveMobileApp,
|
||||
device_identifier: SteamTotp.getDeviceID(this.steamID),
|
||||
sms_phone_id: '1'
|
||||
},
|
||||
json: true
|
||||
}, (err, response, body) => {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
self.httpRequestPost({
|
||||
"uri": "https://api.steampowered.com/ITwoFactorService/AddAuthenticator/v1/",
|
||||
"form": {
|
||||
"steamid": self.steamID.getSteamID64(),
|
||||
"access_token": token,
|
||||
"authenticator_time": Math.floor(Date.now() / 1000),
|
||||
"authenticator_type": ETwoFactorTokenType.ValveMobileApp,
|
||||
"device_identifier": SteamTotp.getDeviceID(self.steamID),
|
||||
"sms_phone_id": "1"
|
||||
},
|
||||
"json": true
|
||||
}, function(err, response, body) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
if (!body.response) {
|
||||
callback(new Error('Malformed response'));
|
||||
return;
|
||||
}
|
||||
|
||||
if(!body.response) {
|
||||
callback(new Error("Malformed response"));
|
||||
return;
|
||||
}
|
||||
if (body.response.status != 1) {
|
||||
var error = new Error('Error ' + body.response.status);
|
||||
error.eresult = body.response.status;
|
||||
callback(error);
|
||||
return;
|
||||
}
|
||||
|
||||
if(body.response.status != 1) {
|
||||
var error = new Error("Error " + body.response.status);
|
||||
error.eresult = body.response.status;
|
||||
callback(error);
|
||||
return;
|
||||
}
|
||||
|
||||
callback(null, body.response);
|
||||
}, "steamcommunity");
|
||||
});
|
||||
callback(null, body.response);
|
||||
}, 'steamcommunity');
|
||||
};
|
||||
|
||||
SteamCommunity.prototype.finalizeTwoFactor = function(secret, activationCode, callback) {
|
||||
var attemptsLeft = 30;
|
||||
var diff = 0;
|
||||
this._verifyMobileAccessToken();
|
||||
|
||||
var self = this;
|
||||
this.getWebApiOauthToken(function(err, token) {
|
||||
if(err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
if (!this.mobileAccessToken) {
|
||||
callback(new Error('No mobile access token available. Provide one by calling setMobileAppAccessToken()'));
|
||||
return;
|
||||
}
|
||||
|
||||
SteamTotp.getTimeOffset(function(err, offset, latency) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
let attemptsLeft = 30;
|
||||
let diff = 0;
|
||||
|
||||
diff = offset;
|
||||
finalize(token);
|
||||
});
|
||||
});
|
||||
let finalize = () => {
|
||||
let code = SteamTotp.generateAuthCode(secret, diff);
|
||||
|
||||
function finalize(token) {
|
||||
var code = SteamTotp.generateAuthCode(secret, diff);
|
||||
|
||||
self.httpRequestPost({
|
||||
"uri": "https://api.steampowered.com/ITwoFactorService/FinalizeAddAuthenticator/v1/",
|
||||
"form": {
|
||||
"steamid": self.steamID.getSteamID64(),
|
||||
"access_token": token,
|
||||
"authenticator_code": code,
|
||||
"authenticator_time": Math.floor(Date.now() / 1000),
|
||||
"activation_code": activationCode
|
||||
this.httpRequestPost({
|
||||
uri: 'https://api.steampowered.com/ITwoFactorService/FinalizeAddAuthenticator/v1/?access_token=' + this.mobileAccessToken,
|
||||
form: {
|
||||
steamid: this.steamID.getSteamID64(),
|
||||
authenticator_code: code,
|
||||
authenticator_time: Math.floor(Date.now() / 1000),
|
||||
activation_code: activationCode
|
||||
},
|
||||
"json": true
|
||||
json: true
|
||||
}, function(err, response, body) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!body.response) {
|
||||
callback(new Error("Malformed response"));
|
||||
if (!body.response) {
|
||||
callback(new Error('Malformed response'));
|
||||
return;
|
||||
}
|
||||
|
||||
body = body.response;
|
||||
|
||||
if(body.server_time) {
|
||||
if (body.server_time) {
|
||||
diff = body.server_time - Math.floor(Date.now() / 1000);
|
||||
}
|
||||
|
||||
if(body.status == 89) {
|
||||
callback(new Error("Invalid activation code"));
|
||||
if (body.status == 89) {
|
||||
callback(new Error('Invalid activation code'));
|
||||
} else if(body.want_more) {
|
||||
attemptsLeft--;
|
||||
diff += 30;
|
||||
|
||||
finalize(token);
|
||||
finalize();
|
||||
} else if(!body.success) {
|
||||
callback(new Error("Error " + body.status));
|
||||
callback(new Error('Error ' + body.status));
|
||||
} else {
|
||||
callback(null);
|
||||
}
|
||||
}, "steamcommunity");
|
||||
}, 'steamcommunity');
|
||||
}
|
||||
};
|
||||
|
||||
SteamCommunity.prototype.disableTwoFactor = function(revocationCode, callback) {
|
||||
var self = this;
|
||||
|
||||
this.getWebApiOauthToken(function(err, token) {
|
||||
if(err) {
|
||||
SteamTotp.getTimeOffset(function(err, offset, latency) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
self.httpRequestPost({
|
||||
"uri": "https://api.steampowered.com/ITwoFactorService/RemoveAuthenticator/v1/",
|
||||
"form": {
|
||||
"steamid": self.steamID.getSteamID64(),
|
||||
"access_token": token,
|
||||
"revocation_code": revocationCode,
|
||||
"steamguard_scheme": 1
|
||||
},
|
||||
"json": true
|
||||
}, function(err, response, body) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!body.response) {
|
||||
callback(new Error("Malformed response"));
|
||||
return;
|
||||
}
|
||||
|
||||
if(!body.response.success) {
|
||||
callback(new Error("Request failed"));
|
||||
return;
|
||||
}
|
||||
|
||||
// success = true means it worked
|
||||
callback(null);
|
||||
}, "steamcommunity");
|
||||
diff = offset;
|
||||
finalize();
|
||||
});
|
||||
};
|
||||
|
||||
SteamCommunity.prototype.disableTwoFactor = function(revocationCode, callback) {
|
||||
this._verifyMobileAccessToken();
|
||||
|
||||
if (!this.mobileAccessToken) {
|
||||
callback(new Error('No mobile access token available. Provide one by calling setMobileAppAccessToken()'));
|
||||
return;
|
||||
}
|
||||
|
||||
this.httpRequestPost({
|
||||
uri: 'https://api.steampowered.com/ITwoFactorService/RemoveAuthenticator/v1/?access_token=' + this.mobileAccessToken,
|
||||
form: {
|
||||
steamid: this.steamID.getSteamID64(),
|
||||
revocation_code: revocationCode,
|
||||
steamguard_scheme: 1
|
||||
},
|
||||
json: true
|
||||
}, function(err, response, body) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!body.response) {
|
||||
callback(new Error('Malformed response'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!body.response.success) {
|
||||
callback(new Error('Request failed'));
|
||||
return;
|
||||
}
|
||||
|
||||
// success = true means it worked
|
||||
callback(null);
|
||||
}, 'steamcommunity');
|
||||
};
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
const Cheerio = require('cheerio');
|
||||
const Crypto = require('crypto');
|
||||
const imageSize = require('image-size');
|
||||
const SteamID = require('steamid');
|
||||
|
||||
const SteamCommunity = require('../index.js');
|
||||
@@ -134,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
|
||||
@@ -149,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"));
|
||||
}
|
||||
@@ -397,17 +499,22 @@ SteamCommunity.prototype.getUserInventory = function(userID, appID, contextID, t
|
||||
* @param {function} callback
|
||||
*/
|
||||
SteamCommunity.prototype.getUserInventoryContents = function(userID, appID, contextID, tradableOnly, language, callback) {
|
||||
if (typeof language === 'function') {
|
||||
callback = language;
|
||||
language = "english";
|
||||
}
|
||||
|
||||
if (!userID) {
|
||||
callback(new Error("The user's SteamID is invalid or missing."));
|
||||
return;
|
||||
}
|
||||
|
||||
var self = this;
|
||||
|
||||
if (typeof userID === 'string') {
|
||||
userID = new SteamID(userID);
|
||||
}
|
||||
|
||||
if (typeof language === 'function') {
|
||||
callback = language;
|
||||
language = "english";
|
||||
}
|
||||
|
||||
var pos = 1;
|
||||
get([], []);
|
||||
|
||||
@@ -419,7 +526,7 @@ SteamCommunity.prototype.getUserInventoryContents = function(userID, appID, cont
|
||||
},
|
||||
"qs": {
|
||||
"l": language, // Default language
|
||||
"count": 5000, // Max items per 'page'
|
||||
"count": 2000, // Max items per 'page'
|
||||
"start_assetid": start
|
||||
},
|
||||
"json": true
|
||||
@@ -503,3 +610,158 @@ SteamCommunity.prototype.getUserInventoryContents = function(userID, appID, cont
|
||||
return quickDescriptionLookup[key];
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Upload an image to Steam and send it to another user over Steam chat.
|
||||
* @param {SteamID|string} userID - Either a SteamID object or a string that can parse into one
|
||||
* @param {Buffer} imageContentsBuffer - The image contents, as a Buffer
|
||||
* @param {{spoiler?: boolean}} [options]
|
||||
* @param {function} callback
|
||||
*/
|
||||
SteamCommunity.prototype.sendImageToUser = function(userID, imageContentsBuffer, options, callback) {
|
||||
if (typeof options == 'function') {
|
||||
callback = options;
|
||||
options = {};
|
||||
}
|
||||
|
||||
options = options || {};
|
||||
|
||||
if (!userID) {
|
||||
callback(new Error('The user\'s SteamID is invalid or missing'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof userID == 'string') {
|
||||
userID = new SteamID(userID);
|
||||
}
|
||||
|
||||
if (!Buffer.isBuffer(imageContentsBuffer)) {
|
||||
callback(new Error('The image contents must be a Buffer containing an image'));
|
||||
return;
|
||||
}
|
||||
|
||||
var imageDetails = null;
|
||||
try {
|
||||
imageDetails = imageSize(imageContentsBuffer);
|
||||
} catch (ex) {
|
||||
callback(ex);
|
||||
return;
|
||||
}
|
||||
|
||||
var imageHash = Crypto.createHash('sha1');
|
||||
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: {
|
||||
referer: 'https://steamcommunity.com/chat/'
|
||||
},
|
||||
formData: { // it's multipart
|
||||
sessionid: this.getSessionID(),
|
||||
l: 'english',
|
||||
file_size: imageContentsBuffer.length,
|
||||
file_name: filename,
|
||||
file_sha: imageHash,
|
||||
file_image_width: imageDetails.width,
|
||||
file_image_height: imageDetails.height,
|
||||
file_type: 'image/' + (imageDetails.type == 'jpg' ? 'jpeg' : imageDetails.type)
|
||||
},
|
||||
json: true
|
||||
}, (err, res, body) => {
|
||||
if (err) {
|
||||
if (body && body.success) {
|
||||
var err2 = Helpers.eresultError(body.success);
|
||||
if (body.message) {
|
||||
err2.message = body.message;
|
||||
}
|
||||
callback(err2);
|
||||
} else {
|
||||
callback(err);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (body.success != 1) {
|
||||
callback(Helpers.eresultError(body.success));
|
||||
return;
|
||||
}
|
||||
|
||||
var hmac = body.hmac;
|
||||
var timestamp = body.timestamp;
|
||||
var startResult = body.result;
|
||||
|
||||
if (!startResult || !startResult.ugcid || !startResult.url_host || !startResult.request_headers) {
|
||||
callback(new Error('Malformed response'));
|
||||
return;
|
||||
}
|
||||
|
||||
// Okay, now we need to PUT the file to the provided URL
|
||||
var uploadUrl = (startResult.use_https ? 'https' : 'http') + '://' + startResult.url_host + startResult.url_path;
|
||||
var headers = {};
|
||||
startResult.request_headers.forEach((header) => {
|
||||
headers[header.name.toLowerCase()] = header.value;
|
||||
});
|
||||
|
||||
this.httpRequest({
|
||||
uri: uploadUrl,
|
||||
method: 'PUT',
|
||||
headers,
|
||||
body: imageContentsBuffer
|
||||
}, (err, res, body) => {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
// Now we need to commit the upload
|
||||
this.httpRequestPost({
|
||||
uri: 'https://steamcommunity.com/chat/commitfileupload/',
|
||||
headers: {
|
||||
referer: 'https://steamcommunity.com/chat/'
|
||||
},
|
||||
formData: { // it's multipart again
|
||||
sessionid: this.getSessionID(),
|
||||
l: 'english',
|
||||
file_name: filename,
|
||||
file_sha: imageHash,
|
||||
success: '1',
|
||||
ugcid: startResult.ugcid,
|
||||
file_type: 'image/' + (imageDetails.type == 'jpg' ? 'jpeg' : imageDetails.type),
|
||||
file_image_width: imageDetails.width,
|
||||
file_image_height: imageDetails.height,
|
||||
timestamp,
|
||||
hmac,
|
||||
friend_steamid: userID.getSteamID64(),
|
||||
spoiler: options.spoiler ? '1' : '0'
|
||||
},
|
||||
json: true
|
||||
}, (err, res, body) => {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
if (body.success != 1) {
|
||||
callback(Helpers.eresultError(body.success));
|
||||
return;
|
||||
}
|
||||
|
||||
if (body.result.success != 1) {
|
||||
// lol valve
|
||||
callback(Helpers.eresultError(body.result.success));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!body.result.details || !body.result.details.url) {
|
||||
callback(new Error('Malformed response'));
|
||||
return;
|
||||
}
|
||||
|
||||
callback(null, body.result.details.url);
|
||||
}, 'steamcommunity');
|
||||
}, 'steamcommunity');
|
||||
}, 'steamcommunity');
|
||||
};
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
var SteamCommunity = require('../index.js');
|
||||
|
||||
const Helpers = require('./helpers.js');
|
||||
|
||||
SteamCommunity.prototype.getWebApiKey = function(domain, callback) {
|
||||
var self = this;
|
||||
this.httpRequest({
|
||||
@@ -45,29 +47,72 @@ SteamCommunity.prototype.getWebApiKey = function(domain, callback) {
|
||||
};
|
||||
|
||||
/**
|
||||
* @deprecated No longer works if not logged in via mobile login. Will be removed in a future release.
|
||||
* @deprecated No longer works. Will be removed in a future release.
|
||||
* @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 is no longer issued by Steam.'));
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets an access_token generated by steam-session using EAuthTokenPlatformType.MobileApp.
|
||||
* Required for some operations such as 2FA enabling and disabling.
|
||||
* This will throw an Error if the provided token is not valid, was not generated for the MobileApp platform, is expired,
|
||||
* or does not belong to the logged-in user account.
|
||||
*
|
||||
* @param {string} token
|
||||
*/
|
||||
SteamCommunity.prototype.setMobileAppAccessToken = function(token) {
|
||||
if (!this.steamID) {
|
||||
throw new Error('Log on to steamcommunity before setting a mobile app access token');
|
||||
}
|
||||
|
||||
let decodedToken = Helpers.decodeJwt(token);
|
||||
|
||||
if (!decodedToken.iss || !decodedToken.sub || !decodedToken.aud || !decodedToken.exp) {
|
||||
throw new Error('Provided value is not a valid Steam access token');
|
||||
}
|
||||
|
||||
if (decodedToken.iss == 'steam') {
|
||||
throw new Error('Provided token is a refresh token, not an access token');
|
||||
}
|
||||
|
||||
if (decodedToken.sub != this.steamID.getSteamID64()) {
|
||||
throw new Error(`Provided token belongs to account ${decodedToken.sub}, but we are logged into ${this.steamID.getSteamID64()}`);
|
||||
}
|
||||
|
||||
if (decodedToken.exp < Math.floor(Date.now() / 1000)) {
|
||||
throw new Error('Provided token is expired');
|
||||
}
|
||||
|
||||
if ((decodedToken.aud || []).indexOf('mobile') == -1) {
|
||||
throw new Error('Provided token is not valid for MobileApp platform type');
|
||||
}
|
||||
|
||||
this.mobileAccessToken = token;
|
||||
};
|
||||
|
||||
/**
|
||||
* Verifies that the mobile access token we already have set is still valid for current login.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
SteamCommunity.prototype._verifyMobileAccessToken = function() {
|
||||
if (!this.mobileAccessToken) {
|
||||
// No access token, so nothing to do here.
|
||||
return;
|
||||
}
|
||||
|
||||
let decodedToken = Helpers.decodeJwt(this.mobileAccessToken);
|
||||
|
||||
let isTokenInvalid = decodedToken.sub != this.steamID.getSteamID64() // SteamID doesn't match
|
||||
|| decodedToken.exp < Math.floor(Date.now() / 1000); // Token is expired
|
||||
|
||||
if (isTokenInvalid) {
|
||||
delete this.mobileAccessToken;
|
||||
}
|
||||
};
|
||||
|
||||
35
examples/README.md
Normal file
35
examples/README.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# node-steamcommunity examples
|
||||
|
||||
The files in this directory are example scripts that you can use as a getting-started point for using node-steamcommunity.
|
||||
|
||||
## Enable or Disable Two-Factor Authentication
|
||||
|
||||
If you need to enable or disable 2FA on your bot account, you can use enable_twofactor.js and disable_twofactor.js to do so.
|
||||
The way that you're intended to use these scripts is by cloning the repository locally, and then running them directly
|
||||
from this examples directory.
|
||||
|
||||
For example:
|
||||
|
||||
```shell
|
||||
git clone https://github.com/DoctorMcKay/node-steamcommunity node-steamcommunity
|
||||
cd node-steamcommunity
|
||||
npm install
|
||||
cd examples
|
||||
node enable_twofactor.js
|
||||
```
|
||||
|
||||
## Accept All Confirmations
|
||||
|
||||
If you need to accept trade or market confirmations on your bot account for which you have your identity secret, you can
|
||||
use accept_all_confirmations.js to do so. The way that you're intended to use this script is by cloning the repository
|
||||
locally, and then running it directly from this examples directory.
|
||||
|
||||
For example:
|
||||
|
||||
```shell
|
||||
git clone https://github.com/DoctorMcKay/node-steamcommunity node-steamcommunity
|
||||
cd node-steamcommunity
|
||||
npm install
|
||||
cd examples
|
||||
node accept_all_confirmations.js
|
||||
```
|
||||
173
examples/accept_all_confirmations.js
Normal file
173
examples/accept_all_confirmations.js
Normal file
@@ -0,0 +1,173 @@
|
||||
// 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 SteamSession = require('steam-session');
|
||||
const SteamTotp = require('steam-totp');
|
||||
const ReadLine = require('readline');
|
||||
|
||||
const EConfirmationType = SteamCommunity.ConfirmationType;
|
||||
|
||||
let g_AbortPromptFunc = null;
|
||||
|
||||
let community = new SteamCommunity();
|
||||
|
||||
main();
|
||||
async function main() {
|
||||
let accountName = await promptAsync('Username: ');
|
||||
let password = await promptAsync('Password (hidden): ', true);
|
||||
|
||||
// Create a LoginSession for us to use to attempt to log into steam
|
||||
let session = new SteamSession.LoginSession(SteamSession.EAuthTokenPlatformType.MobileApp);
|
||||
|
||||
// Go ahead and attach our event handlers before we do anything else.
|
||||
session.on('authenticated', async () => {
|
||||
abortPrompt();
|
||||
|
||||
let cookies = await session.getWebCookies();
|
||||
community.setCookies(cookies);
|
||||
|
||||
doConfirmations();
|
||||
});
|
||||
|
||||
session.on('timeout', () => {
|
||||
abortPrompt();
|
||||
console.log('This login attempt has timed out.');
|
||||
});
|
||||
|
||||
session.on('error', (err) => {
|
||||
abortPrompt();
|
||||
|
||||
// This should ordinarily not happen. This only happens in case there's some kind of unexpected error while
|
||||
// polling, e.g. the network connection goes down or Steam chokes on something.
|
||||
|
||||
console.log(`ERROR: This login attempt has failed! ${err.message}`);
|
||||
});
|
||||
|
||||
// Start our login attempt
|
||||
let startResult = await session.startWithCredentials({accountName, password});
|
||||
if (startResult.actionRequired) {
|
||||
// Some Steam Guard action is required. We only care about email and device codes; in theory an
|
||||
// EmailConfirmation and/or DeviceConfirmation action could be possible, but we're just going to ignore those.
|
||||
// If the user does receive a confirmation and accepts it, LoginSession will detect and handle that automatically.
|
||||
// The only consequence of ignoring it here is that we don't print a message to the user indicating that they
|
||||
// could accept an email or device confirmation.
|
||||
|
||||
let codeActionTypes = [SteamSession.EAuthSessionGuardType.EmailCode, SteamSession.EAuthSessionGuardType.DeviceCode];
|
||||
let codeAction = startResult.validActions.find(action => codeActionTypes.includes(action.type));
|
||||
if (codeAction) {
|
||||
if (codeAction.type == SteamSession.EAuthSessionGuardType.EmailCode) {
|
||||
console.log(`A code has been sent to your email address at ${codeAction.detail}.`);
|
||||
} else {
|
||||
// We wouldn't expect this to happen since we're trying to enable 2FA, but just in case...
|
||||
console.log('You need to provide a Steam Guard Mobile Authenticator code.');
|
||||
}
|
||||
|
||||
let code = await promptAsync('Code or Shared Secret: ');
|
||||
if (code) {
|
||||
// The code might've been a shared secret
|
||||
if (code.length > 10) {
|
||||
code = SteamTotp.getAuthCode(code);
|
||||
}
|
||||
await session.submitSteamGuardCode(code);
|
||||
}
|
||||
|
||||
// If we fall through here without submitting a Steam Guard code, that means one of two things:
|
||||
// 1. The user pressed enter without providing a code, in which case the script will simply exit
|
||||
// 2. The user approved a device/email confirmation, in which case 'authenticated' was emitted and the prompt was canceled
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function doConfirmations() {
|
||||
let identitySecret = await promptAsync('Identity Secret: ');
|
||||
|
||||
let confs = await new Promise((resolve, reject) => {
|
||||
let time = SteamTotp.time();
|
||||
let key = SteamTotp.getConfirmationKey(identitySecret, time, 'conf');
|
||||
community.getConfirmations(time, key, (err, confs) => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
|
||||
resolve(confs);
|
||||
});
|
||||
});
|
||||
|
||||
console.log(`Found ${confs.length} outstanding confirmations.`);
|
||||
|
||||
// We need to track the previous timestamp we used, as we cannot reuse timestamps.
|
||||
let previousTime = 0;
|
||||
|
||||
for (let i = 0; i < confs.length; i++) {
|
||||
let conf = confs[i];
|
||||
|
||||
process.stdout.write(`Accepting confirmation for ${EConfirmationType[conf.type]} - ${conf.title}... `);
|
||||
|
||||
try {
|
||||
await new Promise((resolve, reject) => {
|
||||
let time = SteamTotp.time();
|
||||
if (time == previousTime) {
|
||||
time++;
|
||||
}
|
||||
|
||||
previousTime = time;
|
||||
let key = SteamTotp.getConfirmationKey(identitySecret, time, 'allow');
|
||||
conf.respond(time, key, true, (err) => {
|
||||
err ? reject(err) : resolve();
|
||||
});
|
||||
});
|
||||
|
||||
console.log('success');
|
||||
} catch (ex) {
|
||||
console.log(`error: ${ex.message}`);
|
||||
}
|
||||
|
||||
// sleep 500ms so we don't run too far away from the current timestamp
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
}
|
||||
|
||||
console.log('Finished processing confirmations');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
// Nothing interesting below here, just code for prompting for input from the console.
|
||||
|
||||
function promptAsync(question, sensitiveInput = false) {
|
||||
return new Promise((resolve) => {
|
||||
let rl = ReadLine.createInterface({
|
||||
input: process.stdin,
|
||||
output: sensitiveInput ? null : process.stdout,
|
||||
terminal: true
|
||||
});
|
||||
|
||||
g_AbortPromptFunc = () => {
|
||||
rl.close();
|
||||
resolve('');
|
||||
};
|
||||
|
||||
if (sensitiveInput) {
|
||||
// We have to write the question manually if we didn't give readline an output stream
|
||||
process.stdout.write(question);
|
||||
}
|
||||
|
||||
rl.question(question, (result) => {
|
||||
if (sensitiveInput) {
|
||||
// We have to manually print a newline
|
||||
process.stdout.write('\n');
|
||||
}
|
||||
|
||||
g_AbortPromptFunc = null;
|
||||
rl.close();
|
||||
resolve(result);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function abortPrompt() {
|
||||
if (!g_AbortPromptFunc) {
|
||||
return;
|
||||
}
|
||||
|
||||
g_AbortPromptFunc();
|
||||
process.stdout.write('\n');
|
||||
}
|
||||
@@ -1,61 +1,135 @@
|
||||
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 SteamSession = require('steam-session');
|
||||
const ReadLine = require('readline');
|
||||
|
||||
var community = new SteamCommunity();
|
||||
var rl = ReadLine.createInterface({
|
||||
"input": process.stdin,
|
||||
"output": process.stdout
|
||||
});
|
||||
let g_AbortPromptFunc = null;
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
let community = new SteamCommunity();
|
||||
|
||||
main();
|
||||
async function main() {
|
||||
let accountName = await promptAsync('Username: ');
|
||||
let password = await promptAsync('Password (hidden): ', true);
|
||||
|
||||
// Create a LoginSession for us to use to attempt to log into steam
|
||||
let session = new SteamSession.LoginSession(SteamSession.EAuthTokenPlatformType.MobileApp);
|
||||
|
||||
// Go ahead and attach our event handlers before we do anything else.
|
||||
session.on('authenticated', async () => {
|
||||
abortPrompt();
|
||||
|
||||
let accessToken = session.accessToken;
|
||||
let cookies = await session.getWebCookies();
|
||||
|
||||
community.setCookies(cookies);
|
||||
community.setMobileAppAccessToken(accessToken);
|
||||
|
||||
// Enabling or disabling 2FA is presently the only action in node-steamcommunity which requires an access token.
|
||||
// In all other cases, using `community.setCookies(cookies)` is all you need to do in order to be logged in,
|
||||
// although there's never any harm in setting a mobile app access token.
|
||||
|
||||
doRevoke();
|
||||
});
|
||||
});
|
||||
|
||||
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.");
|
||||
process.exit();
|
||||
return;
|
||||
session.on('timeout', () => {
|
||||
abortPrompt();
|
||||
console.log('This login attempt has timed out.');
|
||||
});
|
||||
|
||||
session.on('error', (err) => {
|
||||
abortPrompt();
|
||||
|
||||
// This should ordinarily not happen. This only happens in case there's some kind of unexpected error while
|
||||
// polling, e.g. the network connection goes down or Steam chokes on something.
|
||||
|
||||
console.log(`ERROR: This login attempt has failed! ${err.message}`);
|
||||
});
|
||||
|
||||
// Start our login attempt
|
||||
let startResult = await session.startWithCredentials({accountName, password});
|
||||
if (startResult.actionRequired) {
|
||||
// Some Steam Guard action is required. We only care about email and device codes; in theory an
|
||||
// EmailConfirmation and/or DeviceConfirmation action could be possible, but we're just going to ignore those.
|
||||
// If the user does receive a confirmation and accepts it, LoginSession will detect and handle that automatically.
|
||||
// The only consequence of ignoring it here is that we don't print a message to the user indicating that they
|
||||
// could accept an email or device confirmation.
|
||||
|
||||
let codeActionTypes = [SteamSession.EAuthSessionGuardType.EmailCode, SteamSession.EAuthSessionGuardType.DeviceCode];
|
||||
let codeAction = startResult.validActions.find(action => codeActionTypes.includes(action.type));
|
||||
if (codeAction) {
|
||||
if (codeAction.type == SteamSession.EAuthSessionGuardType.EmailCode) {
|
||||
// We wouldn't expect this to happen since we're trying to disable 2FA, but just in case...
|
||||
console.log(`A code has been sent to your email address at ${codeAction.detail}.`);
|
||||
} else {
|
||||
console.log('You need to provide a Steam Guard Mobile Authenticator code.');
|
||||
}
|
||||
|
||||
if(err.message == 'CAPTCHA') {
|
||||
console.log(err.captchaurl);
|
||||
rl.question("CAPTCHA: ", function(captchaInput) {
|
||||
doLogin(accountName, password, authCode, captchaInput);
|
||||
});
|
||||
|
||||
return;
|
||||
let code = await promptAsync('Code: ');
|
||||
if (code) {
|
||||
await session.submitSteamGuardCode(code);
|
||||
}
|
||||
|
||||
// If we fall through here without submitting a Steam Guard code, that means one of two things:
|
||||
// 1. The user pressed enter without providing a code, in which case the script will simply exit
|
||||
// 2. The user approved a device/email confirmation, in which case 'authenticated' was emitted and the prompt was canceled
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function doRevoke() {
|
||||
let rCode = await promptAsync('Revocation Code: R');
|
||||
community.disableTwoFactor('R' + rCode, (err) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
process.exit();
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("Logged on!");
|
||||
community.disableTwoFactor("R" + rCode, function(err) {
|
||||
if(err) {
|
||||
console.log(err);
|
||||
process.exit();
|
||||
return;
|
||||
console.log('Two-factor authentication disabled!');
|
||||
process.exit();
|
||||
});
|
||||
}
|
||||
|
||||
// Nothing interesting below here, just code for prompting for input from the console.
|
||||
|
||||
function promptAsync(question, sensitiveInput = false) {
|
||||
return new Promise((resolve) => {
|
||||
let rl = ReadLine.createInterface({
|
||||
input: process.stdin,
|
||||
output: sensitiveInput ? null : process.stdout,
|
||||
terminal: true
|
||||
});
|
||||
|
||||
g_AbortPromptFunc = () => {
|
||||
rl.close();
|
||||
resolve('');
|
||||
};
|
||||
|
||||
if (sensitiveInput) {
|
||||
// We have to write the question manually if we didn't give readline an output stream
|
||||
process.stdout.write(question);
|
||||
}
|
||||
|
||||
rl.question(question, (result) => {
|
||||
if (sensitiveInput) {
|
||||
// We have to manually print a newline
|
||||
process.stdout.write('\n');
|
||||
}
|
||||
|
||||
console.log("Two-factor authentication disabled!");
|
||||
process.exit();
|
||||
g_AbortPromptFunc = null;
|
||||
rl.close();
|
||||
resolve(result);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function abortPrompt() {
|
||||
if (!g_AbortPromptFunc) {
|
||||
return;
|
||||
}
|
||||
|
||||
g_AbortPromptFunc();
|
||||
process.stdout.write('\n');
|
||||
}
|
||||
|
||||
@@ -1,48 +1,98 @@
|
||||
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 SteamSession = require('steam-session');
|
||||
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;
|
||||
|
||||
rl.question("Username: ", function(accountName) {
|
||||
rl.question("Password: ", function(password) {
|
||||
doLogin(accountName, password);
|
||||
let g_AbortPromptFunc = null;
|
||||
|
||||
let community = new SteamCommunity();
|
||||
|
||||
main();
|
||||
async function main() {
|
||||
let accountName = await promptAsync('Username: ');
|
||||
let password = await promptAsync('Password (hidden): ', true);
|
||||
|
||||
// Create a LoginSession for us to use to attempt to log into steam
|
||||
let session = new SteamSession.LoginSession(SteamSession.EAuthTokenPlatformType.MobileApp);
|
||||
|
||||
// Go ahead and attach our event handlers before we do anything else.
|
||||
session.on('authenticated', async () => {
|
||||
abortPrompt();
|
||||
|
||||
let accessToken = session.accessToken;
|
||||
let cookies = await session.getWebCookies();
|
||||
|
||||
community.setCookies(cookies);
|
||||
community.setMobileAppAccessToken(accessToken);
|
||||
|
||||
// Enabling or disabling 2FA is presently the only action in node-steamcommunity which requires an access token.
|
||||
// In all other cases, using `community.setCookies(cookies)` is all you need to do in order to be logged in,
|
||||
// although there's never any harm in setting a mobile app access token.
|
||||
|
||||
doSetup();
|
||||
});
|
||||
});
|
||||
|
||||
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.");
|
||||
session.on('timeout', () => {
|
||||
abortPrompt();
|
||||
console.log('This login attempt has timed out.');
|
||||
});
|
||||
|
||||
session.on('error', (err) => {
|
||||
abortPrompt();
|
||||
|
||||
// This should ordinarily not happen. This only happens in case there's some kind of unexpected error while
|
||||
// polling, e.g. the network connection goes down or Steam chokes on something.
|
||||
|
||||
console.log(`ERROR: This login attempt has failed! ${err.message}`);
|
||||
});
|
||||
|
||||
// Start our login attempt
|
||||
let startResult = await session.startWithCredentials({accountName, password});
|
||||
if (startResult.actionRequired) {
|
||||
// Some Steam Guard action is required. We only care about email and device codes; in theory an
|
||||
// EmailConfirmation and/or DeviceConfirmation action could be possible, but we're just going to ignore those.
|
||||
// If the user does receive a confirmation and accepts it, LoginSession will detect and handle that automatically.
|
||||
// The only consequence of ignoring it here is that we don't print a message to the user indicating that they
|
||||
// could accept an email or device confirmation.
|
||||
|
||||
let codeActionTypes = [SteamSession.EAuthSessionGuardType.EmailCode, SteamSession.EAuthSessionGuardType.DeviceCode];
|
||||
let codeAction = startResult.validActions.find(action => codeActionTypes.includes(action.type));
|
||||
if (codeAction) {
|
||||
if (codeAction.type == SteamSession.EAuthSessionGuardType.EmailCode) {
|
||||
console.log(`A code has been sent to your email address at ${codeAction.detail}.`);
|
||||
} else {
|
||||
// We wouldn't expect this to happen since we're trying to enable 2FA, but just in case...
|
||||
console.log('You need to provide a Steam Guard Mobile Authenticator code.');
|
||||
}
|
||||
|
||||
let code = await promptAsync('Code: ');
|
||||
if (code) {
|
||||
await session.submitSteamGuardCode(code);
|
||||
}
|
||||
|
||||
// If we fall through here without submitting a Steam Guard code, that means one of two things:
|
||||
// 1. The user pressed enter without providing a code, in which case the script will simply exit
|
||||
// 2. The user approved a device/email confirmation, in which case 'authenticated' was emitted and the prompt was canceled
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function doSetup() {
|
||||
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.message == 'SteamGuard') {
|
||||
console.log("An email has been sent to your address at " + err.emaildomain);
|
||||
rl.question("Steam Guard Code: ", function (code) {
|
||||
doLogin(accountName, password, code);
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(err.message == 'CAPTCHA') {
|
||||
console.log(err.captchaurl);
|
||||
rl.question("CAPTCHA: ", function(captchaInput) {
|
||||
doLogin(accountName, password, authCode, captchaInput);
|
||||
});
|
||||
|
||||
if (err.eresult == EResult.RateLimitExceeded) {
|
||||
console.log('Error: RateLimitExceeded. Try again later.');
|
||||
process.exit();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -51,57 +101,82 @@ 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?");
|
||||
process.exit();
|
||||
return;
|
||||
}
|
||||
|
||||
if(err.eresult == 84) {
|
||||
console.log("Error: RateLimitExceeded. Try again later.");
|
||||
process.exit();
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(err);
|
||||
process.exit();
|
||||
return;
|
||||
}
|
||||
|
||||
if(response.status != 1) {
|
||||
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"));
|
||||
|
||||
promptActivationCode(response);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
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") {
|
||||
console.log(err);
|
||||
promptActivationCode(response);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(err);
|
||||
} else {
|
||||
console.log("Two-factor authentication enabled!");
|
||||
}
|
||||
|
||||
if (response.status != EResult.OK) {
|
||||
console.log(`Error: Status ${response.status}`);
|
||||
process.exit();
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
async function promptActivationCode(response) {
|
||||
if (response.phone_number_hint) {
|
||||
console.log(`A code has been sent to your phone ending in ${response.phone_number_hint}.`);
|
||||
}
|
||||
|
||||
let smsCode = await promptAsync('SMS Code: ');
|
||||
community.finalizeTwoFactor(response.shared_secret, smsCode, (err) => {
|
||||
if (err) {
|
||||
if (err.message == 'Invalid activation code') {
|
||||
console.log(err);
|
||||
promptActivationCode(response);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(err);
|
||||
} else {
|
||||
console.log('Two-factor authentication enabled!');
|
||||
}
|
||||
|
||||
process.exit();
|
||||
});
|
||||
}
|
||||
|
||||
// Nothing interesting below here, just code for prompting for input from the console.
|
||||
|
||||
function promptAsync(question, sensitiveInput = false) {
|
||||
return new Promise((resolve) => {
|
||||
let rl = ReadLine.createInterface({
|
||||
input: process.stdin,
|
||||
output: sensitiveInput ? null : process.stdout,
|
||||
terminal: true
|
||||
});
|
||||
|
||||
g_AbortPromptFunc = () => {
|
||||
rl.close();
|
||||
resolve('');
|
||||
};
|
||||
|
||||
if (sensitiveInput) {
|
||||
// We have to write the question manually if we didn't give readline an output stream
|
||||
process.stdout.write(question);
|
||||
}
|
||||
|
||||
rl.question(question, (result) => {
|
||||
if (sensitiveInput) {
|
||||
// We have to manually print a newline
|
||||
process.stdout.write('\n');
|
||||
}
|
||||
|
||||
g_AbortPromptFunc = null;
|
||||
rl.close();
|
||||
resolve(result);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function abortPrompt() {
|
||||
if (!g_AbortPromptFunc) {
|
||||
return;
|
||||
}
|
||||
|
||||
g_AbortPromptFunc();
|
||||
process.stdout.write('\n');
|
||||
}
|
||||
|
||||
70
index.js
70
index.js
@@ -1,5 +1,3 @@
|
||||
require('@doctormckay/stats-reporter').setup(require('./package.json'));
|
||||
|
||||
const hex2b64 = require('node-bignumber').hex2b64;
|
||||
const Request = require('request');
|
||||
const RSA = require('node-bignumber').Key;
|
||||
@@ -16,6 +14,8 @@ module.exports = SteamCommunity;
|
||||
SteamCommunity.SteamID = SteamID;
|
||||
SteamCommunity.ConfirmationType = require('./resources/EConfirmationType.js');
|
||||
SteamCommunity.EResult = require('./resources/EResult.js');
|
||||
SteamCommunity.ESharedFileType = require('./resources/ESharedFileType.js');
|
||||
SteamCommunity.EFriendRelationship = require('./resources/EFriendRelationship.js');
|
||||
|
||||
|
||||
function SteamCommunity(options) {
|
||||
@@ -66,7 +66,7 @@ SteamCommunity.prototype.login = function(details, callback) {
|
||||
this._setCookie(Request.cookie('steamMachineAuth' + parts[0] + '=' + encodeURIComponent(parts[1])), true);
|
||||
}
|
||||
|
||||
var disableMobile = details.disableMobile;
|
||||
var disableMobile = typeof details.disableMobile == 'undefined' ? true : details.disableMobile;
|
||||
|
||||
var self = this;
|
||||
|
||||
@@ -124,7 +124,7 @@ SteamCommunity.prototype.login = function(details, callback) {
|
||||
"donotcache": Date.now()
|
||||
};
|
||||
|
||||
if(!disableMobile){
|
||||
if (!disableMobile) {
|
||||
formObj.oauth_client_id = "DE45CD61";
|
||||
formObj.oauth_scope = "read_profile write_profile read_client write_client";
|
||||
formObj.loginfriendlyname = "#login_emailauth_friendlyname_mobile";
|
||||
@@ -162,22 +162,20 @@ SteamCommunity.prototype.login = function(details, callback) {
|
||||
callback(error);
|
||||
} else if (!body.success) {
|
||||
callback(new Error(body.message || "Unknown error"));
|
||||
} else if (!disableMobile && !body.oauth) {
|
||||
callback(new Error("Malformed response"));
|
||||
} else {
|
||||
var sessionID = generateSessionID();
|
||||
var oAuth;
|
||||
var oAuth = {};
|
||||
self._setCookie(Request.cookie('sessionid=' + sessionID));
|
||||
|
||||
var cookies = self._jar.getCookieString("https://steamcommunity.com").split(';').map(function(cookie) {
|
||||
return cookie.trim();
|
||||
});
|
||||
|
||||
if (!disableMobile){
|
||||
if (!disableMobile && body.oauth) {
|
||||
oAuth = JSON.parse(body.oauth);
|
||||
self.steamID = new SteamID(oAuth.steamid);
|
||||
self.oAuthToken = oAuth.oauth_token;
|
||||
}else{
|
||||
} else {
|
||||
for(var i = 0; i < cookies.length; i++) {
|
||||
var parts = cookies[i].split('=');
|
||||
if(parts[0] == 'steamLogin') {
|
||||
@@ -191,7 +189,7 @@ SteamCommunity.prototype.login = function(details, callback) {
|
||||
|
||||
// Find the Steam Guard cookie
|
||||
var steamguard = null;
|
||||
for(var i = 0; i < cookies.length; i++) {
|
||||
for (var i = 0; i < cookies.length; i++) {
|
||||
var parts = cookies[i].split('=');
|
||||
if(parts[0] == 'steamMachineAuth' + self.steamID) {
|
||||
steamguard = self.steamID.toString() + '||' + decodeURIComponent(parts[1]);
|
||||
@@ -217,6 +215,12 @@ SteamCommunity.prototype.login = function(details, callback) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @param {string} steamguard
|
||||
* @param {string} token
|
||||
* @param {function} callback
|
||||
*/
|
||||
SteamCommunity.prototype.oAuthLogin = function(steamguard, token, callback) {
|
||||
steamguard = steamguard.split('||');
|
||||
var steamID = new SteamID(steamguard[0]);
|
||||
@@ -303,10 +307,14 @@ SteamCommunity.prototype.setCookies = function(cookies) {
|
||||
|
||||
this._setCookie(Request.cookie(cookie), !!(cookieName.match(/^steamMachineAuth/) || cookieName.match(/Secure$/)));
|
||||
});
|
||||
|
||||
// The account we're logged in as might have changed, so verify that our mobile access token (if any) is still valid
|
||||
// for this account.
|
||||
this._verifyMobileAccessToken();
|
||||
};
|
||||
|
||||
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 +333,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,19 +545,53 @@ 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');
|
||||
require('./components/market.js');
|
||||
require('./components/groups.js');
|
||||
require('./components/users.js');
|
||||
require('./components/sharedfiles.js');
|
||||
require('./components/inventoryhistory.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');
|
||||
require('./classes/CSteamSharedFile.js');
|
||||
require('./classes/CSteamUser.js');
|
||||
|
||||
/**
|
||||
|
||||
19
package.json
19
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "steamcommunity",
|
||||
"version": "3.40.0",
|
||||
"version": "3.46.0",
|
||||
"description": "Provides an interface for logging into and interacting with the Steam Community website",
|
||||
"keywords": [
|
||||
"steam",
|
||||
@@ -21,14 +21,17 @@
|
||||
"url": "https://github.com/DoctorMcKay/node-steamcommunity.git"
|
||||
},
|
||||
"dependencies": {
|
||||
"@doctormckay/stats-reporter": "^1.0.2",
|
||||
"request": "^2.86.0",
|
||||
"node-bignumber": "^1.2.1",
|
||||
"steamid": "^1.0.0",
|
||||
"xml2js": "^0.4.11",
|
||||
"async": "^2.6.3",
|
||||
"cheerio": "0.22.0",
|
||||
"async": "^2.1.4",
|
||||
"steam-totp": "^1.3.0"
|
||||
"image-size": "^0.8.2",
|
||||
"node-bignumber": "^1.2.1",
|
||||
"request": "^2.88.0",
|
||||
"steam-totp": "^1.5.0",
|
||||
"steamid": "^1.1.3",
|
||||
"xml2js": "^0.4.22"
|
||||
},
|
||||
"devDependencies": {
|
||||
"steam-session": "^1.2.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4.0.0"
|
||||
|
||||
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",
|
||||
};
|
||||
|
||||
13
resources/ESharedFileType.js
Normal file
13
resources/ESharedFileType.js
Normal file
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* @enum ESharedFileType
|
||||
*/
|
||||
module.exports = {
|
||||
"Screenshot": 0,
|
||||
"Artwork": 1,
|
||||
"Guide": 2,
|
||||
|
||||
// Value-to-name mapping for convenience
|
||||
"0": "Screenshot",
|
||||
"1": "Artwork",
|
||||
"2": "Guide"
|
||||
};
|
||||
Reference in New Issue
Block a user