From 5bc274eed2953a8e3971167e91d5e096c5224433 Mon Sep 17 00:00:00 2001 From: idinium96 <47635037+idinium96@users.noreply.github.com> Date: Fri, 5 Mar 2021 08:55:23 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9C=A8option=20to=20show=20proper=20name?= =?UTF-8?q?=20(with=20"The",=20no=20short)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/classes/Options.ts | 2 ++ src/lib/DiscordWebhook/sendOfferReview.ts | 30 +++++++++++++++------- src/lib/DiscordWebhook/sendTradeSummary.ts | 30 +++++++++++++++------- src/lib/tools/summarizeItems.ts | 13 +++++++--- src/lib/tools/summarizeOffer.ts | 5 ++-- src/schemas/options-json/options.ts | 3 +++ 6 files changed, 60 insertions(+), 23 deletions(-) diff --git a/src/classes/Options.ts b/src/classes/Options.ts index 568f215a4..d607357b1 100644 --- a/src/classes/Options.ts +++ b/src/classes/Options.ts @@ -116,6 +116,7 @@ export const DEFAULTS = { showTimeTakenInMS: false, showItemPrices: true, showPureInEmoji: false, + showProperName: false, customText: { summary: { steamChat: 'Summary', @@ -1093,6 +1094,7 @@ interface TradeSummary { showTimeTakenInMS?: boolean; showItemPrices?: boolean; showPureInEmoji?: boolean; + showProperName?: boolean; customText?: TradeSummaryCustomText; } diff --git a/src/lib/DiscordWebhook/sendOfferReview.ts b/src/lib/DiscordWebhook/sendOfferReview.ts index 235a28f07..6b5bd79c1 100644 --- a/src/lib/DiscordWebhook/sendOfferReview.ts +++ b/src/lib/DiscordWebhook/sendOfferReview.ts @@ -40,15 +40,27 @@ export default function sendOfferReview( const pureStock = pure.stock(bot); const message = replace.specialChar(offer.message); - const itemsName = { - invalid: items.invalid.map(name => replace.itemName(name)), - disabled: items.disabled.map(name => replace.itemName(name)), - overstock: items.overstock.map(name => replace.itemName(name)), - understock: items.understock.map(name => replace.itemName(name)), - duped: items.duped.map(name => replace.itemName(name)), - dupedFailed: items.dupedFailed.map(name => replace.itemName(name)), - highValue: items.highValue.map(name => replace.itemName(name)) - }; + const properName = bot.options.tradeSummary.showProperName; + + const itemsName = properName + ? { + invalid: items.invalid, + disabled: items.disabled, + overstock: items.overstock, + understock: items.understock, + duped: items.duped, + dupedFailed: items.dupedFailed, + highValue: items.highValue + } + : { + invalid: items.invalid.map(name => replace.itemName(name)), + disabled: items.disabled.map(name => replace.itemName(name)), + overstock: items.overstock.map(name => replace.itemName(name)), + understock: items.understock.map(name => replace.itemName(name)), + duped: items.duped.map(name => replace.itemName(name)), + dupedFailed: items.dupedFailed.map(name => replace.itemName(name)), + highValue: items.highValue.map(name => replace.itemName(name)) + }; const slots = bot.tf2.backpackSlots; const currentItems = bot.inventoryManager.getInventory.getTotalItems; diff --git a/src/lib/DiscordWebhook/sendTradeSummary.ts b/src/lib/DiscordWebhook/sendTradeSummary.ts index 244e886fd..86f986834 100644 --- a/src/lib/DiscordWebhook/sendTradeSummary.ts +++ b/src/lib/DiscordWebhook/sendTradeSummary.ts @@ -18,15 +18,27 @@ export default async function sendTradeSummary( const optBot = bot.options; const optDW = optBot.discordWebhook; - const itemsName = { - invalid: accepted.invalidItems.map(name => t.replace.itemName(name)), // 🟨_INVALID_ITEMS - disabled: accepted.disabledItems.map(name => t.replace.itemName(name)), // 🟧_DISABLED_ITEMS - overstock: accepted.overstocked.map(name => t.replace.itemName(name)), // 🟦_OVERSTOCKED - understock: accepted.understocked.map(name => t.replace.itemName(name)), // 🟩_UNDERSTOCKED - duped: [], - dupedFailed: [], - highValue: accepted.highValue.map(name => t.replace.itemName(name)) // 🔶_HIGH_VALUE_ITEMS - }; + const properName = bot.options.tradeSummary.showProperName; + + const itemsName = properName + ? { + invalid: accepted.invalidItems, + disabled: accepted.disabledItems, + overstock: accepted.overstocked, + understock: accepted.understocked, + duped: [], + dupedFailed: [], + highValue: accepted.highValue + } + : { + invalid: accepted.invalidItems.map(name => t.replace.itemName(name)), // 🟨_INVALID_ITEMS + disabled: accepted.disabledItems.map(name => t.replace.itemName(name)), // 🟧_DISABLED_ITEMS + overstock: accepted.overstocked.map(name => t.replace.itemName(name)), // 🟦_OVERSTOCKED + understock: accepted.understocked.map(name => t.replace.itemName(name)), // 🟩_UNDERSTOCKED + duped: [], + dupedFailed: [], + highValue: accepted.highValue.map(name => t.replace.itemName(name)) // 🔶_HIGH_VALUE_ITEMS + }; const keyPrices = bot.pricelist.getKeyPrices; const value = t.valueDiff(offer, keyPrices, isTradingKeys, optBot.miscSettings.showOnlyMetal.enable); diff --git a/src/lib/tools/summarizeItems.ts b/src/lib/tools/summarizeItems.ts index f6f29d360..59aa8449a 100644 --- a/src/lib/tools/summarizeItems.ts +++ b/src/lib/tools/summarizeItems.ts @@ -112,10 +112,11 @@ function listPrices(offer: TradeOffer, bot: Bot, isSteamChat: boolean): string { let text = ''; const toJoin: string[] = []; + const properName = bot.options.tradeSummary.showProperName; let buyPrice: string; let sellPrice: string; - let autoprice = 'unknown/removed'; + let autoprice = 'removed'; for (const sku in prices) { if (!Object.prototype.hasOwnProperty.call(prices, sku)) { @@ -135,8 +136,14 @@ function listPrices(offer: TradeOffer, bot: Bot, isSteamChat: boolean): string { toJoin.push( `${ isSteamChat - ? `${bot.schema.getName(SKU.fromString(sku), false)} - ${buyPrice} / ${sellPrice} (${autoprice})` - : `_${bot.schema.getName(SKU.fromString(sku), false)}_ - ${buyPrice} / ${sellPrice} (${autoprice})` + ? `${bot.schema.getName( + SKU.fromString(sku), + properName + )} - ${buyPrice} / ${sellPrice} (${autoprice})` + : `_${bot.schema.getName( + SKU.fromString(sku), + properName + )}_ - ${buyPrice} / ${sellPrice} (${autoprice})` }` ); } diff --git a/src/lib/tools/summarizeOffer.ts b/src/lib/tools/summarizeOffer.ts index d717dcc64..b0e85ba3e 100644 --- a/src/lib/tools/summarizeOffer.ts +++ b/src/lib/tools/summarizeOffer.ts @@ -128,6 +128,7 @@ function getSummary( } const summary: string[] = []; + const properName = bot.options.tradeSummary.showProperName; for (const sku in dict) { if (!Object.prototype.hasOwnProperty.call(dict, sku)) { @@ -136,8 +137,8 @@ function getSummary( // compatible with pollData from before v3.0.0 / before v2.2.0 and/or v3.0.0 or later ↓ const amount = typeof dict[sku] === 'object' ? (dict[sku]['amount'] as number) : dict[sku]; - const generateName = bot.schema.getName(SKU.fromString(sku.replace(/;p\d+/, '')), false); - const name = replace.itemName(generateName ? generateName : 'unknown'); + const generateName = bot.schema.getName(SKU.fromString(sku.replace(/;p\d+/, '')), properName); + const name = properName ? generateName : replace.itemName(generateName ? generateName : 'unknown'); if (showStockChanges) { let oldStock = 0; diff --git a/src/schemas/options-json/options.ts b/src/schemas/options-json/options.ts index f9eb7971a..d7664a4d3 100644 --- a/src/schemas/options-json/options.ts +++ b/src/schemas/options-json/options.ts @@ -593,6 +593,9 @@ export const optionsSchema: jsonschema.Schema = { showPureInEmoji: { type: 'boolean' }, + showProperName: { + type: 'boolean' + }, customText: { type: 'object', properties: { From 8f2629f2bbf25370194d153b4bcdccb0751edf8f Mon Sep 17 00:00:00 2001 From: idinium96 <47635037+idinium96@users.noreply.github.com> Date: Fri, 5 Mar 2021 09:01:21 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=94=A8=20small=20refactor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/tools/summarizeItems.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/lib/tools/summarizeItems.ts b/src/lib/tools/summarizeItems.ts index 59aa8449a..0b64e38c4 100644 --- a/src/lib/tools/summarizeItems.ts +++ b/src/lib/tools/summarizeItems.ts @@ -133,17 +133,13 @@ function listPrices(offer: TradeOffer, bot: Bot, isSteamChat: boolean): string { sellPrice = new Currencies(prices[sku].sell).toString(); } + const name = bot.schema.getName(SKU.fromString(sku), properName); + toJoin.push( `${ isSteamChat - ? `${bot.schema.getName( - SKU.fromString(sku), - properName - )} - ${buyPrice} / ${sellPrice} (${autoprice})` - : `_${bot.schema.getName( - SKU.fromString(sku), - properName - )}_ - ${buyPrice} / ${sellPrice} (${autoprice})` + ? `${name} - ${buyPrice} / ${sellPrice} (${autoprice})` + : `_${name}_ - ${buyPrice} / ${sellPrice} (${autoprice})` }` ); }