Skip to content

Commit

Permalink
🔀Merge pull request #415 from TF2Autobot/options/proper-name
Browse files Browse the repository at this point in the history
✨option to show proper name (with "The", no short)
  • Loading branch information
idinium96 authored Mar 5, 2021
2 parents 20ca897 + 8f2629f commit ca429b6
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 23 deletions.
2 changes: 2 additions & 0 deletions src/classes/Options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export const DEFAULTS = {
showTimeTakenInMS: false,
showItemPrices: true,
showPureInEmoji: false,
showProperName: false,
customText: {
summary: {
steamChat: 'Summary',
Expand Down Expand Up @@ -1093,6 +1094,7 @@ interface TradeSummary {
showTimeTakenInMS?: boolean;
showItemPrices?: boolean;
showPureInEmoji?: boolean;
showProperName?: boolean;
customText?: TradeSummaryCustomText;
}

Expand Down
30 changes: 21 additions & 9 deletions src/lib/DiscordWebhook/sendOfferReview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
30 changes: 21 additions & 9 deletions src/lib/DiscordWebhook/sendTradeSummary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 6 additions & 3 deletions src/lib/tools/summarizeItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -132,11 +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), false)} - ${buyPrice} / ${sellPrice} (${autoprice})`
: `_${bot.schema.getName(SKU.fromString(sku), false)}_ - ${buyPrice} / ${sellPrice} (${autoprice})`
? `${name} - ${buyPrice} / ${sellPrice} (${autoprice})`
: `_${name}_ - ${buyPrice} / ${sellPrice} (${autoprice})`
}`
);
}
Expand Down
5 changes: 3 additions & 2 deletions src/lib/tools/summarizeOffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/schemas/options-json/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,9 @@ export const optionsSchema: jsonschema.Schema = {
showPureInEmoji: {
type: 'boolean'
},
showProperName: {
type: 'boolean'
},
customText: {
type: 'object',
properties: {
Expand Down

0 comments on commit ca429b6

Please sign in to comment.