Skip to content

Commit

Permalink
πŸ”€ Merge pull request #1049 from carlosliam/delete-junk
Browse files Browse the repository at this point in the history
πŸ—‘οΈ Add opt-in deletion of seasonal junk untradables
  • Loading branch information
idinium96 committed May 20, 2022
2 parents cd9e986 + 06cb685 commit 28207aa
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 2 deletions.
5 changes: 4 additions & 1 deletion .example/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
"customTexture": {
"enable": true
}
},
"deleteUntradableJunk": {
"enable": false
}
},
"sendAlert": {
Expand Down Expand Up @@ -1001,4 +1004,4 @@
"Robots Killed During Halloween": ""
}
}
}
}
21 changes: 21 additions & 0 deletions src/classes/Inventory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,27 @@ export default class Inventory {
return dict;
}

findUntradableJunk(): string[] {
const result: string[] = [];
for (const sku in this.nonTradable) {
const item = SKU.fromString(sku);
if (
[
536, // Noise Maker - TF Birthday
537, // Party Hat
655, // Spirit of Giving
5826 // Soul Gargoyle
].includes(item.defindex)
) {
for (const itemWithAssetid of this.nonTradable[sku]) {
result.push(itemWithAssetid.id);
}
}
}

return result;
}

private static highValue(
sku: string,
econ: EconItem,
Expand Down
23 changes: 23 additions & 0 deletions src/classes/MyHandler/MyHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ export default class MyHandler extends Handler {
return this.opt.crafting.manual;
}

private get isDeletingUntradableJunk(): boolean {
return this.opt.miscSettings.deleteUntradableJunk.enable;
}

private isPremium = false;

private botName = '';
Expand Down Expand Up @@ -272,6 +276,11 @@ export default class MyHandler extends Handler {
}, 5 * 1000);
}

if (this.isDeletingUntradableJunk) {
// Delete untradable junk
this.deleteUntradableJunk();
}

// Auto sell and buy keys if ref < minimum
this.autokeys.check();

Expand Down Expand Up @@ -2192,6 +2201,11 @@ export default class MyHandler extends Handler {
}, 5 * 1000);
}

if (this.isDeletingUntradableJunk) {
// Delete untradable junk
this.deleteUntradableJunk();
}

// Sort inventory
this.sortInventory();

Expand Down Expand Up @@ -2476,6 +2490,15 @@ export default class MyHandler extends Handler {
});
}

private deleteUntradableJunk(): void {
const assetidsToDelete = this.bot.inventoryManager.getInventory.findUntradableJunk();

for (const assetid of assetidsToDelete) {
log.debug(`Deleting junk item ${assetid}`);
this.bot.tf2gc.deleteItem(assetid);
}
}

onPollData(pollData: PollData): void {
files.writeFile(this.paths.files.pollData, pollData, true).catch(err => {
log.warn('Failed to save polldata: ', err);
Expand Down
4 changes: 4 additions & 0 deletions src/classes/Options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ export const DEFAULTS: JsonOptions = {
// giftedByTag: {
// enable: true
// }
},
deleteUntradableJunk: {
enable: false
}
},

Expand Down Expand Up @@ -1118,6 +1121,7 @@ interface MiscSettings {
checkUses?: CheckUses;
game?: Game;
alwaysRemoveItemAttributes?: AlwaysRemoveItemAttributes;
deleteUntradableJunk?: OnlyEnable;
}

interface AlwaysRemoveItemAttributes {
Expand Down
6 changes: 5 additions & 1 deletion src/schemas/options-json/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,9 @@ export const optionsSchema: jsonschema.Schema = {
},
required: ['customTexture'], // 'giftedByTag'
additionalProperties: false
},
deleteUntradableJunk: {
$ref: '#/definitions/only-enable'
}
},
required: [
Expand All @@ -440,7 +443,8 @@ export const optionsSchema: jsonschema.Schema = {
'weaponsAsCurrency',
'checkUses',
'game',
'alwaysRemoveItemAttributes'
'alwaysRemoveItemAttributes',
'deleteUntradableJunk'
],
additionalProperties: false
},
Expand Down

0 comments on commit 28207aa

Please sign in to comment.