From 12071d27fdcb035ea6c81f48a335df95855d675c Mon Sep 17 00:00:00 2001 From: idinium96 Date: Sat, 1 Aug 2020 03:44:51 +0800 Subject: [PATCH 1/3] add !relist command --- src/classes/Commands.ts | 51 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/classes/Commands.ts b/src/classes/Commands.ts index f941a3526..231216c78 100644 --- a/src/classes/Commands.ts +++ b/src/classes/Commands.ts @@ -53,6 +53,7 @@ const ADMIN_COMMANDS: string[] = [ '!add - Add a pricelist entry ➕', '!update - Update a pricelist entry', '!adjustrate buy.metal=&sell.metal= - Manually adjust key rate (reset on restart, self-update when key rate changes)', + '!relist - Perform relist if some of your listings are missing (you can run only once, then need to wait 30 minutes if you want to run it again)', '!remove OR - Remove a pricelist entry ➖', '!get OR - Get raw information about a pricelist entry', '!pricecheck OR - Requests an item to be priced by PricesTF', @@ -83,9 +84,24 @@ export = class Commands { private queuePositionCheck; + private first30Minutes = true; + + private first30MinutesTimeout; + + private executed: boolean; + + private lastExecutedTime: number | null = null; + + private executeTimeout; + constructor(bot: Bot) { this.bot = bot; this.discord = new DiscordWebhook(bot); + + this.first30MinutesTimeout = setTimeout(() => { + this.first30Minutes = false; + clearTimeout(this.first30MinutesTimeout); + }, 30 * 60 * 1000); } get cartQueue(): CartQueue { @@ -129,6 +145,8 @@ export = class Commands { this.rateCommand(steamID); } else if (command === 'adjustrate' && isAdmin) { this.adjustKeyRateCommand(steamID, message); + } else if (command === 'relist' && isAdmin) { + this.relistCommand(steamID); } else if (command === 'message') { this.messageCommand(steamID, message); } else if (command === 'cart') { @@ -417,6 +435,39 @@ export = class Commands { ); } + private relistCommand(steamID: SteamID): void { + if (this.first30Minutes) { + this.bot.sendMessage(steamID, `❌ I am just started... Please wait until the first 30 minutes has ended.`); + return; + } + + const newExecutedTime = moment().valueOf(); + const timeDiff = newExecutedTime - this.lastExecutedTime; + + if (this.executed === true) { + this.bot.sendMessage( + steamID, + '⚠️ You need to wait ' + + Math.trunc((30 * 60 * 1000 - timeDiff) / (1000 * 60)) + + ' minutes before you can relist again.' + ); + return; + } else { + clearTimeout(this.executeTimeout); + this.lastExecutedTime = moment().valueOf(); + + this.bot.listings.checkAllWithDelay(); + this.bot.sendMessage(steamID, `✅ Relisting executed.`); + + this.executed = true; + this.executeTimeout = setTimeout(() => { + this.lastExecutedTime = null; + this.executed = false; + clearTimeout(this.executeTimeout); + }, 30 * 60 * 1000); + } + } + private pureCommand(steamID: SteamID): void { const pureStock = (this.bot.handler as MyHandler).pureStock(); From eff4c58e940815b4739fb0c1602a9d88223aa4e6 Mon Sep 17 00:00:00 2001 From: idinium96 Date: Sat, 1 Aug 2020 03:46:31 +0800 Subject: [PATCH 2/3] !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; From 9cc5abedac72cd8a64d3697989a3daa55f3708cb Mon Sep 17 00:00:00 2001 From: idinium96 Date: Sat, 1 Aug 2020 03:51:01 +0800 Subject: [PATCH 3/3] update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c04875bb7..b57129ea6 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ The original tf2-automatic repository already have a lot of features, but some f - automatically restart your bot on queue problem, and automatically relist if backpack.tf does not synchronized with your bot listings on Autokeys (sometimes it's set to automatically buy keys, but at backpack.tf, it's listed to sell.) - use emojis on almost all messages - list out every items on each offer review reasons -- New added commands: "!pure", "!time", "!delete", "!check", "!block", "!unblock", "!autokeys", "!inventory", "!adjustrate", "!craftweapon" and "!uncraftweapon" commands +- New added commands: "!pure", "!time", "!delete", "!check", "!block", "!unblock", "!autokeys", "!inventory", "!adjustrate", "!relist", "!craftweapon" and "!uncraftweapon" commands - and more to come! ## Added features