Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix unhandled rejection error that crashes the bot #1284

Merged
merged 1 commit into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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