-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclasses_Community.js.html
More file actions
476 lines (398 loc) · 14 KB
/
Copy pathclasses_Community.js.html
File metadata and controls
476 lines (398 loc) · 14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: classes/Community.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: classes/Community.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>Community.prototype.__proto__ = require('events').EventEmitter.prototype;
const EResult = require("../enums/EResult");
const SteamID = require('steam-tradeoffer-manager').SteamID;
/**
* A class to handle all community functions
* @param community
* @param Auth
* @param logger
* @constructor
*/
function Community(community, Auth, logger) {
// Ensure account values are valid
var self = this;
self.community = community;
self.Auth = Auth;
self.logger = logger;
}
/**
* Upvote an attachement file on SteamCommunity
* @param sharedFileId
* @param callbackErrorOnly
*/
Community.prototype.upvoteSharedFile = function (sharedFileId, callbackErrorOnly) {
var self = this;
var options = {
form: {
'sessionid': self.Auth.sessionid,
'id': sharedFileId
}
};
self.community.httpRequestPost('https://steamcommunity.com/sharedfiles/voteup', options, function (error, response, body) {
if (response.statusCode == 200 && JSON.parse(body).success == 1)
callbackErrorOnly(undefined);
else
callbackErrorOnly(error || EResult[JSON.parse(body).success]);
});
};
/**
* Downvote an attachement file on SteamCommunity.
* @param sharedFileId
* @param callbackErrorOnly
*/
Community.prototype.downvoteSharedFile = function (sharedFileId, callbackErrorOnly) {
var self = this;
var options = {
form: {
'sessionid': self.Auth.sessionid,
'id': sharedFileId
}
};
self.community.httpRequestPost('https://steamcommunity.com/sharedfiles/votedown', options, function (error, response, body) {
if (response.statusCode == 200 && JSON.parse(body).success == 1)
callbackErrorOnly(undefined);
else
callbackErrorOnly(error || EResult[JSON.parse(body).success]);
});
};
/**
* Preview an attachement file on SteamCommunity to increase the unique views of a certain attachment
* @param sharedFileId
* @param callbackErrorOnly
*/
Community.prototype.previewSharedFile = function (sharedFileId, callbackErrorOnly) {
var self = this;
var options = {};
self.community.httpRequestGet('http://steamcommunity.com/sharedfiles/filedetails/?id=' + sharedFileId, options, function (error, response, body) {
if (response.statusCode == 200)
callbackErrorOnly(undefined);
else
callbackErrorOnly(error);
});
};
/**
* Favourite an attachement file on SteamCommunity.
* @param sharedFileId
* @param sharedFileAppId
* @param callbackErrorOnly
*/
Community.prototype.favouriteSharedFile = function (sharedFileId, sharedFileAppId, callbackErrorOnly) {
var self = this;
var options = {
form: {
'sessionid': self.Auth.sessionid,
'id': sharedFileId,
'appid': sharedFileAppId
}
};
self.community.httpRequestPost('http://steamcommunity.com/sharedfiles/favorite', options, function (error, response, body) {
if (!error)
callbackErrorOnly(undefined);
else
callbackErrorOnly(error || EResult[JSON.parse(body).success]);
});
};
/**
* Subscribe to an attachement file on SteamCommunity.
* @param sharedFileId
* @param sharedFileAppId
* @param callbackErrorOnly
*/
Community.prototype.subscribeSharedFile = function (sharedFileId, sharedFileAppId, callbackErrorOnly) {
var self = this;
var options = {
form: {
'sessionid': self.Auth.sessionid,
'id': sharedFileId,
'appid': sharedFileAppId
}
};
self.community.httpRequestPost('http://steamcommunity.com/sharedfiles/subscribe', options, function (error, response, body) {
if (!error)
callbackErrorOnly(undefined);
else
callbackErrorOnly(error || EResult[JSON.parse(body).success]);
});
};
/**
* Unsubscribe to an attachement file on SteamCommunity.
* @param sharedFileId
* @param sharedFileAppId
* @param callbackErrorOnly
*/
Community.prototype.unsubscribeSharedFile = function (sharedFileId, sharedFileAppId, callbackErrorOnly) {
var self = this;
var options = {
form: {
'sessionid': self.Auth.sessionid,
'id': sharedFileId,
'appid': sharedFileAppId
}
};
self.community.httpRequestPost('http://steamcommunity.com/sharedfiles/unsubscribe', options, function (error, response, body) {
if (!error)
callbackErrorOnly(undefined);
else
callbackErrorOnly(error || EResult[JSON.parse(body).success]);
});
};
/**
* Unfavourite an attachement file on SteamCommunity.
* @param sharedFileId
* @param sharedFileAppId
* @param callbackErrorOnly
*/
Community.prototype.unfavouriteSharedFile = function (sharedFileId, sharedFileAppId, callbackErrorOnly) {
var self = this;
var options = {
form: {
'sessionid': self.Auth.sessionid,
'id': sharedFileId,
'appid': sharedFileAppId
}
};
self.community.httpRequestPost('http://steamcommunity.com/sharedfiles/unfavorite', options, function (error, response, body) {
if (!error)
callbackErrorOnly(undefined);
else
callbackErrorOnly(error || EResult[JSON.parse(body).success]);
});
};
/**
* Comment on an attachement file on SteamCommunity.
* @param comment
* @param sharedFileId
* @param fileIdOwner
* @param callbackErrorOnly
*/
Community.prototype.commentSharedFile = function (comment, sharedFileId, fileIdOwner, callbackErrorOnly) {
var self = this;
var options = {
form: {
'sessionid': self.Auth.sessionid,
'comment': comment
}
};
self.community.httpRequestPost('http://steamcommunity.com/comment/PublishedFile_Public/post/' + fileIdOwner + '/' + sharedFileId + '/', options, function (error, response, body) {
if (!error)
callbackErrorOnly(undefined);
else
callbackErrorOnly(error || EResult[JSON.parse(body).success]);
});
};
/**
* Delete comment on an attachement file on SteamCommunity.
* @param comment
* @param sharedFileId
* @param fileIdOwner
* @param callbackErrorOnly
*/
Community.prototype.deleteCommentSharedFile = function (commentId, sharedFileId, fileIdOwner, callbackErrorOnly) {
var self = this;
var options = {
form: {
'sessionid': self.Auth.sessionid,
'gidcomment': commentId
}
};
self.community.httpRequestPost('http://steamcommunity.com/comment/PublishedFile_Public/delete/' + fileIdOwner + '/' + sharedFileId + '/', options, function (error, response, body) {
if (!error)
callbackErrorOnly(undefined);
else
callbackErrorOnly(error || EResult[JSON.parse(body).success]);
});
};
/**
* Follow a user on SteamCommunity.
* @param steamid | profile name or steamid2, steamid3, steamid64
* @param callbackErrorOnly
*/
Community.prototype.followPublisher = function (steamid, callbackErrorOnly) {
var self = this;
var user = null;
try {
var steamID = new SteamID(steamid);
user = 'profiles/' + steamID.getSteamID64();
} catch (e){
user = 'id/' + steamid;
}
var options = {
form: {
'sessionid': self.Auth.sessionid
}
};
self.community.httpRequestPost('https://steamcommunity.com/' + user + '/followuser/', options, function (error, response, body) {
if (response.statusCode == 200 && JSON.parse(body).success == 1)
callbackErrorOnly(undefined);
else
callbackErrorOnly(error || EResult[JSON.parse(body).success]);
});
};
/**
* Unfollow a user on SteamCommunity.
* @param steamid | SteamID object or profile name
* @param callbackErrorOnly
*/
Community.prototype.unfollowPublisher = function (steamid, callbackErrorOnly) {
var self = this;
var user = null;
try {
var steamID = new SteamID(steamid);
user = 'profiles/' + steamID.getSteamID64();
} catch (e){
user = 'id/' + steamid;
}
var options = {
form: {
'sessionid': self.Auth.sessionid
}
};
self.community.httpRequestPost('https://steamcommunity.com/' + user + '/unfollowuser/', options, function (error, response, body) {
if (response.statusCode == 200 && JSON.parse(body).success == 1)
callbackErrorOnly(undefined);
else
callbackErrorOnly(error || EResult[JSON.parse(body).success]);
});
};
/**
* Invite a user on SteamCommunity to a group.
* @param groupID
* @param steamIDInvitee | Either an array list of steamid's or a single steamid. Must be an array object if list.
* @param callbackErrorOnly
*/
Community.prototype.inviteToGroup = function (groupID, steamIDInvitee, callbackErrorOnly) {
var self = this;
var options = {
form: {
json: 1,
type: 'groupInvite',
group: groupID,
sessionID: self.Auth.sessionid
}
};
if ( steamIDInvitee instanceof Array )
options.form.invitee_list = JSON.stringify( steamIDInvitee );
else
options.form.invitee = steamIDInvitee;
self.community.httpRequestPost('https://steamcommunity.com/actions/GroupInvite', options, function (error, response, body) {
if (response.statusCode == 200 && JSON.parse(body).success == 1)
callbackErrorOnly(undefined);
else if (response.statusCode == 200 && JSON.parse(body).duplicate)
callbackErrorOnly("Failed to send one or more invites due to a user being already invited or in the group by " + self.Auth.accountName);
else if (response.statusCode == 403)
callbackErrorOnly(self.Auth.accountName + " is not part of the group, therefore unable to invite users.");
else
callbackErrorOnly(error || EResult[JSON.parse(body).success]);
});
};
/**
* Join a group
* @param groupID
* @param callbackErrorOnly
*/
Community.prototype.joinGroup = function (groupID, callbackErrorOnly) {
var self = this;
self.community.getSteamGroup(groupID, function(err, group){
if (err)
return callbackErrorOnly(err);
group.join(function(err){
return callbackErrorOnly(err);
})
});
};
/**
* Leave a group
* @param groupID
* @param callbackErrorOnly
*/
Community.prototype.leaveGroup = function (groupID, callbackErrorOnly) {
var self = this;
self.community.getSteamGroup(groupID, function(err, group){
if (err)
return callbackErrorOnly(err);
group.leave(function(err){
return callbackErrorOnly(err);
})
});
};
/**
* Kick user from group
* @param groupID
* @param {SteamID} steamID
* @param callbackErrorOnly
*/
Community.prototype.kickFromGroup = function (groupID, steamID, callbackErrorOnly) {
var self = this;
self.community.getSteamGroup(groupID, function(err, group){
if (err)
return callbackErrorOnly(err);
group.kick(steamID, function(err){
return callbackErrorOnly(err);
})
});
};
/**
* Get Group info...
* @param groupID
* @param callbackGroup
*/
Community.prototype.getGroup = function (groupID, callbackGroup) {
var self = this;
self.community.getSteamGroup(groupID, function(err, group){
if (err)
return callbackGroup(err, null);
return callbackGroup(null, group);
});
};
/**
* Set-up a profile if the account is new and profile is not set-up yet.
* @param callbackErrorOnly
*/
Community.prototype.setupProfile = function (callbackErrorOnly) {
var self = this;
self.community.setupProfile(callbackErrorOnly);
};
/**
* Fetch API Key from Steam Community
* @param callbackErrorOnly
*/
Community.prototype.getWebApiKey = function (domain, callbackApiKey) {
var self = this;
self.community.getWebApiKey(domain, function(err, apiKey){
callbackApiKey(err, apiKey);
});
};
module.exports = Community;
</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Auth.html">Auth</a></li><li><a href="Bot.html">Bot</a></li><li><a href="global.html#BotManager">BotManager</a></li><li><a href="Community.html">Community</a></li><li><a href="Friends.html">Friends</a></li><li><a href="GUI_Handler.html">GUI_Handler</a></li><li><a href="Profile.html">Profile</a></li><li><a href="Request.html">Request</a></li><li><a href="Trade.html">Trade</a></li></ul><h3>Events</h3><ul><li><a href="Bot.html#event:chatMessage">chatMessage</a></li><li><a href="Bot.html#event:loggedIn">loggedIn</a></li><li><a href="Bot.html#event:newOffer">newOffer</a></li><li><a href="Bot.html#event:offerChanged">offerChanged</a></li><li><a href="Bot.html#event:offerList">offerList</a></li><li><a href="Bot.html#event:sentOfferChanged">sentOfferChanged</a></li><li><a href="Bot.html#event:tradeOffers">tradeOffers</a></li></ul><h3>Global</h3><ul><li><a href="global.html#webserver">webserver</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Sat Oct 28 2017 11:52:44 GMT-0400 (Eastern Daylight Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>