steamcommunity 3.44.3 → 3.45.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/FUNDING.yml +2 -2
- package/.idea/inspectionProfiles/Project_Default.xml +10 -10
- package/README.md +23 -23
- package/classes/CConfirmation.js +35 -35
- package/classes/CMarketItem.js +189 -189
- package/classes/CMarketSearchResult.js +89 -89
- package/classes/CSteamGroup.js +155 -155
- package/components/chat.js +283 -283
- package/components/groups.js +732 -732
- package/components/helpers.js +68 -56
- package/components/inventoryhistory.js +188 -188
- package/components/twofactor.js +152 -159
- package/components/webapi.js +118 -57
- package/examples/disable_twofactor.js +81 -62
- package/examples/edit-group-announcement.js +118 -118
- package/examples/enable_twofactor.js +131 -112
- package/index.js +597 -589
- package/package.json +1 -1
package/.github/FUNDING.yml
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
github: DoctorMcKay
|
|
2
|
-
custom: 'https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=N36YVAT42CZ4G&item_name=node%2dsteamcommunity¤cy_code=USD'
|
|
1
|
+
github: DoctorMcKay
|
|
2
|
+
custom: 'https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=N36YVAT42CZ4G&item_name=node%2dsteamcommunity¤cy_code=USD'
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
<component name="InspectionProjectProfileManager">
|
|
2
|
-
<profile version="1.0">
|
|
3
|
-
<option name="myName" value="Project Default" />
|
|
4
|
-
<inspection_tool class="ES6ConvertRequireIntoImport" enabled="false" level="INFORMATION" enabled_by_default="false" />
|
|
5
|
-
<inspection_tool class="ES6ConvertToForOf" enabled="false" level="INFORMATION" enabled_by_default="false" />
|
|
6
|
-
<inspection_tool class="ES6ConvertVarToLetConst" enabled="false" level="WARNING" enabled_by_default="false" />
|
|
7
|
-
<inspection_tool class="JSEqualityComparisonWithCoercion" enabled="false" level="WARNING" enabled_by_default="false" />
|
|
8
|
-
<inspection_tool class="JSFunctionExpressionToArrowFunction" enabled="false" level="INFORMATION" enabled_by_default="false" />
|
|
9
|
-
<inspection_tool class="JSStringConcatenationToES6Template" enabled="false" level="INFORMATION" enabled_by_default="false" />
|
|
10
|
-
</profile>
|
|
1
|
+
<component name="InspectionProjectProfileManager">
|
|
2
|
+
<profile version="1.0">
|
|
3
|
+
<option name="myName" value="Project Default" />
|
|
4
|
+
<inspection_tool class="ES6ConvertRequireIntoImport" enabled="false" level="INFORMATION" enabled_by_default="false" />
|
|
5
|
+
<inspection_tool class="ES6ConvertToForOf" enabled="false" level="INFORMATION" enabled_by_default="false" />
|
|
6
|
+
<inspection_tool class="ES6ConvertVarToLetConst" enabled="false" level="WARNING" enabled_by_default="false" />
|
|
7
|
+
<inspection_tool class="JSEqualityComparisonWithCoercion" enabled="false" level="WARNING" enabled_by_default="false" />
|
|
8
|
+
<inspection_tool class="JSFunctionExpressionToArrowFunction" enabled="false" level="INFORMATION" enabled_by_default="false" />
|
|
9
|
+
<inspection_tool class="JSStringConcatenationToES6Template" enabled="false" level="INFORMATION" enabled_by_default="false" />
|
|
10
|
+
</profile>
|
|
11
11
|
</component>
|
package/README.md
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
# Steam Community for Node.js
|
|
2
|
-
[](https://npmjs.com/package/steamcommunity)
|
|
3
|
-
[](https://npmjs.com/package/steamcommunity)
|
|
4
|
-
[](https://david-dm.org/DoctorMcKay/node-steamcommunity)
|
|
5
|
-
[](https://github.com/DoctorMcKay/node-steamcommunity/blob/master/LICENSE)
|
|
6
|
-
[](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=N36YVAT42CZ4G&item_name=node%2dsteamcommunity¤cy_code=USD)
|
|
7
|
-
|
|
8
|
-
This module provides an easy interface for the Steam Community website. This module can be used to simply login to steamcommunity.com for use with other libraries, or to interact with steamcommunity.com.
|
|
9
|
-
|
|
10
|
-
It supports Steam Guard and CAPTCHAs.
|
|
11
|
-
|
|
12
|
-
**Have a question about the module or coding in general? *Do not create a GitHub issue.* GitHub issues are for feature
|
|
13
|
-
requests and bug reports. Instead, post in the [dedicated forum](https://dev.doctormckay.com/forum/8-node-steamcommunity/).
|
|
14
|
-
Such issues may be ignored!**
|
|
15
|
-
|
|
16
|
-
# Documentation
|
|
17
|
-
|
|
18
|
-
Documentation is available on the [GitHub wiki](https://github.com/DoctorMcKay/node-steamcommunity/wiki).
|
|
19
|
-
|
|
20
|
-
# Support
|
|
21
|
-
|
|
22
|
-
Report bugs on the [issue tracker](https://github.com/DoctorMcKay/node-steamcommunity/issues) or ask questions
|
|
23
|
-
on the [dedicated forum](https://dev.doctormckay.com/forum/8-node-steamcommunity/).
|
|
1
|
+
# Steam Community for Node.js
|
|
2
|
+
[](https://npmjs.com/package/steamcommunity)
|
|
3
|
+
[](https://npmjs.com/package/steamcommunity)
|
|
4
|
+
[](https://david-dm.org/DoctorMcKay/node-steamcommunity)
|
|
5
|
+
[](https://github.com/DoctorMcKay/node-steamcommunity/blob/master/LICENSE)
|
|
6
|
+
[](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=N36YVAT42CZ4G&item_name=node%2dsteamcommunity¤cy_code=USD)
|
|
7
|
+
|
|
8
|
+
This module provides an easy interface for the Steam Community website. This module can be used to simply login to steamcommunity.com for use with other libraries, or to interact with steamcommunity.com.
|
|
9
|
+
|
|
10
|
+
It supports Steam Guard and CAPTCHAs.
|
|
11
|
+
|
|
12
|
+
**Have a question about the module or coding in general? *Do not create a GitHub issue.* GitHub issues are for feature
|
|
13
|
+
requests and bug reports. Instead, post in the [dedicated forum](https://dev.doctormckay.com/forum/8-node-steamcommunity/).
|
|
14
|
+
Such issues may be ignored!**
|
|
15
|
+
|
|
16
|
+
# Documentation
|
|
17
|
+
|
|
18
|
+
Documentation is available on the [GitHub wiki](https://github.com/DoctorMcKay/node-steamcommunity/wiki).
|
|
19
|
+
|
|
20
|
+
# Support
|
|
21
|
+
|
|
22
|
+
Report bugs on the [issue tracker](https://github.com/DoctorMcKay/node-steamcommunity/issues) or ask questions
|
|
23
|
+
on the [dedicated forum](https://dev.doctormckay.com/forum/8-node-steamcommunity/).
|
package/classes/CConfirmation.js
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
var SteamCommunity = require('../index.js');
|
|
2
|
-
|
|
3
|
-
module.exports = CConfirmation;
|
|
4
|
-
|
|
5
|
-
function CConfirmation(community, data) {
|
|
6
|
-
Object.defineProperty(this, "_community", {"value": community});
|
|
7
|
-
|
|
8
|
-
this.id = data.id.toString();
|
|
9
|
-
this.type = data.type;
|
|
10
|
-
this.creator = data.creator.toString();
|
|
11
|
-
this.key = data.key;
|
|
12
|
-
this.title = data.title;
|
|
13
|
-
this.receiving = data.receiving;
|
|
14
|
-
this.time = data.time;
|
|
15
|
-
this.icon = data.icon;
|
|
16
|
-
this.offerID = this.type == SteamCommunity.ConfirmationType.Trade ? this.creator : null;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
CConfirmation.prototype.getOfferID = function(time, key, callback) {
|
|
20
|
-
if (this.type && this.creator) {
|
|
21
|
-
if (this.type != SteamCommunity.ConfirmationType.Trade) {
|
|
22
|
-
callback(new Error("Not a trade confirmation"));
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
callback(null, this.creator);
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
this._community.getConfirmationOfferID(this.id, time, key, callback);
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
CConfirmation.prototype.respond = function(time, key, accept, callback) {
|
|
34
|
-
this._community.respondToConfirmation(this.id, this.key, time, key, accept, callback);
|
|
35
|
-
};
|
|
1
|
+
var SteamCommunity = require('../index.js');
|
|
2
|
+
|
|
3
|
+
module.exports = CConfirmation;
|
|
4
|
+
|
|
5
|
+
function CConfirmation(community, data) {
|
|
6
|
+
Object.defineProperty(this, "_community", {"value": community});
|
|
7
|
+
|
|
8
|
+
this.id = data.id.toString();
|
|
9
|
+
this.type = data.type;
|
|
10
|
+
this.creator = data.creator.toString();
|
|
11
|
+
this.key = data.key;
|
|
12
|
+
this.title = data.title;
|
|
13
|
+
this.receiving = data.receiving;
|
|
14
|
+
this.time = data.time;
|
|
15
|
+
this.icon = data.icon;
|
|
16
|
+
this.offerID = this.type == SteamCommunity.ConfirmationType.Trade ? this.creator : null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
CConfirmation.prototype.getOfferID = function(time, key, callback) {
|
|
20
|
+
if (this.type && this.creator) {
|
|
21
|
+
if (this.type != SteamCommunity.ConfirmationType.Trade) {
|
|
22
|
+
callback(new Error("Not a trade confirmation"));
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
callback(null, this.creator);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
this._community.getConfirmationOfferID(this.id, time, key, callback);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
CConfirmation.prototype.respond = function(time, key, accept, callback) {
|
|
34
|
+
this._community.respondToConfirmation(this.id, this.key, time, key, accept, callback);
|
|
35
|
+
};
|
package/classes/CMarketItem.js
CHANGED
|
@@ -1,189 +1,189 @@
|
|
|
1
|
-
var SteamCommunity = require('../index.js');
|
|
2
|
-
var Cheerio = require('cheerio');
|
|
3
|
-
|
|
4
|
-
SteamCommunity.prototype.getMarketItem = function(appid, hashName, currency, callback) {
|
|
5
|
-
if (typeof currency == "function") {
|
|
6
|
-
callback = currency;
|
|
7
|
-
currency = 1;
|
|
8
|
-
}
|
|
9
|
-
var self = this;
|
|
10
|
-
this.httpRequest("https://steamcommunity.com/market/listings/" + appid + "/" + encodeURIComponent(hashName), function(err, response, body) {
|
|
11
|
-
if (err) {
|
|
12
|
-
callback(err);
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
var $ = Cheerio.load(body);
|
|
17
|
-
if($('.market_listing_table_message') && $('.market_listing_table_message').text().trim() == 'There are no listings for this item.') {
|
|
18
|
-
callback(new Error("There are no listings for this item."));
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
var item = new CMarketItem(appid, hashName, self, body, $);
|
|
23
|
-
item.updatePrice(currency, function(err) {
|
|
24
|
-
if(err) {
|
|
25
|
-
callback(err);
|
|
26
|
-
} else {
|
|
27
|
-
callback(null, item);
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
}, "steamcommunity");
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
function CMarketItem(appid, hashName, community, body, $) {
|
|
34
|
-
this._appid = appid;
|
|
35
|
-
this._hashName = hashName;
|
|
36
|
-
this._community = community;
|
|
37
|
-
this._$ = $;
|
|
38
|
-
|
|
39
|
-
this._country = "US";
|
|
40
|
-
var match = body.match(/var g_strCountryCode = "([^"]+)";/);
|
|
41
|
-
if(match) {
|
|
42
|
-
this._country = match[1];
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
this._language = "english";
|
|
46
|
-
match = body.match(/var g_strLanguage = "([^"]+)";/);
|
|
47
|
-
if(match) {
|
|
48
|
-
this._language = match[1];
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
this.commodity = false;
|
|
52
|
-
match = body.match(/Market_LoadOrderSpread\(\s*(\d+)\s*\);/);
|
|
53
|
-
if(match) {
|
|
54
|
-
this.commodity = true;
|
|
55
|
-
this.commodityID = parseInt(match[1], 10);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
this.medianSalePrices = null;
|
|
59
|
-
match = body.match(/var line1=([^;]+);/);
|
|
60
|
-
if(match) {
|
|
61
|
-
try {
|
|
62
|
-
this.medianSalePrices = JSON.parse(match[1]);
|
|
63
|
-
this.medianSalePrices = this.medianSalePrices.map(function(item) {
|
|
64
|
-
return {
|
|
65
|
-
"hour": new Date(item[0]),
|
|
66
|
-
"price": item[1],
|
|
67
|
-
"quantity": parseInt(item[2], 10)
|
|
68
|
-
};
|
|
69
|
-
});
|
|
70
|
-
} catch(e) {
|
|
71
|
-
// ignore
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
this.firstAsset = null;
|
|
76
|
-
this.assets = null;
|
|
77
|
-
match = body.match(/var g_rgAssets = (.*);/);
|
|
78
|
-
if (match) {
|
|
79
|
-
try {
|
|
80
|
-
this.assets = JSON.parse(match[1]);
|
|
81
|
-
this.assets = this.assets[appid];
|
|
82
|
-
this.assets = this.assets[Object.keys(this.assets)[0]];
|
|
83
|
-
this.firstAsset = this.assets[Object.keys(this.assets)[0]];
|
|
84
|
-
} catch (e) {
|
|
85
|
-
// ignore
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
this.quantity = 0;
|
|
90
|
-
this.lowestPrice = 0;
|
|
91
|
-
// TODO: Buying listings and placing buy orders
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
CMarketItem.prototype.updatePrice = function (currency, callback) {
|
|
95
|
-
if (this.commodity) {
|
|
96
|
-
this.updatePriceForCommodity(currency, callback);
|
|
97
|
-
} else {
|
|
98
|
-
this.updatePriceForNonCommodity(currency, callback);
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
CMarketItem.prototype.updatePriceForCommodity = function(currency, callback) {
|
|
103
|
-
if(!this.commodity) {
|
|
104
|
-
throw new Error("Cannot update price for non-commodity item");
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
var self = this;
|
|
108
|
-
this._community.httpRequest({
|
|
109
|
-
"uri": "https://steamcommunity.com/market/itemordershistogram?country=US&language=english¤cy=" + currency + "&item_nameid=" + this.commodityID,
|
|
110
|
-
"json": true
|
|
111
|
-
}, function(err, response, body) {
|
|
112
|
-
if (err) {
|
|
113
|
-
callback(err);
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if(body.success != 1) {
|
|
118
|
-
if(callback) {
|
|
119
|
-
callback(new Error("Error " + body.success));
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
var match = (body.sell_order_summary || '').match(/<span class="market_commodity_orders_header_promote">(\d+)<\/span>/);
|
|
126
|
-
if(match) {
|
|
127
|
-
self.quantity = parseInt(match[1], 10);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
self.buyQuantity = 0;
|
|
131
|
-
match = (body.buy_order_summary || '').match(/<span class="market_commodity_orders_header_promote">(\d+)<\/span>/);
|
|
132
|
-
if(match) {
|
|
133
|
-
self.buyQuantity = parseInt(match[1], 10);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
self.lowestPrice = parseInt(body.lowest_sell_order, 10);
|
|
137
|
-
self.highestBuyOrder = parseInt(body.highest_buy_order, 10);
|
|
138
|
-
|
|
139
|
-
// TODO: The tables?
|
|
140
|
-
if(callback) {
|
|
141
|
-
callback(null);
|
|
142
|
-
}
|
|
143
|
-
}, "steamcommunity");
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
CMarketItem.prototype.updatePriceForNonCommodity = function (currency, callback) {
|
|
147
|
-
if(this.commodity) {
|
|
148
|
-
throw new Error("Cannot update price for commodity item");
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
var self = this;
|
|
152
|
-
this._community.httpRequest({
|
|
153
|
-
"uri": "https://steamcommunity.com/market/listings/" +
|
|
154
|
-
this._appid + "/" +
|
|
155
|
-
encodeURIComponent(this._hashName) +
|
|
156
|
-
"/render/?query=&start=0&count=10&country=US&language=english¤cy=" + currency,
|
|
157
|
-
"json": true
|
|
158
|
-
}, function(err, response, body) {
|
|
159
|
-
if (err) {
|
|
160
|
-
callback(err);
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
if (body.success != 1) {
|
|
165
|
-
callback && callback(new Error("Error " + body.success));
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
var match = body.total_count;
|
|
170
|
-
if (match) {
|
|
171
|
-
self.quantity = parseInt(match, 10);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
var lowestPrice;
|
|
175
|
-
var $ = Cheerio.load(body.results_html);
|
|
176
|
-
match = $(".market_listing_price.market_listing_price_with_fee");
|
|
177
|
-
if (match) {
|
|
178
|
-
for (var i = 0; i < match.length; i++) {
|
|
179
|
-
lowestPrice = parseFloat($(match[i]).text().replace(",", ".").replace(/[^\d.]/g, ''));
|
|
180
|
-
if (!isNaN(lowestPrice)) {
|
|
181
|
-
self.lowestPrice = lowestPrice;
|
|
182
|
-
break;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
callback && callback(null);
|
|
188
|
-
}, "steamcommunity");
|
|
189
|
-
};
|
|
1
|
+
var SteamCommunity = require('../index.js');
|
|
2
|
+
var Cheerio = require('cheerio');
|
|
3
|
+
|
|
4
|
+
SteamCommunity.prototype.getMarketItem = function(appid, hashName, currency, callback) {
|
|
5
|
+
if (typeof currency == "function") {
|
|
6
|
+
callback = currency;
|
|
7
|
+
currency = 1;
|
|
8
|
+
}
|
|
9
|
+
var self = this;
|
|
10
|
+
this.httpRequest("https://steamcommunity.com/market/listings/" + appid + "/" + encodeURIComponent(hashName), function(err, response, body) {
|
|
11
|
+
if (err) {
|
|
12
|
+
callback(err);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
var $ = Cheerio.load(body);
|
|
17
|
+
if($('.market_listing_table_message') && $('.market_listing_table_message').text().trim() == 'There are no listings for this item.') {
|
|
18
|
+
callback(new Error("There are no listings for this item."));
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
var item = new CMarketItem(appid, hashName, self, body, $);
|
|
23
|
+
item.updatePrice(currency, function(err) {
|
|
24
|
+
if(err) {
|
|
25
|
+
callback(err);
|
|
26
|
+
} else {
|
|
27
|
+
callback(null, item);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}, "steamcommunity");
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
function CMarketItem(appid, hashName, community, body, $) {
|
|
34
|
+
this._appid = appid;
|
|
35
|
+
this._hashName = hashName;
|
|
36
|
+
this._community = community;
|
|
37
|
+
this._$ = $;
|
|
38
|
+
|
|
39
|
+
this._country = "US";
|
|
40
|
+
var match = body.match(/var g_strCountryCode = "([^"]+)";/);
|
|
41
|
+
if(match) {
|
|
42
|
+
this._country = match[1];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
this._language = "english";
|
|
46
|
+
match = body.match(/var g_strLanguage = "([^"]+)";/);
|
|
47
|
+
if(match) {
|
|
48
|
+
this._language = match[1];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
this.commodity = false;
|
|
52
|
+
match = body.match(/Market_LoadOrderSpread\(\s*(\d+)\s*\);/);
|
|
53
|
+
if(match) {
|
|
54
|
+
this.commodity = true;
|
|
55
|
+
this.commodityID = parseInt(match[1], 10);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
this.medianSalePrices = null;
|
|
59
|
+
match = body.match(/var line1=([^;]+);/);
|
|
60
|
+
if(match) {
|
|
61
|
+
try {
|
|
62
|
+
this.medianSalePrices = JSON.parse(match[1]);
|
|
63
|
+
this.medianSalePrices = this.medianSalePrices.map(function(item) {
|
|
64
|
+
return {
|
|
65
|
+
"hour": new Date(item[0]),
|
|
66
|
+
"price": item[1],
|
|
67
|
+
"quantity": parseInt(item[2], 10)
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
} catch(e) {
|
|
71
|
+
// ignore
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
this.firstAsset = null;
|
|
76
|
+
this.assets = null;
|
|
77
|
+
match = body.match(/var g_rgAssets = (.*);/);
|
|
78
|
+
if (match) {
|
|
79
|
+
try {
|
|
80
|
+
this.assets = JSON.parse(match[1]);
|
|
81
|
+
this.assets = this.assets[appid];
|
|
82
|
+
this.assets = this.assets[Object.keys(this.assets)[0]];
|
|
83
|
+
this.firstAsset = this.assets[Object.keys(this.assets)[0]];
|
|
84
|
+
} catch (e) {
|
|
85
|
+
// ignore
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
this.quantity = 0;
|
|
90
|
+
this.lowestPrice = 0;
|
|
91
|
+
// TODO: Buying listings and placing buy orders
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
CMarketItem.prototype.updatePrice = function (currency, callback) {
|
|
95
|
+
if (this.commodity) {
|
|
96
|
+
this.updatePriceForCommodity(currency, callback);
|
|
97
|
+
} else {
|
|
98
|
+
this.updatePriceForNonCommodity(currency, callback);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
CMarketItem.prototype.updatePriceForCommodity = function(currency, callback) {
|
|
103
|
+
if(!this.commodity) {
|
|
104
|
+
throw new Error("Cannot update price for non-commodity item");
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
var self = this;
|
|
108
|
+
this._community.httpRequest({
|
|
109
|
+
"uri": "https://steamcommunity.com/market/itemordershistogram?country=US&language=english¤cy=" + currency + "&item_nameid=" + this.commodityID,
|
|
110
|
+
"json": true
|
|
111
|
+
}, function(err, response, body) {
|
|
112
|
+
if (err) {
|
|
113
|
+
callback(err);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if(body.success != 1) {
|
|
118
|
+
if(callback) {
|
|
119
|
+
callback(new Error("Error " + body.success));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
var match = (body.sell_order_summary || '').match(/<span class="market_commodity_orders_header_promote">(\d+)<\/span>/);
|
|
126
|
+
if(match) {
|
|
127
|
+
self.quantity = parseInt(match[1], 10);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
self.buyQuantity = 0;
|
|
131
|
+
match = (body.buy_order_summary || '').match(/<span class="market_commodity_orders_header_promote">(\d+)<\/span>/);
|
|
132
|
+
if(match) {
|
|
133
|
+
self.buyQuantity = parseInt(match[1], 10);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
self.lowestPrice = parseInt(body.lowest_sell_order, 10);
|
|
137
|
+
self.highestBuyOrder = parseInt(body.highest_buy_order, 10);
|
|
138
|
+
|
|
139
|
+
// TODO: The tables?
|
|
140
|
+
if(callback) {
|
|
141
|
+
callback(null);
|
|
142
|
+
}
|
|
143
|
+
}, "steamcommunity");
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
CMarketItem.prototype.updatePriceForNonCommodity = function (currency, callback) {
|
|
147
|
+
if(this.commodity) {
|
|
148
|
+
throw new Error("Cannot update price for commodity item");
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
var self = this;
|
|
152
|
+
this._community.httpRequest({
|
|
153
|
+
"uri": "https://steamcommunity.com/market/listings/" +
|
|
154
|
+
this._appid + "/" +
|
|
155
|
+
encodeURIComponent(this._hashName) +
|
|
156
|
+
"/render/?query=&start=0&count=10&country=US&language=english¤cy=" + currency,
|
|
157
|
+
"json": true
|
|
158
|
+
}, function(err, response, body) {
|
|
159
|
+
if (err) {
|
|
160
|
+
callback(err);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (body.success != 1) {
|
|
165
|
+
callback && callback(new Error("Error " + body.success));
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
var match = body.total_count;
|
|
170
|
+
if (match) {
|
|
171
|
+
self.quantity = parseInt(match, 10);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
var lowestPrice;
|
|
175
|
+
var $ = Cheerio.load(body.results_html);
|
|
176
|
+
match = $(".market_listing_price.market_listing_price_with_fee");
|
|
177
|
+
if (match) {
|
|
178
|
+
for (var i = 0; i < match.length; i++) {
|
|
179
|
+
lowestPrice = parseFloat($(match[i]).text().replace(",", ".").replace(/[^\d.]/g, ''));
|
|
180
|
+
if (!isNaN(lowestPrice)) {
|
|
181
|
+
self.lowestPrice = lowestPrice;
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
callback && callback(null);
|
|
188
|
+
}, "steamcommunity");
|
|
189
|
+
};
|