diff --git a/src/app.ts b/src/app.ts index 3285d61fe..017e4d29b 100644 --- a/src/app.ts +++ b/src/app.ts @@ -69,9 +69,7 @@ SchemaManager.prototype.getSchema = function (callback): void { this.setSchema(schema, true); callback(null, this.schema); }) - .catch(err => { - callback(err); - }); + .catch(err => callback(err)); }; /*eslint-enable */ diff --git a/src/classes/Autokeys/Autokeys.ts b/src/classes/Autokeys/Autokeys.ts index 60f7b2595..16b843425 100644 --- a/src/classes/Autokeys/Autokeys.ts +++ b/src/classes/Autokeys/Autokeys.ts @@ -124,9 +124,7 @@ export default class Autokeys { check(): void { log.debug(`checking autokeys (Enabled: ${String(this.isEnabled)})`); - if (this.isEnabled === false) { - return; - } + if (this.isEnabled === false) return; const userPure = this.userPure; @@ -319,7 +317,6 @@ export default class Autokeys { if (setMaxKeys === currKeys) { setMaxKeys += 1; } - if (currKeys >= setMaxKeys) { setMaxKeys = currKeys + 1; } @@ -354,152 +351,107 @@ export default class Autokeys { rKeysCanSell !== this.oldAmount.keysCanSell || currKeys !== this.oldAmount.ofKeys); - if (this.isActive) { - // if Autokeys already running + const alertLowPure = () => { + const msg = 'I am now low on both keys and refs.'; + if (opt.sendAlert.enable && opt.sendAlert.autokeys.lowPure) { + if (opt.discordWebhook.sendAlert.enable && opt.discordWebhook.sendAlert.url.main !== '') + sendAlert('lowPure', this.bot, msg); + else this.bot.messageAdmins(msg, []); + } + }; + + const common1 = () => { + this.setOverallStatus = [false, true, false, true, false, false]; + this.setOldAmount = [0, 0, rKeysCanBankMin, rKeysCanBankMax, currKeys]; + this.setActiveStatus = true; + }; + + const common2 = () => { + this.setOverallStatus = [true, false, false, false, true, false]; + this.setOldAmount = [0, rKeysCanBankMax, 0, 0, currKeys]; + this.setActiveStatus = true; + }; + + const common3 = () => { + this.setOverallStatus = [true, false, false, false, true, false]; + this.setOldAmount = [0, rKeysCanBuy, 0, 0, currKeys]; + this.setActiveStatus = true; + }; + + const common4 = () => { + this.setOverallStatus = [false, false, false, false, false, true]; + this.setOldAmount = [rKeysCanSell, 0, 0, 0, currKeys]; + this.setActiveStatus = true; + }; + + const common5 = () => { + this.setOverallStatus = [false, false, true, false, false, false]; + this.setActiveStatus = false; + alertLowPure(); + }; + + const isNotInPricelist = this.bot.pricelist.getPrice({ priceKey: '5021;6', onlyEnabled: false }) === null; + + if (this.isActive || (!this.isActive && !isNotInPricelist)) { + // if Autokeys already running OR Not running and exist in pricelist if (isBanking) { // enable keys banking - if banking conditions to enable banking matched and banking is enabled - this.setOverallStatus = [false, true, false, true, false, false]; - this.setOldAmount = [0, 0, rKeysCanBankMin, rKeysCanBankMax, currKeys]; - this.setActiveStatus = true; + common1(); this.updateToBank(setMinKeys, setMaxKeys, currKeyPrice); // } else if (isTooManyRefWhileBanking) { // enable keys banking - if refs > minRefs but Keys < minKeys, will buy keys. - this.setOverallStatus = [true, false, false, false, true, false]; - this.setOldAmount = [0, rKeysCanBankMax, 0, 0, currKeys]; - this.setActiveStatus = true; + common2(); this.update(setMinKeys, setMaxKeys, currKeyPrice, 'buy'); // } else if (buyKeys) { // enable Autokeys - Buying - if buying keys conditions matched - this.setOverallStatus = [true, false, false, false, true, false]; - this.setOldAmount = [0, rKeysCanBuy, 0, 0, currKeys]; - this.setActiveStatus = true; + common3(); this.update(setMinKeys, setMaxKeys, currKeyPrice, 'buy'); // } else if (sellKeys) { // enable Autokeys - Selling - if selling keys conditions matched - this.setOverallStatus = [false, false, false, false, false, true]; - this.setOldAmount = [rKeysCanSell, 0, 0, 0, currKeys]; - this.setActiveStatus = true; + common4(); this.update(setMinKeys, setMaxKeys, currKeyPrice, 'sell'); // - } else if (isRemoveBankingKeys && isEnableKeyBanking) { + } else if ( + this.isActive && + ((isRemoveBankingKeys && isEnableKeyBanking) || (isRemoveAutoKeys && !isEnableKeyBanking)) + ) { // disable keys banking - if to conditions to disable banking matched and banking is enabled this.setOverallStatus = [false, false, false, false, false, false]; this.setActiveStatus = false; void this.disable(currKeyPrice); // - } else if (isRemoveAutoKeys && !isEnableKeyBanking) { - // disable Autokeys when conditions to disable Autokeys matched - this.setOverallStatus = [false, false, false, false, false, false]; - this.setActiveStatus = false; - void this.disable(currKeyPrice); - // } else if (isAlertAdmins && !this.status.checkAlertOnLowPure) { // alert admins when low pure - this.setOverallStatus = [false, false, true, false, false, false]; - this.setActiveStatus = false; - - const msg = 'I am now low on both keys and refs.'; - if (opt.sendAlert.enable && opt.sendAlert.autokeys.lowPure) { - if (opt.discordWebhook.sendAlert.enable && opt.discordWebhook.sendAlert.url.main !== '') { - sendAlert('lowPure', this.bot, msg); - } else { - this.bot.messageAdmins(msg, []); - } - } + common5(); } - } else { - // if Autokeys is not running/disabled - if (this.bot.pricelist.getPrice({ priceKey: '5021;6', onlyEnabled: false }) === null) { - // if Mann Co. Supply Crate Key entry does not exist in the pricelist.json - if (isBankingKeys && isEnableKeyBanking) { - //create new Key entry and enable keys banking - if banking conditions to enable banking matched and banking is enabled - this.setOverallStatus = [false, true, false, true, false, false]; - this.setOldAmount = [0, 0, rKeysCanBankMin, rKeysCanBankMax, currKeys]; - this.setActiveStatus = true; - this.createToBank(setMinKeys, setMaxKeys, currKeyPrice); - // - } else if (isBankingBuyKeysWithEnoughRefs && isEnableKeyBanking) { - // enable keys banking - if refs > minRefs but Keys < minKeys, will buy keys. - this.setOverallStatus = [true, false, false, false, true, false]; - this.setOldAmount = [0, rKeysCanBankMax, 0, 0, currKeys]; - this.setActiveStatus = true; - this.create(setMinKeys, setMaxKeys, currKeyPrice, 'buy'); - // - } else if (isBuyingKeys) { - // create new Key entry and enable Autokeys - Buying - if buying keys conditions matched - this.setOverallStatus = [true, false, false, false, true, false]; - this.setOldAmount = [0, rKeysCanBuy, 0, 0, currKeys]; - this.setActiveStatus = true; - this.create(setMinKeys, setMaxKeys, currKeyPrice, 'buy'); - // - } else if (isSellingKeys) { - // create new Key entry and enable Autokeys - Selling - if selling keys conditions matched - this.setOverallStatus = [false, false, false, false, false, true]; - this.setOldAmount = [rKeysCanSell, 0, 0, 0, currKeys]; - this.setActiveStatus = true; - this.create(setMinKeys, setMaxKeys, currKeyPrice, 'sell'); - // - } else if (isAlertAdmins && !this.status.checkAlertOnLowPure) { - // alert admins when low pure - this.setOverallStatus = [false, false, true, false, false, false]; - this.setActiveStatus = false; - - const msg = 'I am now low on both keys and refs.'; - if (opt.sendAlert.enable && opt.sendAlert.autokeys.lowPure) { - if (opt.discordWebhook.sendAlert.enable && opt.discordWebhook.sendAlert.url.main !== '') { - sendAlert('lowPure', this.bot, msg); - } else { - this.bot.messageAdmins(msg, []); - } - } - } - } else { - // if Mann Co. Supply Crate Key entry already in the pricelist.json - if (isBanking) { - // enable keys banking - if banking conditions to enable banking matched and banking is enabled - this.setOverallStatus = [false, true, false, true, false, false]; - this.setOldAmount = [0, 0, rKeysCanBankMin, rKeysCanBankMax, currKeys]; - this.setActiveStatus = true; - this.updateToBank(setMinKeys, setMaxKeys, currKeyPrice); - // - } else if (isTooManyRefWhileBanking) { - // enable keys banking - if refs > minRefs but Keys < minKeys, will buy keys. - this.setOverallStatus = [true, false, false, false, true, false]; - this.setOldAmount = [0, rKeysCanBankMax, 0, 0, currKeys]; - this.setActiveStatus = true; - this.update(setMinKeys, setMaxKeys, currKeyPrice, 'buy'); - // - } else if (buyKeys) { - // enable Autokeys - Buying - if buying keys conditions matched - this.setOverallStatus = [true, false, false, false, true, false]; - this.setOldAmount = [0, rKeysCanBuy, 0, 0, currKeys]; - this.setActiveStatus = true; - this.update(setMinKeys, setMaxKeys, currKeyPrice, 'buy'); - // - } else if (sellKeys) { - // enable Autokeys - Selling - if selling keys conditions matched - this.setOverallStatus = [false, false, false, false, false, true]; - this.setOldAmount = [rKeysCanSell, 0, 0, 0, currKeys]; - this.setActiveStatus = true; - this.update(setMinKeys, setMaxKeys, currKeyPrice, 'sell'); - // - } else if (isAlertAdmins && !this.status.checkAlertOnLowPure) { - // alert admins when low pure - this.setOverallStatus = [false, false, true, false, false, false]; - this.setActiveStatus = false; - - const msg = 'I am now low on both keys and refs.'; - if (opt.sendAlert.enable && opt.sendAlert.autokeys.lowPure) { - if (opt.discordWebhook.sendAlert.enable && opt.discordWebhook.sendAlert.url.main !== '') { - sendAlert('lowPure', this.bot, msg); - } else { - this.bot.messageAdmins(msg, []); - } - } - } + } else if (isNotInPricelist) { + // if Autokeys is not running/disabled AND not exist in pricelist + if (isBankingKeys && isEnableKeyBanking) { + //create new Key entry and enable keys banking - if banking conditions to enable banking matched and banking is enabled + common1(); + this.createToBank(setMinKeys, setMaxKeys, currKeyPrice); + // + } else if (isBankingBuyKeysWithEnoughRefs && isEnableKeyBanking) { + // enable keys banking - if refs > minRefs but Keys < minKeys, will buy keys. + common2(); + this.create(setMinKeys, setMaxKeys, currKeyPrice, 'buy'); + // + } else if (isBuyingKeys) { + // create new Key entry and enable Autokeys - Buying - if buying keys conditions matched + common3(); + this.create(setMinKeys, setMaxKeys, currKeyPrice, 'buy'); + // + } else if (isSellingKeys) { + // create new Key entry and enable Autokeys - Selling - if selling keys conditions matched + common4(); + this.create(setMinKeys, setMaxKeys, currKeyPrice, 'sell'); + // + } else if (isAlertAdmins && !this.status.checkAlertOnLowPure) { + // alert admins when low pure + common5(); } } log.debug( @@ -689,11 +641,7 @@ export default class Autokeys { disable(keyPrices: KeyPrices): Promise { return new Promise((resolve, reject) => { const match = this.bot.pricelist.getPrice({ priceKey: '5021;6', onlyEnabled: false }); - if (match === null) { - return resolve(); - } - - if (!match.enabled) { + if (match === null || !match.enabled) { return resolve(); } diff --git a/src/classes/Commands/Commands.ts b/src/classes/Commands/Commands.ts index 1d0c571ab..696777091 100644 --- a/src/classes/Commands/Commands.ts +++ b/src/classes/Commands/Commands.ts @@ -1505,9 +1505,7 @@ function getMptfDashboardItems(mptfApiKey: string, ignorePainted = false): Promi return resolve(toReturn); }) - .catch(err => { - reject(err); - }); + .catch(err => reject(err)); }); } diff --git a/src/classes/Friends.ts b/src/classes/Friends.ts index 688edac44..6ee01122d 100644 --- a/src/classes/Friends.ts +++ b/src/classes/Friends.ts @@ -65,9 +65,7 @@ export default class Friends { this.maxFriends = base + level * multiplier; resolve(this.maxFriends); }) - .catch(err => { - return reject(err); - }); + .catch(err => reject(err)); }); } } diff --git a/src/classes/TF2Inventory.ts b/src/classes/TF2Inventory.ts index 934dfd9a3..1415c80b9 100644 --- a/src/classes/TF2Inventory.ts +++ b/src/classes/TF2Inventory.ts @@ -118,9 +118,7 @@ export default class TF2Inventory { this.items = body.result.items; return resolve(); }) - .catch(err => { - return reject(err); - }); + .catch(err => reject(err)); }); } @@ -160,9 +158,7 @@ export default class TF2Inventory { history: [] }); }) - .catch(err => { - return reject(err); - }); + .catch(err => reject(err)); }); } } diff --git a/src/lib/apiRequest.ts b/src/lib/apiRequest.ts index f0249a4bb..542553da1 100644 --- a/src/lib/apiRequest.ts +++ b/src/lib/apiRequest.ts @@ -45,14 +45,7 @@ export async function apiRequest({ return new Promise((resolve, reject) => { axios(options) - .then(response => { - const body = response.data as B; - resolve(body); - }) - .catch((err: AxiosError) => { - if (err) { - reject(filterAxiosError(err)); - } - }); + .then(response => resolve(response.data as B)) + .catch((err: AxiosError) => reject(filterAxiosError(err))); }); } diff --git a/src/lib/bans.ts b/src/lib/bans.ts index 9835c28cb..e7b6432cf 100644 --- a/src/lib/bans.ts +++ b/src/lib/bans.ts @@ -226,10 +226,8 @@ export default class Bans { return resolve({ isBanned: this._isBptfBanned, content: result.content }); }) .catch(err => { - if (this.showLog) { - log.warn('Failed to get data from backpack.tf'); - log.debug(err); - } + log.warn('Failed to get data from backpack.tf'); + log.debug(err); return resolve(undefined); }); }); @@ -252,10 +250,8 @@ export default class Bans { return resolve({ isBanned: isSteamRepBanned, content: fullRepInfo }); }) .catch(err => { - if (this.showLog) { - log.warn('Failed to get data from SteamRep'); - log.debug(err); - } + log.warn('Failed to get data from SteamRep'); + log.debug(err); if (this._isBptfSteamRepBanned !== null) { return resolve({ isBanned: this._isBptfSteamRepBanned }); } @@ -308,7 +304,7 @@ export default class Bans { return resolve({ isBanned: false }); }) .catch(err => { - if (this.showLog) log.warn('Failed to get data from Marketplace.tf', err); + log.warn('Failed to get data from Marketplace.tf', err); return resolve(undefined); }); }); @@ -338,12 +334,8 @@ export default class Bans { if (err instanceof AbortSignal && attempt !== 'retry') { return this.isListedUntrusted('retry'); } - if (err) { - if (this.showLog) { - log.warn('Failed to get data from Github'); - log.debug(err); - } - } + log.warn('Failed to get data from Github'); + log.debug(err); resolve(undefined); }); }); diff --git a/src/lib/pricer/custom/custom-pricer-api.ts b/src/lib/pricer/custom/custom-pricer-api.ts index 1aed91050..ec42d82fa 100644 --- a/src/lib/pricer/custom/custom-pricer-api.ts +++ b/src/lib/pricer/custom/custom-pricer-api.ts @@ -101,15 +101,9 @@ export default class CustomPricerApi { return new Promise((resolve, reject) => { axios(options) - .then(response => { - // eslint-disable-next-line @typescript-eslint/no-unsafe-argument - resolve(response.data); - }) - .catch((err: AxiosError) => { - if (err) { - reject(filterAxiosError(err)); - } - }); + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + .then(response => resolve(response.data)) + .catch((err: AxiosError) => reject(filterAxiosError(err))); }); }