From 3a879bede316640e214a26bcf8a61efac8f8653a Mon Sep 17 00:00:00 2001 From: IdiNium <47635037+idinium96@users.noreply.github.com> Date: Tue, 17 Jan 2023 06:14:18 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20temporarily=20disable=20item=20w?= =?UTF-8?q?ith=20ppu=20if=20failed=20to=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../offer/accepted/updateListings.ts | 36 ++++++++++++++----- src/lib/DiscordWebhook/sendAlert.ts | 7 ++++ 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/classes/MyHandler/offer/accepted/updateListings.ts b/src/classes/MyHandler/offer/accepted/updateListings.ts index ef8f40489..c5515eb81 100644 --- a/src/classes/MyHandler/offer/accepted/updateListings.ts +++ b/src/classes/MyHandler/offer/accepted/updateListings.ts @@ -583,18 +583,38 @@ export default function updateListings( if (isPricecheckRequestEnabled) addToQ(priceKey, isNotPure, existsInPricelist); }) .catch(err => { - const msg = `❌ Failed to automatically update prices for ${name} (${priceKey}): ${ + let msg = `❌ Failed to automatically update partially priced for ${name} (${priceKey}) and the item has been temporarily disabled.\n\nError: ${ (err as Error).message }`; log.error(`❌ Failed to automatically update prices for ${priceKey}`, err); - if (opt.sendAlert.enable && opt.sendAlert.partialPrice.onFailedUpdatePartialPriced) { - if (dwEnabled) { - sendAlert('autoUpdatePartialPriceFailed', bot, msg); - } else { - bot.messageAdmins(msg, []); - } - } + entry.autoprice = false; + entry.enabled = false; + bot.pricelist + .updatePrice({ priceKey: entry.sku, entryData: entry, emitChange: true }) + .then(() => { + log.info(`${name} (${priceKey}) has been temporarily disabled.`); + + if (opt.sendAlert.enable && opt.sendAlert.partialPrice.onFailedUpdatePartialPriced) { + if (dwEnabled) { + sendAlert('autoUpdatePartialPriceFailed', bot, msg); + } else { + bot.messageAdmins(msg, []); + } + } + }) + .catch(err => { + log.error(`Error disabling ${name} (${priceKey}):`, err); + + if (opt.sendAlert.enable && opt.sendAlert.partialPrice.onFailedUpdatePartialPriced) { + if (dwEnabled) { + msg = `❌ Failed to automatically disable partially priced ${name} (${priceKey}) after failing to get the latest item price.`; + sendAlert('autoUpdatePartialPriceFailedToDisable', bot, msg); + } else { + bot.messageAdmins(msg, []); + } + } + }); if (isPricecheckRequestEnabled) addToQ(priceKey, isNotPure, existsInPricelist); }); diff --git a/src/lib/DiscordWebhook/sendAlert.ts b/src/lib/DiscordWebhook/sendAlert.ts index a3909b951..a282c9a9e 100644 --- a/src/lib/DiscordWebhook/sendAlert.ts +++ b/src/lib/DiscordWebhook/sendAlert.ts @@ -40,6 +40,7 @@ type AlertType = | 'error-accept' | 'autoUpdatePartialPriceSuccess' | 'autoUpdatePartialPriceFailed' + | 'autoUpdatePartialPriceFailedToDisable' | 'autoResetPartialPrice' | 'autoResetPartialPriceBulk' | 'onBulkUpdatePartialPriced' @@ -156,6 +157,10 @@ export default function sendAlert( title = 'Failed update item prices (Partial price update)'; description = msg; color = '16711680'; // red + } else if (type === 'autoUpdatePartialPriceFailedToDisable') { + title = 'Failed disabling item (Partial price update failed)'; + description = msg; + color = '16711680'; // red } else if (type === 'autoResetPartialPrice') { title = '✅ Automatically reset partially priced item'; description = msg; @@ -256,6 +261,7 @@ export default function sendAlert( 'escrow-check-failed-not-restart-bptf-down', 'queue-problem-not-restart-bptf-down', 'autoAddPaintedItemsFailed', + 'autoUpdatePartialPriceFailedToDisable', 'failed-accept', 'error-accept', 'unusualInvalidItems' @@ -282,6 +288,7 @@ export default function sendAlert( [ 'autoUpdatePartialPriceSuccess', 'autoUpdatePartialPriceFailed', + 'autoUpdatePartialPriceFailedToDisable', 'autoResetPartialPrice', 'autoResetPartialPriceBulk', 'onBulkUpdatePartialPriced',