Skip to content

Commit

Permalink
🔀Merge pull request #408 from TF2Autobot/option-exclude-partial-price
Browse files Browse the repository at this point in the history
✅ opt to exclude items for partial price update
  • Loading branch information
idinium96 authored Mar 4, 2021
2 parents ca2bc1b + 5a6b0ee commit e97de9d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/classes/Options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ export const DEFAULTS = {
pricelist: {
partialPriceUpdate: {
enable: false,
thresholdInSeconds: 604800 // 7 days
thresholdInSeconds: 604800, // 7 days
excludeSKU: []
},
filterCantAfford: {
enable: false
Expand Down Expand Up @@ -1058,6 +1059,7 @@ interface Pricelist {

interface PartialPriceUpdate extends OnlyEnable {
thresholdInSeconds?: number;
excludeSKU?: string[];
}

interface PriceAge {
Expand Down
7 changes: 5 additions & 2 deletions src/classes/Pricelist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,7 @@ export default class Pricelist extends EventEmitter {
// Go through our pricelist
const oldCount = old.length;
const opt = this.options.pricelist.partialPriceUpdate;
const excludedSKU = ['5021;6'].concat(opt.excludeSKU);
const keyPrice = this.getKeyPrice.metal;

for (let i = 0; i < oldCount; i++) {
Expand Down Expand Up @@ -733,8 +734,9 @@ export default class Pricelist extends EventEmitter {
const currSellingValue = currPrice.sell.toValue(keyPrice);

const isNotExceedThreshold = newestPrice.time - currPrice.time < opt.thresholdInSeconds;
const isNotExcluded = !excludedSKU.includes(currPrice.sku);

if (opt.enable && isInStock && isNotExceedThreshold && currPrice.sku !== '5021;6') {
if (opt.enable && isInStock && isNotExceedThreshold && isNotExcluded) {
// if optPartialUpdate.enable is true and the item is currently in stock
// and difference between latest time and time recorded in pricelist is less than threshold

Expand Down Expand Up @@ -859,13 +861,14 @@ export default class Pricelist extends EventEmitter {
const optPartialUpdate = opt.pricelist.partialPriceUpdate;
const isInStock = this.bot.inventoryManager.getInventory.getAmount(match.sku, true) > 0;
const isNotExceedThreshold = data.time - match.time < optPartialUpdate.thresholdInSeconds;
const isNotExcluded = !['5021;6'].concat(optPartialUpdate.excludeSKU).includes(match.sku);

if (
optPartialUpdate.enable &&
isInStock &&
isNotExceedThreshold &&
this.globalKeyPrices !== undefined &&
match.sku !== '5021;6'
isNotExcluded
) {
// if optPartialUpdate.enable is true and the item is currently in stock
// and difference between latest time and time recorded in pricelist is less than threshold
Expand Down
5 changes: 4 additions & 1 deletion src/schemas/options-json/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,12 @@ export const optionsSchema: jsonschema.Schema = {
thresholdInSeconds: {
type: 'integer',
minimum: 86400 // 1 day
},
excludeSKU: {
type: '#/definitions/string-array'
}
},
required: ['enable', 'thresholdInSeconds'],
required: ['enable', 'thresholdInSeconds', 'excludeSKU'],
additionalProperties: false
},
filterCantAfford: {
Expand Down

0 comments on commit e97de9d

Please sign in to comment.