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();