steamcommunity 3.49.0 → 3.50.1

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.
@@ -1,225 +1,225 @@
1
- var SteamCommunity = require('../index.js');
2
- var Helpers = require('../components/helpers.js');
3
- var SteamID = require('steamid');
4
- var xml2js = require('xml2js');
5
-
6
- SteamCommunity.prototype.getSteamUser = function(id, callback) {
7
- if(typeof id !== 'string' && !Helpers.isSteamID(id)) {
8
- throw new Error("id parameter should be a user URL string or a SteamID object");
9
- }
10
-
11
- if(typeof id === 'object' && (id.universe != SteamID.Universe.PUBLIC || id.type != SteamID.Type.INDIVIDUAL)) {
12
- throw new Error("SteamID must stand for an individual account in the public universe");
13
- }
14
-
15
- var self = this;
16
- this.httpRequest("https://steamcommunity.com/" + (typeof id === 'string' ? "id/" + id : "profiles/" + id.toString()) + "/?xml=1", function(err, response, body) {
17
- if (err) {
18
- callback(err);
19
- return;
20
- }
21
-
22
- xml2js.parseString(body, function(err, result) {
23
- if(err || (!result.response && !result.profile)) {
24
- callback(err || new Error("No valid response"));
25
- return;
26
- }
27
-
28
- if(result.response && result.response.error && result.response.error.length) {
29
- callback(new Error(result.response.error[0]));
30
- return;
31
- }
32
-
33
- // Try and find custom URL from redirect
34
- var customurl = null;
35
- if(response.request.redirects && response.request.redirects.length) {
36
- var match = response.request.redirects[0].redirectUri.match(/https?:\/\/steamcommunity\.com\/id\/([^/])+\/\?xml=1/);
37
- if(match) {
38
- customurl = match[1];
39
- }
40
- }
41
-
42
- if(!result.profile.steamID64) {
43
- callback(new Error("No valid response"));
44
- return;
45
- }
46
-
47
- callback(null, new CSteamUser(self, result.profile, customurl));
48
- });
49
- }, "steamcommunity");
50
- };
51
-
52
- function CSteamUser(community, userData, customurl) {
53
- this._community = community;
54
-
55
- this.steamID = new SteamID(userData.steamID64[0]);
56
- this.name = processItem('steamID');
57
- this.onlineState = processItem('onlineState');
58
- this.stateMessage = processItem('stateMessage');
59
- this.privacyState = processItem('privacyState', 'uncreated');
60
- this.visibilityState = processItem('visibilityState');
61
- this.avatarHash = processItem('avatarIcon', '').match(/([0-9a-f]+)\.[a-z]+$/);
62
- if(this.avatarHash) {
63
- this.avatarHash = this.avatarHash[1];
64
- }
65
-
66
- this.vacBanned = processItem('vacBanned', false) == 1;
67
- this.tradeBanState = processItem('tradeBanState', 'None');
68
- this.isLimitedAccount = processItem('isLimitedAccount') == 1;
69
- this.customURL = processItem('customURL', customurl);
70
-
71
- if(this.visibilityState == 3) {
72
- let memberSinceValue = processItem('memberSince', '0').replace(/(\d{1,2})(st|nd|th)/, "$1");
73
-
74
- if (memberSinceValue.indexOf(',') === -1) {
75
- memberSinceValue += ', ' + new Date().getFullYear();
76
- }
77
-
78
- this.memberSince = new Date(memberSinceValue);
79
- this.location = processItem('location');
80
- this.realName = processItem('realname');
81
- this.summary = processItem('summary');
82
- } else {
83
- this.memberSince = null;
84
- this.location = null;
85
- this.realName = null;
86
- this.summary = null;
87
- }
88
-
89
- // Maybe handle mostPlayedGames?
90
-
91
- this.groups = null;
92
- this.primaryGroup = null;
93
-
94
- var self = this;
95
- if(userData.groups && userData.groups[0] && userData.groups[0].group) {
96
- this.groups = userData.groups[0].group.map(function(group) {
97
- if(group['$'] && group['$'].isPrimary === "1") {
98
- self.primaryGroup = new SteamID(group.groupID64[0]);
99
- }
100
-
101
- return new SteamID(group.groupID64[0]);
102
- });
103
- }
104
-
105
- function processItem(name, defaultVal) {
106
- if(!userData[name]) {
107
- return defaultVal;
108
- }
109
-
110
- return userData[name][0];
111
- }
112
- }
113
-
114
- CSteamUser.getAvatarURL = function(hash, size, protocol) {
115
- size = size || '';
116
- protocol = protocol || 'http://';
117
-
118
- hash = hash || "72f78b4c8cc1f62323f8a33f6d53e27db57c2252"; // The default "?" avatar
119
-
120
- var url = protocol + "steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/" + hash.substring(0, 2) + "/" + hash;
121
- if(size == 'full' || size == 'medium') {
122
- return url + "_" + size + ".jpg";
123
- } else {
124
- return url + ".jpg";
125
- }
126
- };
127
-
128
- CSteamUser.prototype.getAvatarURL = function(size, protocol) {
129
- return CSteamUser.getAvatarURL(this.avatarHash, size, protocol);
130
- };
131
-
132
- CSteamUser.prototype.addFriend = function(callback) {
133
- this._community.addFriend(this.steamID, callback);
134
- };
135
-
136
- CSteamUser.prototype.acceptFriendRequest = function(callback) {
137
- this._community.acceptFriendRequest(this.steamID, callback);
138
- };
139
-
140
- CSteamUser.prototype.removeFriend = function(callback) {
141
- this._community.removeFriend(this.steamID, callback);
142
-
143
- };
144
-
145
- CSteamUser.prototype.blockCommunication = function(callback) {
146
- this._community.blockCommunication(this.steamID, callback);
147
- };
148
-
149
- CSteamUser.prototype.unblockCommunication = function(callback) {
150
- this._community.unblockCommunication(this.steamID, callback);
151
- };
152
-
153
- CSteamUser.prototype.comment = function(message, callback) {
154
- this._community.postUserComment(this.steamID, message, callback);
155
- };
156
-
157
- CSteamUser.prototype.deleteComment = function(commentID, callback) {
158
- this._community.deleteUserComment(this.steamID, commentID, callback);
159
- };
160
-
161
- CSteamUser.prototype.getComments = function(options, callback) {
162
- this._community.getUserComments(this.steamID, options, callback);
163
- };
164
-
165
- CSteamUser.prototype.inviteToGroup = function(groupID, callback) {
166
- this._community.inviteUserToGroup(this.steamID, groupID, callback);
167
- };
168
-
169
- CSteamUser.prototype.follow = function(callback) {
170
- this._community.followUser(this.steamID, callback);
171
- };
172
-
173
- CSteamUser.prototype.unfollow = function(callback) {
174
- this._community.unfollowUser(this.steamID, callback);
175
- };
176
-
177
- CSteamUser.prototype.getAliases = function(callback) {
178
- this._community.getUserAliases(this.steamID, callback);
179
- };
180
-
181
- CSteamUser.prototype.getInventoryContexts = function(callback) {
182
- this._community.getUserInventoryContexts(this.steamID, callback);
183
- };
184
-
185
- /**
186
- * Get the contents of a user's inventory context.
187
- * @deprecated Use CSteamUser#getInventoryContents instead
188
- * @param {int} appID - The Steam application ID of the game for which you want an inventory
189
- * @param {int} contextID - The ID of the "context" within the game you want to retrieve
190
- * @param {boolean} tradableOnly - true to get only tradable items and currencies
191
- * @param callback
192
- */
193
- CSteamUser.prototype.getInventory = function(appID, contextID, tradableOnly, callback) {
194
- this._community.getUserInventory(this.steamID, appID, contextID, tradableOnly, callback);
195
- };
196
-
197
- /**
198
- * Get the contents of a user's inventory context.
199
- * @param {int} appID - The Steam application ID of the game for which you want an inventory
200
- * @param {int} contextID - The ID of the "context" within the game you want to retrieve
201
- * @param {boolean} tradableOnly - true to get only tradable items and currencies
202
- * @param {string} [language] - The language of item descriptions to return. Omit for default (which may either be English or your account's chosen language)
203
- * @param callback
204
- */
205
- CSteamUser.prototype.getInventoryContents = function(appID, contextID, tradableOnly, language, callback) {
206
- this._community.getUserInventoryContents(this.steamID, appID, contextID, tradableOnly, language, callback);
207
- };
208
-
209
- /**
210
- * Get the background URL of user's profile.
211
- * @param {function} callback
212
- */
213
- CSteamUser.prototype.getProfileBackground = function(callback) {
214
- this._community.getUserProfileBackground(this.steamID, callback);
215
- };
216
-
217
- /**
218
- * Upload an image to Steam and send it to the target user over chat.
219
- * @param {Buffer} imageContentsBuffer - The image contents, as a Buffer
220
- * @param {{spoiler?: boolean}} [options]
221
- * @param {function} callback
222
- */
223
- CSteamUser.prototype.sendImage = function(imageContentsBuffer, options, callback) {
224
- this._community.sendImageToUser(this.steamID, imageContentsBuffer, options, callback);
225
- };
1
+ var SteamCommunity = require('../index.js');
2
+ var Helpers = require('../components/helpers.js');
3
+ var SteamID = require('steamid');
4
+ var xml2js = require('xml2js');
5
+
6
+ SteamCommunity.prototype.getSteamUser = function(id, callback) {
7
+ if(typeof id !== 'string' && !Helpers.isSteamID(id)) {
8
+ throw new Error("id parameter should be a user URL string or a SteamID object");
9
+ }
10
+
11
+ if(typeof id === 'object' && (id.universe != SteamID.Universe.PUBLIC || id.type != SteamID.Type.INDIVIDUAL)) {
12
+ throw new Error("SteamID must stand for an individual account in the public universe");
13
+ }
14
+
15
+ var self = this;
16
+ this.httpRequest("https://steamcommunity.com/" + (typeof id === 'string' ? "id/" + id : "profiles/" + id.toString()) + "/?xml=1", function(err, response, body) {
17
+ if (err) {
18
+ callback(err);
19
+ return;
20
+ }
21
+
22
+ xml2js.parseString(body, function(err, result) {
23
+ if(err || (!result.response && !result.profile)) {
24
+ callback(err || new Error("No valid response"));
25
+ return;
26
+ }
27
+
28
+ if(result.response && result.response.error && result.response.error.length) {
29
+ callback(new Error(result.response.error[0]));
30
+ return;
31
+ }
32
+
33
+ // Try and find custom URL from redirect
34
+ var customurl = null;
35
+ if(response.request.redirects && response.request.redirects.length) {
36
+ var match = response.request.redirects[0].redirectUri.match(/https?:\/\/steamcommunity\.com\/id\/([^/])+\/\?xml=1/);
37
+ if(match) {
38
+ customurl = match[1];
39
+ }
40
+ }
41
+
42
+ if(!result.profile.steamID64) {
43
+ callback(new Error("No valid response"));
44
+ return;
45
+ }
46
+
47
+ callback(null, new CSteamUser(self, result.profile, customurl));
48
+ });
49
+ }, "steamcommunity");
50
+ };
51
+
52
+ function CSteamUser(community, userData, customurl) {
53
+ this._community = community;
54
+
55
+ this.steamID = new SteamID(userData.steamID64[0]);
56
+ this.name = processItem('steamID');
57
+ this.onlineState = processItem('onlineState');
58
+ this.stateMessage = processItem('stateMessage');
59
+ this.privacyState = processItem('privacyState', 'uncreated');
60
+ this.visibilityState = processItem('visibilityState');
61
+ this.avatarHash = processItem('avatarIcon', '').match(/([0-9a-f]+)\.[a-z]+$/);
62
+ if(this.avatarHash) {
63
+ this.avatarHash = this.avatarHash[1];
64
+ }
65
+
66
+ this.vacBanned = processItem('vacBanned', false) == 1;
67
+ this.tradeBanState = processItem('tradeBanState', 'None');
68
+ this.isLimitedAccount = processItem('isLimitedAccount') == 1;
69
+ this.customURL = processItem('customURL', customurl);
70
+
71
+ if(this.visibilityState == 3) {
72
+ let memberSinceValue = processItem('memberSince', '0').replace(/(\d{1,2})(st|nd|th)/, "$1");
73
+
74
+ if (memberSinceValue.indexOf(',') === -1) {
75
+ memberSinceValue += ', ' + new Date().getFullYear();
76
+ }
77
+
78
+ this.memberSince = new Date(memberSinceValue);
79
+ this.location = processItem('location');
80
+ this.realName = processItem('realname');
81
+ this.summary = processItem('summary');
82
+ } else {
83
+ this.memberSince = null;
84
+ this.location = null;
85
+ this.realName = null;
86
+ this.summary = null;
87
+ }
88
+
89
+ // Maybe handle mostPlayedGames?
90
+
91
+ this.groups = null;
92
+ this.primaryGroup = null;
93
+
94
+ var self = this;
95
+ if(userData.groups && userData.groups[0] && userData.groups[0].group) {
96
+ this.groups = userData.groups[0].group.map(function(group) {
97
+ if(group['$'] && group['$'].isPrimary === "1") {
98
+ self.primaryGroup = new SteamID(group.groupID64[0]);
99
+ }
100
+
101
+ return new SteamID(group.groupID64[0]);
102
+ });
103
+ }
104
+
105
+ function processItem(name, defaultVal) {
106
+ if(!userData[name]) {
107
+ return defaultVal;
108
+ }
109
+
110
+ return userData[name][0];
111
+ }
112
+ }
113
+
114
+ CSteamUser.getAvatarURL = function(hash, size, protocol) {
115
+ size = size || '';
116
+ protocol = protocol || 'http://';
117
+
118
+ hash = hash || "72f78b4c8cc1f62323f8a33f6d53e27db57c2252"; // The default "?" avatar
119
+
120
+ var url = protocol + "steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/" + hash.substring(0, 2) + "/" + hash;
121
+ if(size == 'full' || size == 'medium') {
122
+ return url + "_" + size + ".jpg";
123
+ } else {
124
+ return url + ".jpg";
125
+ }
126
+ };
127
+
128
+ CSteamUser.prototype.getAvatarURL = function(size, protocol) {
129
+ return CSteamUser.getAvatarURL(this.avatarHash, size, protocol);
130
+ };
131
+
132
+ CSteamUser.prototype.addFriend = function(callback) {
133
+ this._community.addFriend(this.steamID, callback);
134
+ };
135
+
136
+ CSteamUser.prototype.acceptFriendRequest = function(callback) {
137
+ this._community.acceptFriendRequest(this.steamID, callback);
138
+ };
139
+
140
+ CSteamUser.prototype.removeFriend = function(callback) {
141
+ this._community.removeFriend(this.steamID, callback);
142
+
143
+ };
144
+
145
+ CSteamUser.prototype.blockCommunication = function(callback) {
146
+ this._community.blockCommunication(this.steamID, callback);
147
+ };
148
+
149
+ CSteamUser.prototype.unblockCommunication = function(callback) {
150
+ this._community.unblockCommunication(this.steamID, callback);
151
+ };
152
+
153
+ CSteamUser.prototype.comment = function(message, callback) {
154
+ this._community.postUserComment(this.steamID, message, callback);
155
+ };
156
+
157
+ CSteamUser.prototype.deleteComment = function(commentID, callback) {
158
+ this._community.deleteUserComment(this.steamID, commentID, callback);
159
+ };
160
+
161
+ CSteamUser.prototype.getComments = function(options, callback) {
162
+ this._community.getUserComments(this.steamID, options, callback);
163
+ };
164
+
165
+ CSteamUser.prototype.inviteToGroup = function(groupID, callback) {
166
+ this._community.inviteUserToGroup(this.steamID, groupID, callback);
167
+ };
168
+
169
+ CSteamUser.prototype.follow = function(callback) {
170
+ this._community.followUser(this.steamID, callback);
171
+ };
172
+
173
+ CSteamUser.prototype.unfollow = function(callback) {
174
+ this._community.unfollowUser(this.steamID, callback);
175
+ };
176
+
177
+ CSteamUser.prototype.getAliases = function(callback) {
178
+ this._community.getUserAliases(this.steamID, callback);
179
+ };
180
+
181
+ CSteamUser.prototype.getInventoryContexts = function(callback) {
182
+ this._community.getUserInventoryContexts(this.steamID, callback);
183
+ };
184
+
185
+ /**
186
+ * Get the contents of a user's inventory context.
187
+ * @deprecated Use CSteamUser#getInventoryContents instead
188
+ * @param {int} appID - The Steam application ID of the game for which you want an inventory
189
+ * @param {int} contextID - The ID of the "context" within the game you want to retrieve
190
+ * @param {boolean} tradableOnly - true to get only tradable items and currencies
191
+ * @param callback
192
+ */
193
+ CSteamUser.prototype.getInventory = function(appID, contextID, tradableOnly, callback) {
194
+ this._community.getUserInventory(this.steamID, appID, contextID, tradableOnly, callback);
195
+ };
196
+
197
+ /**
198
+ * Get the contents of a user's inventory context.
199
+ * @param {int} appID - The Steam application ID of the game for which you want an inventory
200
+ * @param {int} contextID - The ID of the "context" within the game you want to retrieve
201
+ * @param {boolean} tradableOnly - true to get only tradable items and currencies
202
+ * @param {string} [language] - The language of item descriptions to return. Omit for default (which may either be English or your account's chosen language)
203
+ * @param callback
204
+ */
205
+ CSteamUser.prototype.getInventoryContents = function(appID, contextID, tradableOnly, language, callback) {
206
+ this._community.getUserInventoryContents(this.steamID, appID, contextID, tradableOnly, language, callback);
207
+ };
208
+
209
+ /**
210
+ * Get the background URL of user's profile.
211
+ * @param {function} callback
212
+ */
213
+ CSteamUser.prototype.getProfileBackground = function(callback) {
214
+ this._community.getUserProfileBackground(this.steamID, callback);
215
+ };
216
+
217
+ /**
218
+ * Upload an image to Steam and send it to the target user over chat.
219
+ * @param {Buffer} imageContentsBuffer - The image contents, as a Buffer
220
+ * @param {{spoiler?: boolean}} [options]
221
+ * @param {function} callback
222
+ */
223
+ CSteamUser.prototype.sendImage = function(imageContentsBuffer, options, callback) {
224
+ this._community.sendImageToUser(this.steamID, imageContentsBuffer, options, callback);
225
+ };