From eff4c58e940815b4739fb0c1602a9d88223aa4e6 Mon Sep 17 00:00:00 2001 From: idinium96 Date: Sat, 1 Aug 2020 03:46:31 +0800 Subject: [PATCH] !adjustrate command will also refresh autokeys --- src/classes/Commands.ts | 12 +++++++++++- src/classes/MyHandler.ts | 24 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/classes/Commands.ts b/src/classes/Commands.ts index 231216c78..22d2dcdbe 100644 --- a/src/classes/Commands.ts +++ b/src/classes/Commands.ts @@ -617,8 +617,18 @@ export = class Commands { const sell = { keys: sellKeys, metal: sellMetal }; this.bot.pricelist.adjustKeyRate(buy, sell); + const autokeys = (this.bot.handler as MyHandler).getUserAutokeys(); + + let reply; + reply = '✅ Key rate adjusted to ' + new Currencies(buy) + '/' + new Currencies(sell); - this.bot.sendMessage(steamID, '✅ Key rate adjusted to ' + new Currencies(buy) + '/' + new Currencies(sell)); + if (autokeys.enabled === false) { + reply += '. Autokeys is disabled so no adjustment made on Autokeys.'; + } else { + (this.bot.handler as MyHandler).refreshAutoKeys(); + reply += '. Autokeys is enabled and has been automatically refreshed.'; + } + this.bot.sendMessage(steamID, reply); } private messageCommand(steamID: SteamID, message: string): void { diff --git a/src/classes/MyHandler.ts b/src/classes/MyHandler.ts index e51d7f5fa..49e8954b3 100644 --- a/src/classes/MyHandler.ts +++ b/src/classes/MyHandler.ts @@ -2184,6 +2184,30 @@ Autokeys status:- }); } + refreshAutoKeys(): void { + const isKeysAlreadyExist = this.bot.pricelist.searchByName('Mann Co. Supply Crate Key', false); + if (isKeysAlreadyExist) { + this.bot.pricelist + .removePrice('5021;6', true) + .then(() => { + log.debug(`✅ Automatically remove Mann Co. Supply Crate Key.`); + this.isBuyingKeys = false; + this.isBankingKeys = false; + this.checkAutokeysStatus = false; + this.checkAlertOnLowPure = false; + this.alreadyUpdatedToBank = false; + this.alreadyUpdatedToBuy = false; + this.alreadyUpdatedToSell = false; + }) + .catch(err => { + log.warn(`❌ Failed to remove Mann Co. Supply Crate Key automatically: ${err.message}`); + this.checkAutokeysStatus = true; + }); + } + this.sleep(2000); + this.autokeys(); + } + private keepMetalSupply(): void { if (process.env.DISABLE_CRAFTING === 'true') { return;