Skip to content

Commit

Permalink
Add proxy checking functions
Browse files Browse the repository at this point in the history
  • Loading branch information
3urobeat committed Oct 10, 2023
1 parent 25f3c78 commit eed7c9b
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/data/fileStructure.json
Original file line number Diff line number Diff line change
Expand Up @@ -578,13 +578,18 @@
{
"path": "src/dataManager/dataManager.js",
"url": "https://raw.githubusercontent.com/3urobeat/steam-comment-service-bot/beta-testing/src/dataManager/dataManager.js",
"checksum": "5e226fff75fc009bda5121c9ccbe8a5d"
"checksum": "9a9c827bc01c11624c0d7f60a1227c53"
},
{
"path": "src/dataManager/dataProcessing.js",
"url": "https://raw.githubusercontent.com/3urobeat/steam-comment-service-bot/beta-testing/src/dataManager/dataProcessing.js",
"checksum": "e3927776806e2df7cda77eace731232d"
},
{
"path": "src/dataManager/helpers/checkProxies.js",
"url": "https://raw.githubusercontent.com/3urobeat/steam-comment-service-bot/beta-testing/src/dataManager/helpers/checkProxies.js",
"checksum": "031337c90a9a313691b5a4e744f1cd31"
},
{
"path": "src/dataManager/helpers/getLang.js",
"url": "https://raw.githubusercontent.com/3urobeat/steam-comment-service-bot/beta-testing/src/dataManager/helpers/getLang.js",
Expand Down Expand Up @@ -798,7 +803,7 @@
{
"path": "types/types.d.ts",
"url": "https://raw.githubusercontent.com/3urobeat/steam-comment-service-bot/beta-testing/types/types.d.ts",
"checksum": "1b0de8d2e346f31a3c94aeaa1d09f683"
"checksum": "7fb30947e8c2489efdf582f30dcebc09"
}
]
}
17 changes: 15 additions & 2 deletions src/dataManager/dataManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Created Date: 21.03.2023 22:34:51
* Author: 3urobeat
*
* Last Modified: 10.10.2023 16:57:59
* Last Modified: 10.10.2023 22:16:36
* Modified By: 3urobeat
*
* Copyright (c) 2023 3urobeat <https://github.com/3urobeat>
Expand Down Expand Up @@ -127,7 +127,7 @@ DataManager.prototype._loadDataManagerFiles = function() {
// The files need to be explicitly defined for restoring using checkAndGetFile to work
const helperPaths = [
"dataCheck.js", "dataExport.js", "dataImport.js", "dataIntegrity.js", "dataProcessing.js",
"helpers/getLang.js", "helpers/getQuote.js", "helpers/handleCooldowns.js", "helpers/handleExpiringTokens.js", "helpers/misc.js", "helpers/refreshCache.js", "helpers/repairFile.js"
"helpers/checkProxies.js", "helpers/getLang.js", "helpers/getQuote.js", "helpers/handleCooldowns.js", "helpers/handleExpiringTokens.js", "helpers/misc.js", "helpers/refreshCache.js", "helpers/repairFile.js"
];

helperPaths.forEach(async (e, i) => {
Expand Down Expand Up @@ -206,6 +206,19 @@ DataManager.prototype.verifyIntegrity = function() {};
*/
DataManager.prototype.processData = async function() {};

/**
* Checks if a proxy can reach steamcommunity.com and updates its isOnline and lastOnlineCheck
* @param {number} proxyIndex Index of the proxy to check in the DataManager proxies array
* @returns {boolean} True if the proxy can reach steamcommunity.com, false otherwise.
*/
DataManager.prototype.checkProxy = async function(proxyIndex) {}; // eslint-disable-line

/**
* Checks all proxies if they can reach steamcommunity.com and updates their entries
* @returns {Promise.<void>} Resolves when all proxies have been checked
*/
DataManager.prototype.checkAllProxies = async function() {};

/**
* Retrieves a language string from one of the available language files and replaces keywords if desired.
* If a userID is provided it will lookup which language the user has set. If nothing is set, the default language set in the config will be returned.
Expand Down
61 changes: 61 additions & 0 deletions src/dataManager/helpers/checkProxies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* File: checkProxies.js
* Project: steam-comment-service-bot
* Created Date: 09.10.2023 21:08:13
* Author: 3urobeat
*
* Last Modified: 10.10.2023 22:12:47
* Modified By: 3urobeat
*
* Copyright (c) 2023 3urobeat <https://github.com/3urobeat>
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*/


const DataManager = require("../dataManager");


/**
* Checks if a proxy can reach steamcommunity.com and updates its isOnline and lastOnlineCheck
* @param {number} proxyIndex Index of the proxy to check in the DataManager proxies array
* @returns {boolean} True if the proxy can reach steamcommunity.com, false otherwise.
*/
DataManager.prototype.checkProxy = async function(proxyIndex) {
let { checkConnection, splitProxyString } = this.controller.misc;

let thisProxy = this.proxies[proxyIndex];

// Check connection using checkConnection helper
await checkConnection("https://steamcommunity.com", true, thisProxy.proxy != null ? splitProxyString(thisProxy.proxy) : null) // Quick ternary to only split non-hosts
.then((res) => {
thisProxy.isOnline = res.statusCode >= 200 && res.statusCode < 300; // Check if response code is in 200 (OK) range
})
.catch(() => {
thisProxy.isOnline = false;
});

thisProxy.lastOnlineCheck = Date.now();

// Return result of check above
return thisProxy.isOnline;
};


/**
* Checks all proxies if they can reach steamcommunity.com and updates their entries
* @returns {Promise.<void>} Resolves when all proxies have been checked
*/
DataManager.prototype.checkAllProxies = async function() {
let promiseArr = [];

// Iterate over all proxies and call this.checkProxies(). We don't need any delay here as all requests go over different IPs
this.proxies.forEach((e) => {
promiseArr.push(this.checkProxy(e.proxyIndex));
});

// Await all promises so this function resolves when all proxies have been checked
await Promise.all(promiseArr);
};
29 changes: 28 additions & 1 deletion types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ declare class Bot {
* Handles checking for missing game licenses, requests them and then starts playing
*/
handleMissingGameLicenses(): void;
/**
* Changes the proxy of this bot account and relogs it.
* @param newProxyIndex - Index of the new proxy inside the DataManager.proxies array.
*/
switchProxy(newProxyIndex: number): void;
/**
* Attempts to get this account, after failing all logOnRetries, back online after some time. Does not apply to initial logins.
*/
Expand Down Expand Up @@ -825,7 +830,7 @@ declare class DataManager {
/**
* Stores all proxies provided via the `proxies.txt` file.
*/
proxies: string[];
proxies: { proxy: string; proxyIndex: number; isOnline: boolean; lastOnlineCheck: number; }[];
/**
* Stores IDs from config files converted at runtime and backups for all config & data files.
*/
Expand Down Expand Up @@ -912,6 +917,17 @@ declare class DataManager {
* Converts owners and groups imported from config.json to steam ids and updates cachefile. (Call this after dataImport and before dataCheck)
*/
processData(): void;
/**
* Checks if a proxy can reach steamcommunity.com and updates its isOnline and lastOnlineCheck
* @param proxyIndex - Index of the proxy to check in the DataManager proxies array
* @returns True if the proxy can reach steamcommunity.com, false otherwise.
*/
checkProxy(proxyIndex: number): boolean;
/**
* Checks all proxies if they can reach steamcommunity.com and updates their entries
* @returns Resolves when all proxies have been checked
*/
checkAllProxies(): Promise<void>;
/**
* Retrieves a language string from one of the available language files and replaces keywords if desired.
* If a userID is provided it will lookup which language the user has set. If nothing is set, the default language set in the config will be returned.
Expand Down Expand Up @@ -984,6 +1000,17 @@ declare class DataManager {
* Converts owners and groups imported from config.json to steam ids and updates cachefile. (Call this after dataImport and before dataCheck)
*/
processData(): void;
/**
* Checks if a proxy can reach steamcommunity.com and updates its isOnline and lastOnlineCheck
* @param proxyIndex - Index of the proxy to check in the DataManager proxies array
* @returns True if the proxy can reach steamcommunity.com, false otherwise.
*/
checkProxy(proxyIndex: number): boolean;
/**
* Checks all proxies if they can reach steamcommunity.com and updates their entries
* @returns Resolves when all proxies have been checked
*/
checkAllProxies(): Promise<void>;
/**
* Retrieves a language string from one of the available language files and replaces keywords if desired.
* If a userID is provided it will lookup which language the user has set. If nothing is set, the default language set in the config will be returned.
Expand Down

0 comments on commit eed7c9b

Please sign in to comment.