From 0cb0d22433dde230f3f2beaef3e4143384a39ded Mon Sep 17 00:00:00 2001 From: Alex Corn Date: Thu, 14 Feb 2019 00:29:21 -0500 Subject: [PATCH] Cleaned up imports --- classes/CConfirmation.js | 2 +- classes/CMarketItem.js | 5 ++-- classes/CMarketSearchResult.js | 5 ++-- classes/CSteamGroup.js | 11 +++---- classes/CSteamUser.js | 11 +++---- components/chat.js | 55 +++++++++++++++++----------------- components/confirmations.js | 9 +++--- components/groups.js | 22 +++++++------- components/http.js | 2 +- components/market.js | 5 ++-- components/twofactor.js | 7 +++-- components/webapi.js | 4 +-- index.js | 6 ++-- 13 files changed, 78 insertions(+), 66 deletions(-) diff --git a/classes/CConfirmation.js b/classes/CConfirmation.js index 0a450c4..8585474 100644 --- a/classes/CConfirmation.js +++ b/classes/CConfirmation.js @@ -1,4 +1,4 @@ -var SteamCommunity = require('../index.js'); +const SteamCommunity = require('../index.js'); module.exports = CConfirmation; diff --git a/classes/CMarketItem.js b/classes/CMarketItem.js index a23c1b7..b031d34 100644 --- a/classes/CMarketItem.js +++ b/classes/CMarketItem.js @@ -1,5 +1,6 @@ -var SteamCommunity = require('../index.js'); -var Cheerio = require('cheerio'); +const Cheerio = require('cheerio'); + +const SteamCommunity = require('../index.js'); SteamCommunity.prototype.getMarketItem = function(appid, hashName, currency, callback) { if (typeof currency == "function") { diff --git a/classes/CMarketSearchResult.js b/classes/CMarketSearchResult.js index e345b7d..8d1c888 100644 --- a/classes/CMarketSearchResult.js +++ b/classes/CMarketSearchResult.js @@ -1,5 +1,6 @@ -var SteamCommunity = require('../index.js'); -var Cheerio = require('cheerio'); +const Cheerio = require('cheerio'); + +const SteamCommunity = require('../index.js'); SteamCommunity.prototype.marketSearch = function(options, callback) { var qs = {}; diff --git a/classes/CSteamGroup.js b/classes/CSteamGroup.js index c18889f..c200929 100644 --- a/classes/CSteamGroup.js +++ b/classes/CSteamGroup.js @@ -1,7 +1,8 @@ -var SteamCommunity = require('../index.js'); -var Helpers = require('../components/helpers.js'); -var SteamID = require('steamid'); -var xml2js = require('xml2js'); +const SteamID = require('steamid'); +const XML2JS = require('xml2js'); + +const Helpers = require('../components/helpers.js'); +const SteamCommunity = require('../index.js'); SteamCommunity.prototype.getSteamGroup = function(id, callback) { if(typeof id !== 'string' && !Helpers.isSteamID(id)) { @@ -19,7 +20,7 @@ SteamCommunity.prototype.getSteamGroup = function(id, callback) { return; } - xml2js.parseString(body, function(err, result) { + XML2JS.parseString(body, function(err, result) { if(err) { callback(err); return; diff --git a/classes/CSteamUser.js b/classes/CSteamUser.js index 9ca4564..b38ecea 100644 --- a/classes/CSteamUser.js +++ b/classes/CSteamUser.js @@ -1,7 +1,8 @@ -var SteamCommunity = require('../index.js'); -var Helpers = require('../components/helpers.js'); -var SteamID = require('steamid'); -var xml2js = require('xml2js'); +const SteamID = require('steamid'); +const XML2JS = require('xml2js'); + +const Helpers = require('../components/helpers.js'); +const SteamCommunity = require('../index.js'); SteamCommunity.prototype.getSteamUser = function(id, callback) { if(typeof id !== 'string' && !Helpers.isSteamID(id)) { @@ -19,7 +20,7 @@ SteamCommunity.prototype.getSteamUser = function(id, callback) { return; } - xml2js.parseString(body, function(err, result) { + XML2JS.parseString(body, function(err, result) { if(err || (!result.response && !result.profile)) { callback(err || new Error("No valid response")); return; diff --git a/components/chat.js b/components/chat.js index 21e743a..09750e8 100644 --- a/components/chat.js +++ b/components/chat.js @@ -1,5 +1,6 @@ -var SteamCommunity = require('../index.js'); -var SteamID = require('steamid'); +const SteamID = require('steamid'); + +const SteamCommunity = require('../index.js'); SteamCommunity.ChatState = require('../resources/EChatState.js'); SteamCommunity.PersonaState = require('../resources/EPersonaState.js'); @@ -9,13 +10,13 @@ SteamCommunity.prototype.chatLogon = function(interval, uiMode) { if(this.chatState == SteamCommunity.ChatState.LoggingOn || this.chatState == SteamCommunity.ChatState.LoggedOn) { return; } - + interval = interval || 500; uiMode = uiMode || "web"; - + this.emit('debug', 'Requesting chat WebAPI token'); this.chatState = SteamCommunity.ChatState.LoggingOn; - + var self = this; this.getWebApiOauthToken(function(err, token) { if(err) { @@ -32,7 +33,7 @@ SteamCommunity.prototype.chatLogon = function(interval, uiMode) { self.emit('debug', "Cannot get oauth token: " + err.message); return; } - + self.httpRequestPost({ "uri": "https://api.steampowered.com/ISteamWebUserPresenceOAuth/Logon/v1", "form": { @@ -48,7 +49,7 @@ SteamCommunity.prototype.chatLogon = function(interval, uiMode) { setTimeout(self.chatLogon.bind(self), 5000); return; } - + if(body.error != 'OK') { self.chatState = SteamCommunity.ChatState.LogOnFailed; self.emit('chatLogOnFailed', new Error(body.error), false); @@ -56,7 +57,7 @@ SteamCommunity.prototype.chatLogon = function(interval, uiMode) { setTimeout(self.chatLogon.bind(self), 5000); return; } - + self._chat = { "umqid": body.umqid, "message": body.message, @@ -64,9 +65,9 @@ SteamCommunity.prototype.chatLogon = function(interval, uiMode) { "interval": interval, "uiMode": uiMode }; - + self.chatFriends = {}; - + self.chatState = SteamCommunity.ChatState.LoggedOn; self.emit('chatLoggedOn'); self._chatPoll(); @@ -78,16 +79,16 @@ SteamCommunity.prototype.chatMessage = function(recipient, text, type, callback) if(this.chatState != SteamCommunity.ChatState.LoggedOn) { throw new Error("Chat must be logged on before messages can be sent"); } - + if(typeof recipient === 'string') { recipient = new SteamID(recipient); } - + if(typeof type === 'function') { callback = type; type = 'saytext'; } - + type = type || 'saytext'; var self = this; @@ -105,12 +106,12 @@ SteamCommunity.prototype.chatMessage = function(recipient, text, type, callback) if(!callback) { return; } - + if (err) { callback(err); return; } - + if(body.error != 'OK') { callback(new Error(body.error)); } else { @@ -143,7 +144,7 @@ SteamCommunity.prototype.chatLogoff = function() { SteamCommunity.prototype._chatPoll = function() { this.emit('debug', 'Doing chat poll'); - + var self = this; this.httpRequestPost({ "uri": "https://api.steampowered.com/ISteamWebUserPresenceOAuth/Poll/v1", @@ -161,9 +162,9 @@ SteamCommunity.prototype._chatPoll = function() { if (self.chatState == SteamCommunity.ChatState.Offline) { return; } - + self._chat.timer = setTimeout(self._chatPoll.bind(self), self._chat.interval); - + if(err || response.statusCode != 200) { self.emit('debug', 'Error in chat poll: ' + (err ? err.message : "HTTP error " + response.statusCode)); if (err.message == "Not Logged On") { @@ -172,7 +173,7 @@ SteamCommunity.prototype._chatPoll = function() { return; } - + if(!body || body.error != 'OK') { self.emit('debug', 'Error in chat poll: ' + (body && body.error ? body.error : "Malformed response")); if (body && body.error && body.error == "Not Logged On") { @@ -181,29 +182,29 @@ SteamCommunity.prototype._chatPoll = function() { return; } - + self._chat.message = body.messagelast; - + (body.messages || []).forEach(function(message) { var sender = new SteamID(); sender.universe = SteamID.Universe.PUBLIC; sender.type = SteamID.Type.INDIVIDUAL; sender.instance = SteamID.Instance.DESKTOP; sender.accountid = message.accountid_from; - + switch(message.type) { case 'personastate': self._chatUpdatePersona(sender); break; - + case 'saytext': self.emit('chatMessage', sender, message.text); break; - + case 'typing': self.emit('chatTyping', sender); break; - + default: self.emit('debug', 'Unhandled chat message type: ' + message.type); } @@ -240,7 +241,7 @@ SteamCommunity.prototype._chatUpdatePersona = function(steamID) { }, 2000); return; } - + var persona = { "steamID": steamID, "personaName": body.m_strName, @@ -255,4 +256,4 @@ SteamCommunity.prototype._chatUpdatePersona = function(steamID) { self.emit('chatPersonaState', steamID, persona); self.chatFriends[steamID.getSteamID64()] = persona; }, "steamcommunity"); -}; \ No newline at end of file +}; diff --git a/components/confirmations.js b/components/confirmations.js index 04681e1..3fa88c6 100644 --- a/components/confirmations.js +++ b/components/confirmations.js @@ -1,8 +1,9 @@ -var SteamCommunity = require('../index.js'); -var Cheerio = require('cheerio'); -var SteamTotp = require('steam-totp'); +const Cheerio = require('cheerio'); +const SteamTotp = require('steam-totp'); -var CConfirmation = require('../classes/CConfirmation.js'); +const SteamCommunity = require('../index.js'); + +const CConfirmation = require('../classes/CConfirmation.js'); /** * Get a list of your account's currently outstanding confirmations. diff --git a/components/groups.js b/components/groups.js index 5bd42b4..d9a3ef7 100644 --- a/components/groups.js +++ b/components/groups.js @@ -1,9 +1,11 @@ -var SteamCommunity = require('../index.js'); -var SteamID = require('steamid'); -var xml2js = require('xml2js'); -var Cheerio = require('cheerio'); -var Helpers = require('./helpers.js'); -var EResult = SteamCommunity.EResult; +const Cheerio = require('cheerio'); +const SteamID = require('steamid'); +const XML2JS = require('xml2js'); + +const Helpers = require('./helpers.js'); +const SteamCommunity = require('../index.js'); + +const EResult = SteamCommunity.EResult; SteamCommunity.prototype.getGroupMembers = function(gid, callback, members, link, addresses, addressIdx) { members = members || []; @@ -46,7 +48,7 @@ SteamCommunity.prototype.getGroupMembers = function(gid, callback, members, link return; } - xml2js.parseString(body, function(err, result) { + XML2JS.parseString(body, function(err, result) { if (err) { callback(err); return; @@ -129,7 +131,7 @@ SteamCommunity.prototype.getAllGroupAnnouncements = function(gid, time, callback return; } - xml2js.parseString(body, function(err, results) { + XML2JS.parseString(body, function(err, results) { if(err) { return callback(err); } @@ -398,7 +400,7 @@ SteamCommunity.prototype.setGroupPlayerOfTheWeek = function(gid, steamID, callba return; } - xml2js.parseString(body, function(err, results) { + XML2JS.parseString(body, function(err, results) { if(err) { callback(err); return; @@ -634,7 +636,7 @@ SteamCommunity.prototype.respondToGroupJoinRequests = function(gid, steamIDs, ap if (typeof gid === 'string') { gid = new SteamID(gid); } - + var rgAccounts = (!Array.isArray(steamIDs) ? [steamIDs] : steamIDs).map(sid => sid.toString()); this.httpRequestPost({ diff --git a/components/http.js b/components/http.js index ebb1846..f8d92f7 100644 --- a/components/http.js +++ b/components/http.js @@ -1,4 +1,4 @@ -var SteamCommunity = require('../index.js'); +const SteamCommunity = require('../index.js'); SteamCommunity.prototype.httpRequest = function(uri, options, callback, source) { if (typeof uri === 'object') { diff --git a/components/market.js b/components/market.js index ac35725..cb6923e 100644 --- a/components/market.js +++ b/components/market.js @@ -1,5 +1,6 @@ -var SteamCommunity = require('../index.js'); -var Cheerio = require('cheerio'); +const Cheerio = require('cheerio'); + +const SteamCommunity = require('../index.js'); /** * Get a list of all apps on the market diff --git a/components/twofactor.js b/components/twofactor.js index 651c691..c02828d 100644 --- a/components/twofactor.js +++ b/components/twofactor.js @@ -1,7 +1,8 @@ -var SteamTotp = require('steam-totp'); -var SteamCommunity = require('../index.js'); +const SteamTotp = require('steam-totp'); -var ETwoFactorTokenType = { +const SteamCommunity = require('../index.js'); + +const 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. diff --git a/components/webapi.js b/components/webapi.js index dc507fa..ee246c2 100644 --- a/components/webapi.js +++ b/components/webapi.js @@ -1,4 +1,4 @@ -var SteamCommunity = require('../index.js'); +const SteamCommunity = require('../index.js'); SteamCommunity.prototype.getWebApiKey = function(domain, callback) { var self = this; @@ -14,7 +14,7 @@ SteamCommunity.prototype.getWebApiKey = function(domain, callback) { if(body.match(/

Access Denied<\/h2>/)) { return callback(new Error("Access Denied")); } - + if(body.match(/You must have a validated email address to create a Steam Web API key./)) { return callback(new Error("You must have a validated email address to create a Steam Web API key.")); } diff --git a/index.js b/index.js index 112a7ae..c2a15b5 100644 --- a/index.js +++ b/index.js @@ -1,19 +1,21 @@ require('@doctormckay/stats-reporter').setup(require('./package.json')); +const EventEmitter = require('events').EventEmitter; const hex2b64 = require('node-bignumber').hex2b64; const Request = require('request'); const RSA = require('node-bignumber').Key; const SteamID = require('steamid'); +const Util = require('util'); const USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"; -require('util').inherits(SteamCommunity, require('events').EventEmitter); +Util.inherits(SteamCommunity, EventEmitter); module.exports = SteamCommunity; SteamCommunity.SteamID = SteamID; SteamCommunity.ConfirmationType = require('./resources/EConfirmationType.js'); -SteamCommunity.EResult = require('./resources/EResult.js') +SteamCommunity.EResult = require('./resources/EResult.js'); function SteamCommunity(options) {