diff --git a/components/chat.js b/components/chat.js index d2eceef..f409eab 100644 --- a/components/chat.js +++ b/components/chat.js @@ -75,7 +75,7 @@ SteamCommunity.prototype.chatLogon = function(interval, uiMode) { this.chatState = SteamCommunity.ChatState.LoggedOn; this.emit('chatLoggedOn'); this._chatPoll(); - }, "steamcommunity"); + }, 'steamcommunity'); }); }; @@ -127,7 +127,7 @@ SteamCommunity.prototype.chatMessage = function(recipient, text, type, callback) } else { callback(null); } - }, "steamcommunity"); + }, 'steamcommunity'); }; /** @@ -151,7 +151,7 @@ SteamCommunity.prototype.chatLogoff = function() { delete this.chatFriends; this.chatState = SteamCommunity.ChatState.Offline; } - }, "steamcommunity"); + }, 'steamcommunity'); }; /** @@ -223,7 +223,7 @@ SteamCommunity.prototype._chatPoll = function() { this.emit('debug', 'Unhandled chat message type: ' + message.type); } }); - }, "steamcommunity"); + }, 'steamcommunity'); }; /** @@ -275,5 +275,5 @@ SteamCommunity.prototype._chatUpdatePersona = function(steamID) { this.emit('chatPersonaState', steamID, persona); this.chatFriends[steamID.getSteamID64()] = persona; - }, "steamcommunity"); + }, 'steamcommunity'); }; diff --git a/components/confirmations.js b/components/confirmations.js index 6007f4e..e3cd09a 100644 --- a/components/confirmations.js +++ b/components/confirmations.js @@ -269,5 +269,5 @@ function request(community, url, key, time, tag, params, json, callback) { } callback(null, body); - }, "steamcommunity"); + }, 'steamcommunity'); } diff --git a/components/groups.js b/components/groups.js index ac12794..156e732 100644 --- a/components/groups.js +++ b/components/groups.js @@ -11,14 +11,15 @@ SteamCommunity.prototype.getGroupMembers = function(gid, callback, members, link members = members || []; if (!link) { - if (typeof gid !== 'string') { + if (typeof gid != 'string') { // It's a SteamID object - link = "http://steamcommunity.com/gid/" + gid.toString() + "/memberslistxml/?xml=1"; + link = "https://steamcommunity.com/gid/" + gid.toString() + "/memberslistxml/?xml=1"; } else { try { - var sid = new SteamID(gid); + // new SteamID could throw which is why we have this funky-looking try/catch set up here + let sid = new SteamID(gid); if (sid.type == SteamID.Type.CLAN && sid.isValid()) { - link = "http://steamcommunity.com/gid/" + sid.getSteamID64() + "/memberslistxml/?xml=1"; + link = "https://steamcommunity.com/gid/" + sid.getSteamID64() + "/memberslistxml/?xml=1"; } else { throw new Error("Doesn't particularly matter what this message is"); } @@ -30,42 +31,39 @@ SteamCommunity.prototype.getGroupMembers = function(gid, callback, members, link addressIdx = addressIdx || 0; - var options = {}; + let options = {}; options.uri = link; - if(addresses) { - if(addressIdx >= addresses.length) { + if (addresses) { + if (addressIdx >= addresses.length) { addressIdx = 0; } options.localAddress = addresses[addressIdx]; } - var self = this; - this.httpRequest(options, function(err, response, body) { + this.httpRequest(options, (err, response, body) => { if (err) { callback(err); return; } - XML2JS.parseString(body, function(err, result) { + XML2JS.parseString(body, (err, result) => { if (err) { callback(err); return; } - members = members.concat(result.memberList.members[0].steamID64.map(function(steamID) { - return new SteamID(steamID); - })); + members = members.concat(result.memberList.members[0].steamID64.map(sid => new SteamID(sid))); if (result.memberList.nextPageLink) { addressIdx++; - self.getGroupMembers(gid, callback, members, result.memberList.nextPageLink[0], addresses, addressIdx); + this.getGroupMembers(gid, callback, members, result.memberList.nextPageLink[0], addresses, addressIdx); } else { callback(null, members); } }); - }, "steamcommunity"); + }, 'steamcommunity'); }; SteamCommunity.prototype.getGroupMembersEx = function(gid, addresses, callback) { @@ -73,38 +71,36 @@ SteamCommunity.prototype.getGroupMembersEx = function(gid, addresses, callback) }; SteamCommunity.prototype.joinGroup = function(gid, callback) { - if(typeof gid === 'string') { + if (typeof gid == 'string') { gid = new SteamID(gid); } - var self = this; this.httpRequestPost({ "uri": "https://steamcommunity.com/gid/" + gid.getSteamID64(), "form": { "action": "join", "sessionID": this.getSessionID() } - }, function(err, response, body) { - if(!callback) { + }, (err, response, body) => { + if (!callback) { return; } callback(err || null); - }, "steamcommunity"); + }, 'steamcommunity'); }; SteamCommunity.prototype.leaveGroup = function(gid, callback) { - if(typeof gid === 'string') { + if (typeof gid == 'string') { gid = new SteamID(gid); } - var self = this; this._myProfile("home_process", { "sessionID": this.getSessionID(), "action": "leaveGroup", "groupId": gid.getSteamID64() - }, function(err, response, body) { - if(!callback) { + }, (err, response, body) => { + if (!callback) { return; } @@ -113,57 +109,53 @@ SteamCommunity.prototype.leaveGroup = function(gid, callback) { }; SteamCommunity.prototype.getAllGroupAnnouncements = function(gid, time, callback) { - if(typeof gid === 'string') { + if (typeof gid == 'string') { gid = new SteamID(gid); } - if(typeof time === 'function') { + if (typeof time == 'function') { callback = time; time = new Date(0); // The beginnig of time... } - var self = this; this.httpRequest({ "uri": "https://steamcommunity.com/gid/" + gid.getSteamID64() + "/rss/" - }, function(err, response, body) { + }, (err, response, body) => { if (err) { callback(err); return; } - XML2JS.parseString(body, function(err, results) { - if(err) { + XML2JS.parseString(body, (err, results) => { + if (err) { return callback(err); } - if(!results.rss.channel[0].item) { + if (!results.rss.channel[0].item) { return callback(null, []); } - var announcements = results.rss.channel[0].item.map(function(announcement) { - var splitLink = announcement.link[0].split('/'); + let announcements = results.rss.channel[0].item.map((announcement) => { + let splitLink = announcement.link[0].split('/'); return { headline: announcement.title[0], - content: announcement.description[0], - date: new Date(announcement.pubDate[0]), - author: (typeof announcement.author === 'undefined') ? null : announcement.author[0], - aid: splitLink[splitLink.length - 1] + content: announcement.description[0], + date: new Date(announcement.pubDate[0]), + author: (typeof announcement.author === 'undefined') ? null : announcement.author[0], + aid: splitLink[splitLink.length - 1] } - }).filter(function(announcement) { - return (announcement.date > time); - }); + }).filter(announcement => announcement.date > time); return callback(null, announcements); }); - }, "steamcommunity"); + }, 'steamcommunity'); }; SteamCommunity.prototype.postGroupAnnouncement = function(gid, headline, content, callback) { - if(typeof gid === 'string') { + if (typeof gid == 'string') { gid = new SteamID(gid); } - var self = this; this.httpRequestPost({ "uri": "https://steamcommunity.com/gid/" + gid.getSteamID64() + "/announcements", "form": { @@ -174,23 +166,21 @@ SteamCommunity.prototype.postGroupAnnouncement = function(gid, headline, content "languages[0][headline]": headline, "languages[0][body]": content } - }, function(err, response, body) { - if(!callback) { + }, (err, response, body) => { + if (!callback) { return; } callback(err || null); - }, "steamcommunity"); + }, 'steamcommunity'); }; SteamCommunity.prototype.editGroupAnnouncement = function(gid, aid, headline, content, callback) { - if(typeof gid === 'string') { + if (typeof gid == 'string') { gid = new SteamID(gid); } - var self = this; - - var submitData = { + let submitData = { "uri": "https://steamcommunity.com/gid/" + gid.getSteamID64() + "/announcements", "form": { "sessionID": this.getSessionID(), @@ -204,117 +194,64 @@ SteamCommunity.prototype.editGroupAnnouncement = function(gid, aid, headline, co } }; - this.httpRequestPost(submitData, function(err, response, body) { - if(!callback) { + this.httpRequestPost(submitData, (err, response, body) => { + if (!callback) { return; } callback(err || null); - }, "steamcommunity"); + }, 'steamcommunity'); }; SteamCommunity.prototype.deleteGroupAnnouncement = function(gid, aid, callback) { - if(typeof gid === 'string') { + if (typeof gid == 'string') { gid = new SteamID(gid); } - var self = this; - - var submitData = { + let submitData = { "uri": "https://steamcommunity.com/gid/" + gid.getSteamID64() + "/announcements/delete/" + aid + "?sessionID=" + this.getSessionID() }; - this.httpRequestGet(submitData, function(err, response, body) { - if(!callback) { + this.httpRequestGet(submitData, (err, response, body) => { + if (!callback) { return; } callback(err || null); - }, "steamcommunity"); + }, 'steamcommunity'); }; SteamCommunity.prototype.scheduleGroupEvent = function(gid, name, type, description, time, server, callback) { - if(typeof gid === 'string') { + if (typeof gid == 'string') { gid = new SteamID(gid); } // Event types: ChatEvent - Chat, OtherEvent - A lil somethin somethin, PartyEvent - Party!, MeetingEvent - Important meeting, SpecialCauseEvent - Special cause (charity ball?), MusicAndArtsEvent - Music or Art type thing, SportsEvent - Sporting endeavor, TripEvent - Out of town excursion // Passing a number for type will make it a game event for that appid - if(typeof server === 'function') { - callback = server; - server = {"ip": "", "password": ""}; - } else if(typeof server === 'string') { - server = {"ip": server, "password": ""}; - } else if(typeof server !== 'object') { - server = {"ip": "", "password": ""}; + switch (typeof server) { + case 'function': + callback = server; + server = {ip: '', password: ''}; + break; + + case 'string': + server = {ip: server, password: ''}; + break; + + default: + if (typeof server != object) { + server = {ip: '', password: ''}; + } } - var form = { + let form = { "sessionid": this.getSessionID(), "action": "newEvent", "tzOffset": new Date().getTimezoneOffset() * -60, "name": name, - "type": (typeof type === 'number' || !isNaN(parseInt(type, 10)) ? "GameEvent" : type), - "appID": (typeof type === 'number' || !isNaN(parseInt(type, 10)) ? type : ''), - "serverIP": server.ip, - "serverPassword": server.password, - "notes": description, - "eventQuickTime": "now" - }; - - if(time === null) { - form.startDate = 'MM/DD/YY'; - form.startHour = '12'; - form.startMinute = '00'; - form.startAMPM = 'PM'; - form.timeChoice = 'quick'; - } else { - form.startDate = (time.getMonth() + 1 < 10 ? '0' : '') + (time.getMonth() + 1) + '/' + (time.getDate() < 10 ? '0' : '') + time.getDate() + '/' + time.getFullYear().toString().substring(2); - form.startHour = (time.getHours() === 0 ? '12' : (time.getHours() > 12 ? time.getHours() - 12 : time.getHours())); - form.startMinute = (time.getMinutes() < 10 ? '0' : '') + time.getMinutes(); - form.startAMPM = (time.getHours() <= 12 ? 'AM' : 'PM'); - form.timeChoice = 'specific'; - } - - var self = this; - this.httpRequestPost({ - "uri": "https://steamcommunity.com/gid/" + gid.toString() + "/eventEdit", - "form": form - }, function(err, response, body) { - if(!callback) { - return; - } - - callback(err || null); - }, "steamcommunity"); -}; - -SteamCommunity.prototype.editGroupEvent = function (gid, id, name, type, description, time, server, callback) { - if (typeof gid === 'string') { - gid = new SteamID(gid); - } - - // Event types: ChatEvent - Chat, OtherEvent - A lil somethin somethin, PartyEvent - Party!, MeetingEvent - Important meeting, SpecialCauseEvent - Special cause (charity ball?), MusicAndArtsEvent - Music or Art type thing, SportsEvent - Sporting endeavor, TripEvent - Out of town excursion - // Passing a number for type will make it a game event for that appid - - if (typeof server === 'function') { - callback = server; - server = {"ip": "", "password": ""}; - } else if (typeof server === 'string') { - server = {"ip": server, "password": ""}; - } else if (typeof server !== 'object') { - server = {"ip": "", "password": ""}; - } - - var form = { - "sessionid": this.getSessionID(), - "action": "updateEvent", - "eventID": id, - "tzOffset": new Date().getTimezoneOffset() * -60, - "name": name, - "type": (typeof type === 'number' || !isNaN(parseInt(type, 10)) ? "GameEvent" : type), - "appID": (typeof type === 'number' || !isNaN(parseInt(type, 10)) ? type : ''), + "type": (typeof type == 'number' || !isNaN(parseInt(type, 10)) ? "GameEvent" : type), + "appID": (typeof type == 'number' || !isNaN(parseInt(type, 10)) ? type : ''), "serverIP": server.ip, "serverPassword": server.password, "notes": description, @@ -335,53 +272,114 @@ SteamCommunity.prototype.editGroupEvent = function (gid, id, name, type, descrip form.timeChoice = 'specific'; } - var self = this; this.httpRequestPost({ "uri": "https://steamcommunity.com/gid/" + gid.toString() + "/eventEdit", - "form": form - }, function(err, response, body) { - if(!callback) { + form + }, (err, response, body) => { + if (!callback) { return; } callback(err || null); - }, "steamcommunity"); + }, 'steamcommunity'); }; -SteamCommunity.prototype.deleteGroupEvent = function(gid, id, callback) { +SteamCommunity.prototype.editGroupEvent = function(gid, id, name, type, description, time, server, callback) { if (typeof gid === 'string') { gid = new SteamID(gid); } - var form = { + // Event types: ChatEvent - Chat, OtherEvent - A lil somethin somethin, PartyEvent - Party!, MeetingEvent - Important meeting, SpecialCauseEvent - Special cause (charity ball?), MusicAndArtsEvent - Music or Art type thing, SportsEvent - Sporting endeavor, TripEvent - Out of town excursion + // Passing a number for type will make it a game event for that appid + + switch (typeof server) { + case 'function': + callback = server; + server = {ip: '', password: ''}; + break; + + case 'string': + server = {ip: server, password: ''}; + break; + + default: + if (typeof server != object) { + server = {ip: '', password: ''}; + } + } + + let form = { + "sessionid": this.getSessionID(), + "action": "updateEvent", + "eventID": id, + "tzOffset": new Date().getTimezoneOffset() * -60, + "name": name, + "type": (typeof type == 'number' || !isNaN(parseInt(type, 10)) ? "GameEvent" : type), + "appID": (typeof type == 'number' || !isNaN(parseInt(type, 10)) ? type : ''), + "serverIP": server.ip, + "serverPassword": server.password, + "notes": description, + "eventQuickTime": "now" + }; + + if (time === null) { + form.startDate = 'MM/DD/YY'; + form.startHour = '12'; + form.startMinute = '00'; + form.startAMPM = 'PM'; + form.timeChoice = 'quick'; + } else { + form.startDate = (time.getMonth() + 1 < 10 ? '0' : '') + (time.getMonth() + 1) + '/' + (time.getDate() < 10 ? '0' : '') + time.getDate() + '/' + time.getFullYear().toString().substring(2); + form.startHour = (time.getHours() === 0 ? '12' : (time.getHours() > 12 ? time.getHours() - 12 : time.getHours())); + form.startMinute = (time.getMinutes() < 10 ? '0' : '') + time.getMinutes(); + form.startAMPM = (time.getHours() <= 12 ? 'AM' : 'PM'); + form.timeChoice = 'specific'; + } + + this.httpRequestPost({ + "uri": "https://steamcommunity.com/gid/" + gid.toString() + "/eventEdit", + "form": form + }, (err, response, body) => { + if (!callback) { + return; + } + + callback(err || null); + }, 'steamcommunity'); +}; + +SteamCommunity.prototype.deleteGroupEvent = function(gid, id, callback) { + if (typeof gid == 'string') { + gid = new SteamID(gid); + } + + let form = { "sessionid": this.getSessionID(), "action": "deleteEvent", "eventID": id }; - var self = this; this.httpRequestPost({ "uri": "https://steamcommunity.com/gid/" + gid.toString() + "/eventEdit", - "form": form - }, function(err, response, body) { - if(!callback) { + form + }, (err, response, body) => { + if (!callback) { return; } callback(err || null); - }, "steamcommunity"); + }, 'steamcommunity'); }; SteamCommunity.prototype.setGroupPlayerOfTheWeek = function(gid, steamID, callback) { - if(typeof gid === 'string') { + if (typeof gid == 'string') { gid = new SteamID(gid); } - if(typeof steamID === 'string') { + if (typeof steamID == 'string') { steamID = new SteamID(steamID); } - var self = this; this.httpRequestPost({ "uri": "https://steamcommunity.com/gid/" + gid.getSteamID64() + "/potwEdit", "form": { @@ -390,41 +388,40 @@ SteamCommunity.prototype.setGroupPlayerOfTheWeek = function(gid, steamID, callba "memberId": steamID.getSteam3RenderedID(), "sessionid": this.getSessionID() } - }, function(err, response, body) { - if(!callback) { + }, (err, response, body) => { + if (!callback) { return; } - if(err || response.statusCode != 200) { + if (err || response.statusCode != 200) { callback(err || new Error("HTTP error " + response.statusCode)); return; } - XML2JS.parseString(body, function(err, results) { - if(err) { + XML2JS.parseString(body, (err, results) => { + if (err) { callback(err); return; } - if(results.response.results[0] == 'OK') { + if (results.response.results[0] == 'OK') { callback(null, new SteamID(results.response.oldPOTW[0]), new SteamID(results.response.newPOTW[0])); } else { callback(new Error(results.response.results[0])); } }); - }, "steamcommunity"); + }, 'steamcommunity'); }; SteamCommunity.prototype.kickGroupMember = function(gid, steamID, callback) { - if(typeof gid === 'string') { + if (typeof gid == 'string') { gid = new SteamID(gid); } - if(typeof steamID === 'string') { + if (typeof steamID == 'string') { steamID = new SteamID(steamID); } - var self = this; this.httpRequestPost({ "uri": "https://steamcommunity.com/gid/" + gid.getSteamID64() + "/membersManage", "form": { @@ -433,57 +430,56 @@ SteamCommunity.prototype.kickGroupMember = function(gid, steamID, callback) { "memberId": steamID.getSteamID64(), "queryString": "" } - }, function(err, response, body) { - if(!callback) { + }, (err, response, body) => { + if (!callback) { return; } callback(err || null); - }, "steamcommunity"); + }, 'steamcommunity'); }; SteamCommunity.prototype.getGroupHistory = function(gid, page, callback) { - if(typeof gid === 'string') { + if (typeof gid == 'string') { gid = new SteamID(gid); } - if(typeof page === 'function') { + if (typeof page == 'function') { callback = page; page = 1; } - var self = this; - this.httpRequest("https://steamcommunity.com/gid/" + gid.getSteamID64() + "/history?p=" + page, function(err, response, body) { + this.httpRequest("https://steamcommunity.com/gid/" + gid.getSteamID64() + "/history?p=" + page, (err, response, body) => { if (err) { callback(err); return; } - var $ = Cheerio.load(body); - var output = {}; + let $ = Cheerio.load(body); + let output = {}; - var paging = $('.group_paging p').text(); - var match = paging.match(/(\d+) - (\d+) of (\d+)/); + let paging = $('.group_paging p').text(); + let match = paging.match(/(\d+) - (\d+) of (\d+)/); - if(match) { + if (match) { output.first = parseInt(match[1], 10); output.last = parseInt(match[2], 10); output.total = parseInt(match[3], 10); } output.items = []; - var currentYear = (new Date()).getFullYear(); - var lastDate = Date.now(); + let currentYear = (new Date()).getFullYear(); + let lastDate = Date.now(); - Array.prototype.forEach.call($('.historyItem, .historyItemb'), function(item) { - var data = {}; + Array.prototype.forEach.call($('.historyItem, .historyItemb'), (item) => { + let data = {}; - var $item = $(item); + let $item = $(item); data.type = $item.find('.historyShort').text().replace(/ /g, ''); - var users = $item.find('.whiteLink[data-miniprofile]'); - var sid; - if(users[0]) { + let users = $item.find('.whiteLink[data-miniprofile]'); + let sid; + if (users[0]) { sid = new SteamID(); sid.universe = SteamID.Universe.PUBLIC; sid.type = SteamID.Type.INDIVIDUAL; @@ -492,7 +488,7 @@ SteamCommunity.prototype.getGroupHistory = function(gid, page, callback) { data.user = sid; } - if(users[1]) { + if (users[1]) { sid = new SteamID(); sid.universe = SteamID.Universe.PUBLIC; sid.type = SteamID.Type.INDIVIDUAL; @@ -502,14 +498,14 @@ SteamCommunity.prototype.getGroupHistory = function(gid, page, callback) { } // Figure out the date. Of course there's no year, because Valve - var dateParts = $item.find('.historyDate').text().split('@'); - var date = dateParts[0].trim().replace(/(st|nd|th)$/, '').trim() + ', ' + currentYear; - var time = dateParts[1].trim().replace(/(am|pm)/, ' $1'); + let dateParts = $item.find('.historyDate').text().split('@'); + let date = dateParts[0].trim().replace(/(st|nd|th)$/, '').trim() + ', ' + currentYear; + let time = dateParts[1].trim().replace(/(am|pm)/, ' $1'); date = new Date(date + ' ' + time + ' UTC'); // If this date is in the future, or it's later than the previous one, decrement the year - if(date.getTime() > lastDate) { + if (date.getTime() > lastDate) { date.setFullYear(date.getFullYear() - 1); } @@ -519,15 +515,15 @@ SteamCommunity.prototype.getGroupHistory = function(gid, page, callback) { }); callback(null, output); - }, "steamcommunity"); + }, 'steamcommunity'); }; SteamCommunity.prototype.getAllGroupComments = function(gid, from, count, callback) { - if (typeof gid === 'string') { + if (typeof gid == 'string') { gid = new SteamID(gid); } - var options = { + let options = { "uri": "https://steamcommunity.com/comment/Clan/render/" + gid.getSteamID64() + "/-1/", "form": { "start": from, @@ -535,22 +531,20 @@ SteamCommunity.prototype.getAllGroupComments = function(gid, from, count, callba } }; - var self = this; - this.httpRequestPost(options, function(err, response, body) { + this.httpRequestPost(options, (err, response, body) => { if (err) { callback(err); return; } - var comments = []; + let comments = []; - var $ = Cheerio.load(JSON.parse(body).comments_html); + let $ = Cheerio.load(JSON.parse(body).comments_html); - $(".commentthread_comment_content").each(function () { - var comment = {}; - var cachedSelector; + $('.commentthread_comment_content').each(function() { + let comment = {}; - var $selector = $(this).find(".commentthread_author_link"); + let $selector = $(this).find(".commentthread_author_link"); comment.authorName = $($selector).find("bdi").text(); comment.authorId = $($selector).attr("href").replace(/https?:\/\/steamcommunity.com\/(id|profiles)\//, ""); comment.date = Helpers.decodeSteamTime($(this).find(".commentthread_comment_timestamp").text().trim()); @@ -563,19 +557,19 @@ SteamCommunity.prototype.getAllGroupComments = function(gid, from, count, callba }); callback(null, comments); - }, "steamcommunity"); + }, 'steamcommunity'); }; SteamCommunity.prototype.deleteGroupComment = function(gid, cid, callback) { - if (typeof gid === 'string') { + if (typeof gid == 'string') { gid = new SteamID(gid); } - if (typeof cid !== 'string') { + if (typeof cid != 'string') { cid = cid.toString(); } - var options = { + let options = { "uri": "https://steamcommunity.com/comment/Clan/delete/" + gid.getSteamID64() + "/-1/", "form": { "sessionid": this.getSessionID(), @@ -583,22 +577,21 @@ SteamCommunity.prototype.deleteGroupComment = function(gid, cid, callback) { } }; - var self = this; - this.httpRequestPost(options, function(err, response, body) { - if(!callback) { + this.httpRequestPost(options, (err, response, body) => { + if (!callback) { return; } callback(err || null); - }, "steamcommunity"); + }, 'steamcommunity'); }; SteamCommunity.prototype.postGroupComment = function(gid, message, callback) { - if (typeof gid === 'string') { + if (typeof gid == 'string') { gid = new SteamID(gid); } - var options = { + let options = { "uri": "https://steamcommunity.com/comment/Clan/post/" + gid.getSteamID64() + "/-1/", "form": { "comment": message, @@ -607,14 +600,13 @@ SteamCommunity.prototype.postGroupComment = function(gid, message, callback) { } }; - var self = this; - this.httpRequestPost(options, function(err, response, body) { - if(!callback) { + this.httpRequestPost(options, (err, response, body) => { + if (!callback) { return; } callback(err || null); - }, "steamcommunity"); + }, 'steamcommunity'); }; /** @@ -623,7 +615,7 @@ SteamCommunity.prototype.postGroupComment = function(gid, message, callback) { * @param {function} callback - First argument is null/Error, second is array of SteamID objects */ SteamCommunity.prototype.getGroupJoinRequests = function(gid, callback) { - if (typeof gid === 'string') { + if (typeof gid == 'string') { gid = new SteamID(gid); } @@ -633,20 +625,20 @@ SteamCommunity.prototype.getGroupJoinRequests = function(gid, callback) { return; } - var matches = body.match(/JoinRequests_ApproveDenyUser\(\W*['"](\d+)['"],\W0\W\)/g); + let matches = body.match(/JoinRequests_ApproveDenyUser\(\W*['"](\d+)['"],\W0\W\)/g); if (!matches) { // no pending requests callback(null, []); return; } - var requests = []; - for (var i = 0; i < matches.length; i++) { + let requests = []; + for (let i = 0; i < matches.length; i++) { requests.push(new SteamID("[U:1:" + matches[i].match(/JoinRequests_ApproveDenyUser\(\W*['"](\d+)['"],\W0\W\)/)[1] + "]")); } callback(null, requests); - }, "steamcommunity"); + }, 'steamcommunity'); }; /** @@ -657,11 +649,11 @@ SteamCommunity.prototype.getGroupJoinRequests = function(gid, callback) { * @param {function} callback - Takes only an Error object/null as the first argument */ SteamCommunity.prototype.respondToGroupJoinRequests = function(gid, steamIDs, approve, callback) { - if (typeof gid === 'string') { + if (typeof gid == 'string') { gid = new SteamID(gid); } - var rgAccounts = (!Array.isArray(steamIDs) ? [steamIDs] : steamIDs).map(sid => sid.toString()); + let rgAccounts = (!Array.isArray(steamIDs) ? [steamIDs] : steamIDs).map(sid => sid.toString()); this.httpRequestPost({ "uri": "https://steamcommunity.com/gid/" + gid.getSteamID64() + "/joinRequestsManage", @@ -678,13 +670,13 @@ SteamCommunity.prototype.respondToGroupJoinRequests = function(gid, steamIDs, ap } if (body != EResult.OK) { - var err = new Error(EResult[body] || ("Error " + body)); + let err = new Error(EResult[body] || ("Error " + body)); err.eresult = body; callback(err); } else { callback(null); } - }, "steamcommunity"); + }, 'steamcommunity'); }; /** @@ -694,7 +686,7 @@ SteamCommunity.prototype.respondToGroupJoinRequests = function(gid, steamIDs, ap * @param {function} callback - Takes only an Error object/null as the first argument */ SteamCommunity.prototype.respondToAllGroupJoinRequests = function(gid, approve, callback) { - if (typeof gid === 'string') { + if (typeof gid == 'string') { gid = new SteamID(gid); } @@ -713,11 +705,11 @@ SteamCommunity.prototype.respondToAllGroupJoinRequests = function(gid, approve, } if (body != EResult.OK) { - var err = new Error(EResult[body] || ("Error " + body)); + let err = new Error(EResult[body] || ("Error " + body)); err.eresult = body; callback(err); } else { callback(null); } - }, "steamcommunity"); + }, 'steamcommunity'); };