Skip to content

Commit

Permalink
Merge branch 'development' into upgrade-discordjs
Browse files Browse the repository at this point in the history
  • Loading branch information
idinium96 committed Aug 5, 2022
2 parents 216bfe2 + bd873a6 commit 02a6a6a
Show file tree
Hide file tree
Showing 7 changed files with 328 additions and 188 deletions.
11 changes: 11 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.git/**/*
.example/**/*
.github/**/*
.idea/**/*
.vscode/**
dist/**/*
node_modules/**/*
.env
npm-debug.log
package-lock.json
yarn.lock
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ RUN npm install typescript@latest pm2 -g && \
cd /app && \
npm install && \
npm run build && \
rm -rf src/ .idea/ .vscode/
rm -rf src/

WORKDIR /app

Expand Down
420 changes: 278 additions & 142 deletions package-lock.json

Large diffs are not rendered by default.

17 changes: 8 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tf2autobot",
"version": "5.2.1",
"version": "5.3.0",
"description": "Fully automated TF2 trading bot advertising on www.backpack.tf using prices from www.prices.tf, Originally made by Nicklason.",
"main": "dist/app.js",
"scripts": {
Expand All @@ -26,7 +26,7 @@
"updateMessage": "",
"homepage": "https://github.com/TF2Autobot/tf2autobot#readme",
"dependencies": {
"@tf2autobot/bptf-listings": "^5.6.5",
"@tf2autobot/bptf-listings": "^5.6.6",
"@tf2autobot/bptf-login": "^2.3.4",
"@tf2autobot/filter-axios-error": "^1.4.0",
"@tf2autobot/jsonlint": "^1.0.0",
Expand Down Expand Up @@ -59,11 +59,10 @@
"retry": "^0.13.1",
"socket.io-client": "^4.5.1",
"steam-totp": "^2.1.2",
"steam-user": "^4.24.5",
"steam-user": "^4.24.6",
"steamid": "^2.0.0",
"url": "^0.11.0",
"valid-url": "^1.0.9",
"websocket-extensions": "^0.1.4",
"winston": "^3.8.1",
"winston-daily-rotate-file": "^4.7.1",
"write-file-atomic": "^4.0.1",
Expand All @@ -76,19 +75,19 @@
"@types/express": "^4.17.13",
"@types/graceful-fs": "^4.1.5",
"@types/jest": "^28.1.6",
"@types/node": "^18.0.6",
"@types/node": "^18.6.3",
"@types/pluralize": "0.0.29",
"@types/request": "^2.48.8",
"@types/retry": "^0.12.2",
"@types/semver": "^7.3.10",
"@types/valid-url": "^1.0.3",
"@types/write-file-atomic": "^4.0.0",
"@types/ws": "^8.5.3",
"@typescript-eslint/eslint-plugin": "^5.30.7",
"@typescript-eslint/parser": "^5.30.7",
"eslint": "^8.20.0",
"@typescript-eslint/eslint-plugin": "^5.32.0",
"@typescript-eslint/parser": "^5.32.0",
"eslint": "^8.21.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-jest": "^26.6.0",
"eslint-plugin-jest": "^26.7.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-tsdoc": "^0.2.16",
"jest": "^28.1.3",
Expand Down
40 changes: 19 additions & 21 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 @@ -2497,7 +2493,7 @@ export default class MyHandler extends Handler {
clearTimeout(this.retryRequest);

this.retryRequest = setTimeout(() => {
void this.getBPTFAccountInfo().catch(() => {
this.getBPTFAccountInfo().catch(() => {
// ignore error
});
}, 5 * 60 * 1000);
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
22 changes: 9 additions & 13 deletions src/lib/pricer/pricestf/prices-tf-api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import axios, { AxiosRequestConfig, Method, AxiosError } from 'axios';
import filterAxiosError from '@tf2autobot/filter-axios-error';
import filterAxiosError, { ErrorFiltered } from '@tf2autobot/filter-axios-error';
import { PricerOptions } from '../../../classes/IPricer';
import log from '../../logger';

Expand Down Expand Up @@ -63,8 +63,8 @@ export default class PricesTfApi {
...headers
});
} catch (e) {
const err = e as AxiosError;
if (err.response && err.response.status === 401) {
const err = e as ErrorFiltered;
if (err?.status === 401) {
log.debug('Requesting new token from prices.tf due to 401');
await this.setupToken();
return this.authedApiRequest(httpMethod, path, params, data, headers);
Expand Down Expand Up @@ -123,16 +123,12 @@ export default class PricesTfApi {
}

async setupToken(): Promise<void> {
return new Promise((resolve, reject) => {
void PricesTfApi.requestAuthAccess()
.then(response => {
this.token = response.accessToken;
resolve();
})
.catch(err => {
reject(err);
});
});
try {
const r = await PricesTfApi.requestAuthAccess();
this.token = r.accessToken;
} catch (e) {
log.error(e as Error);
}
}

async requestCheck(sku: string): Promise<PricesTfRequestCheckResponse> {
Expand Down

0 comments on commit 02a6a6a

Please sign in to comment.