Skip to content

Commit

Permalink
🔀 Merge pull request #1284 from TF2Autobot/fix-unhandled-rejection-error
Browse files Browse the repository at this point in the history
🐛 Fix unhandled rejection error that crashes the bot
  • Loading branch information
idinium96 authored Aug 1, 2022
2 parents 3e5248c + c3a0dd5 commit e19caaf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
38 changes: 18 additions & 20 deletions src/classes/MyHandler/MyHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,13 @@ export default class MyHandler extends Handler {
keepMetalSupply(this.bot, this.minimumScrap, this.minimumReclaimed, this.combineThreshold);

// Craft duplicate weapons
void craftDuplicateWeapons(this.bot);

// Craft class weapons
this.classWeaponsTimeout = setTimeout(() => {
// called after 5 seconds to craft metals and duplicated weapons first.
void craftClassWeapons(this.bot);
}, 5 * 1000);
craftDuplicateWeapons(this.bot)
.then(() => {
return craftClassWeapons(this.bot);
})
.catch(err => {
log.warn('Failed to craft duplicated craft/class weapons', err);
});
}

if (this.isDeletingUntradableJunk) {
Expand Down Expand Up @@ -2205,18 +2205,14 @@ export default class MyHandler extends Handler {
// Smelt / combine metal
keepMetalSupply(this.bot, this.minimumScrap, this.minimumReclaimed, this.combineThreshold);

// Craft duplicated weapons
void craftDuplicateWeapons(this.bot);

this.classWeaponsTimeout = setTimeout(() => {
// called after 5 second to craft metals and duplicated weapons first.
void craftClassWeapons(this.bot);
}, 5 * 1000);
}

if (this.isDeletingUntradableJunk) {
// Delete untradable junk
this.deleteUntradableJunk();
// Craft duplicate weapons
craftDuplicateWeapons(this.bot)
.then(() => {
return craftClassWeapons(this.bot);
})
.catch(err => {
log.warn('Failed to craft duplicated craft/class weapons', err);
});
}

// Sort inventory
Expand Down Expand Up @@ -2546,7 +2542,9 @@ export default class MyHandler extends Handler {

for (const assetid of assetidsToDelete) {
log.debug(`Deleting junk item ${assetid}`);
this.bot.tf2gc.deleteItem(assetid);
this.bot.tf2gc.deleteItem(assetid, err => {
log.warn('Error deleting untradable junk', err);
});
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/classes/MyHandler/utils/craftClassWeapons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ export type ClassesForCraftableWeapons =

export type SlotsForCraftableWeapons = 'primary' | 'secondary' | 'melee' | 'pda2';

export default function craftClassWeapons(bot: Bot): Promise<void> {
export default async function craftClassWeapons(bot: Bot): Promise<void> {
if (!bot.options.crafting.weapons.enable) {
return;
}
const currencies = bot.inventoryManager.getInventory.getCurrencies(bot.craftWeapons, false);

void Promise.all(
await Promise.all(
['scout', 'soldier', 'pyro', 'demoman', 'heavy', 'engineer', 'medic', 'sniper', 'spy'].map(classChar =>
craftEachClassWeapons(bot, bot.craftWeaponsByClass[classChar as ClassesForCraftableWeapons], currencies)
)
Expand Down

0 comments on commit e19caaf

Please sign in to comment.