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

🔨 Bypass checking listings if failed, just delete all on shutdown #1314

Merged
merged 1 commit into from
Aug 14, 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
47 changes: 33 additions & 14 deletions src/classes/Listings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { DictItem } from './Inventory';
import { PaintedNames } from './Options';
import ListingManager from '@tf2autobot/bptf-listings';
import getAttachmentName from '../lib/tools/getAttachmentName';
import filterAxiosError from '@tf2autobot/filter-axios-error';

export default class Listings {
private checkingAllListings = false;
Expand Down Expand Up @@ -446,24 +447,42 @@ export default class Listings {
this.bot.listingManager.actions.create = [];

// Wait for backpack.tf to finish creating / removing listings
void this.waitForListings().then(() => {
if (this.bot.listingManager.listings.length === 0) {
log.debug('We have no listings');
this.removingAllListings = false;
return resolve();
}
this.waitForListings()
.then(() => {
if (this.bot.listingManager.listings.length === 0) {
log.debug('We have no listings');
this.removingAllListings = false;
return resolve();
}

log.debug('Removing all listings...');
log.debug('Removing all listings...');

this.bot.listingManager.deleteAllListings(err => {
if (err) {
return reject(err);
}
this.bot.listingManager.deleteAllListings(err => {
if (err) {
return reject(err);
}

// The request might fail, if it does we will try again
return resolve(this.removeAllListings());
// The request might fail, if it does we will try again
return resolve(this.removeAllListings());
});
})
.catch(err => {
// if an error occurred, we bypass checking listings and just call delete all listings

log.error(
'Error getting listings info, force delete all listings. Error details: ',
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
filterAxiosError(err)
);
this.bot.listingManager.deleteAllListings(err => {
if (err) {
// But if failed to delete all listings, blame bptf 😴
return reject(err);
}

return resolve();
});
});
});
});
}

Expand Down
5 changes: 4 additions & 1 deletion src/classes/MyHandler/MyHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2552,7 +2552,10 @@ export default class MyHandler extends Handler {
async onPricelist(pricelist: PricesObject): Promise<void> {
if (Object.keys(pricelist).length === 0) {
// Ignore errors
await this.bot.listings.removeAll();
await this.bot.listings.removeAll().catch(err => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
log.error('Error on removing all listings: ', filterAxiosError(err));
});
}

/*
Expand Down