Skip to content

Commit

Permalink
✨ opt to always decline non-TF2 items + refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
idinium96 committed Apr 22, 2021
1 parent 86497af commit e4a2ff9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
47 changes: 29 additions & 18 deletions src/classes/MyHandler/MyHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ export default class MyHandler extends Handler {
let isNoiseMakerNotFullUses = false;
const noiseMakerNotFullSKUs: string[] = [];

// let hasInvalidItems = false;
let hasNonTF2Items = false;

const states = [false, true];
for (let i = 0; i < states.length; i++) {
Expand All @@ -770,10 +770,10 @@ export default class MyHandler extends Handler {
continue;
}

// if (sku === 'unknown') {
// // Offer contains an item that is not from TF2
// hasInvalidItems = true;
// }
if (!testSKU(sku)) {
// Offer contains an item that is not from TF2
hasNonTF2Items = true;
}

if (sku === '5000;6') {
exchange.contains.metal = true;
Expand Down Expand Up @@ -907,11 +907,11 @@ export default class MyHandler extends Handler {
return;
}

// if (hasInvalidItems) {
// // Using boolean because items dict always needs to be saved
// offer.log('info', 'contains items not from TF2, declining...');
// return { action: 'decline', reason: '🟨_INVALID_ITEMS_CONTAINS_NON_TF2' };
// }
if (hasNonTF2Items && opt.offerReceived.alwaysDeclineNonTF2Items) {
// Using boolean because items dict always needs to be saved
offer.log('info', 'contains items not from TF2, declining...');
return { action: 'decline', reason: '🟨_CONTAINS_NON_TF2' };
}

const offerMessage = offer.message.toLowerCase();

Expand Down Expand Up @@ -1089,6 +1089,8 @@ export default class MyHandler extends Handler {

const amount = items[which][sku].length;

let isNonTF2Items = false;

if (sku === '5000;6') {
exchange[which].value += amount;
exchange[which].scrap += amount;
Expand All @@ -1109,14 +1111,23 @@ export default class MyHandler extends Handler {
exchange[which].value += value;
exchange[which].scrap += value;
} else {
const match =
which === 'our'
? testSKU(sku)
let match: Entry | null = null;

if (hasNonTF2Items) {
if (testSKU(sku)) {
match =
which === 'our'
? this.bot.pricelist.getPrice(sku)
: this.bot.pricelist.getPrice(sku, false, true);
} else {
isNonTF2Items = true;
}
} else {
match =
which === 'our'
? this.bot.pricelist.getPrice(sku)
: null
: testSKU(sku)
? this.bot.pricelist.getPrice(sku, false, true)
: null;
: this.bot.pricelist.getPrice(sku, false, true);
}

const notIncludeCraftweapons = this.isWeaponsAsCurrency.enable
? !(
Expand Down Expand Up @@ -1240,7 +1251,7 @@ export default class MyHandler extends Handler {

let itemSuggestedValue = 'No price';

if (testSKU(sku)) {
if (!isNonTF2Items) {
// await sleepasync().Promise.sleep(1 * 1000);
const price = await this.bot.pricelist.getItemPrices(sku);
const item = SKU.fromString(sku);
Expand Down
2 changes: 2 additions & 0 deletions src/classes/Options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ export const DEFAULTS = {
sendPreAcceptMessage: {
enable: true
},
alwaysDeclineNonTF2Items: true,
// 🟥_INVALID_VALUE
invalidValue: {
autoDecline: {
Expand Down Expand Up @@ -1269,6 +1270,7 @@ interface Metals extends OnlyEnable {

interface OfferReceived {
sendPreAcceptMessage?: OnlyEnable;
alwaysDeclineNonTF2Items?: boolean;
invalidValue?: InvalidValue;
invalidItems?: InvalidItems;
disabledItems?: AutoAcceptOverpayAndAutoDecline;
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 @@ -992,6 +992,9 @@ export const optionsSchema: jsonschema.Schema = {
sendPreAcceptMessage: {
$ref: '#/definitions/only-enable'
},
alwaysDeclineNonTF2Items: {
type: 'boolean'
},
invalidValue: {
type: 'object',
properties: {
Expand Down

0 comments on commit e4a2ff9

Please sign in to comment.