Skip to content

Commit

Permalink
Merge branch 'master' into IPC
Browse files Browse the repository at this point in the history
  • Loading branch information
idinium96 committed Jul 18, 2024
2 parents e96df6f + f8d7ea5 commit 2ffa33f
Show file tree
Hide file tree
Showing 21 changed files with 419 additions and 558 deletions.
287 changes: 125 additions & 162 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tf2autobot",
"version": "5.12.2",
"version": "5.13.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 @@ -23,7 +23,7 @@
"url": "https://github.com/TF2Autobot/tf2autobot/issues"
},
"updaterepo": true,
"updateMessage": "",
"updateMessage": "Steam/TF2 is quite unstable right now, update/restart at your own will.",
"homepage": "https://github.com/TF2Autobot/tf2autobot#readme",
"dependencies": {
"@tf2autobot/bptf-listings": "^5.7.7",
Expand All @@ -33,7 +33,7 @@
"@tf2autobot/steamcommunity": "^3.48.2",
"@tf2autobot/tf2": "^1.3.6",
"@tf2autobot/tf2-currencies": "^2.0.1",
"@tf2autobot/tf2-schema": "^4.4.4",
"@tf2autobot/tf2-schema": "^4.5.0",
"@tf2autobot/tf2-sku": "^2.0.4",
"@tf2autobot/tradeoffer-manager": "^2.17.6",
"async": "^3.2.5",
Expand Down Expand Up @@ -73,7 +73,7 @@
"winston": "^3.13.0",
"winston-daily-rotate-file": "^4.7.1",
"write-file-atomic": "^5.0.0",
"ws": "^7.5.9"
"ws": "^7.5.10"
},
"devDependencies": {
"@babel/preset-typescript": "^7.24.1",
Expand Down
18 changes: 5 additions & 13 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,12 @@ import { apiRequest } from './lib/apiRequest';

/*eslint-disable */
SchemaManager.prototype.getSchema = function (callback): void {
apiRequest('GET', 'https://schema.autobot.tf/schema')
apiRequest({ method: 'GET', url: 'https://schema.autobot.tf/schema' })
.then(schema => {
this.setSchema(schema, true);
callback(null, this.schema);
})
.catch(err => {
callback(err);
});
.catch(err => callback(err));
};
/*eslint-enable */

Expand All @@ -86,9 +84,7 @@ const botManager = new BotManager(
import ON_DEATH from 'death';
import * as inspect from 'util';
import { Webhook } from './classes/DiscordWebhook/interfaces';
import axios, { AxiosError } from 'axios';
import { uptime } from './lib/tools/time';
import filterAxiosError from '@tf2autobot/filter-axios-error';

ON_DEATH({ uncaughtException: true })((signalOrErr, origin: string | Error) => {
const crashed = !['SIGINT', 'SIGTERM'].includes(signalOrErr as 'SIGINT' | 'SIGTERM' | 'SIGQUIT');
Expand Down Expand Up @@ -143,13 +139,9 @@ ON_DEATH({ uncaughtException: true })((signalOrErr, origin: string | Error) => {
]
};

void axios({
method: 'POST',
url: optDW.sendAlert.url.main,
data: sendAlertWebhook // axios should automatically set Content-Type header to application/json
}).catch((err: AxiosError) => {
log.error('Error sending webhook on crash', filterAxiosError(err));
});
apiRequest({ method: 'POST', url: optDW.sendAlert.url.main, data: sendAlertWebhook }).catch(err =>
log.error('Error sending webhook on crash', err)
);
}

if (botReady) {
Expand Down
210 changes: 79 additions & 131 deletions src/classes/Autokeys/Autokeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,7 @@ export default class Autokeys {

check(): void {
log.debug(`checking autokeys (Enabled: ${String(this.isEnabled)})`);
if (this.isEnabled === false) {
return;
}
if (this.isEnabled === false) return;

const userPure = this.userPure;

Expand Down Expand Up @@ -319,7 +317,6 @@ export default class Autokeys {
if (setMaxKeys === currKeys) {
setMaxKeys += 1;
}

if (currKeys >= setMaxKeys) {
setMaxKeys = currKeys + 1;
}
Expand Down Expand Up @@ -354,152 +351,107 @@ export default class Autokeys {
rKeysCanSell !== this.oldAmount.keysCanSell ||
currKeys !== this.oldAmount.ofKeys);

if (this.isActive) {
// if Autokeys already running
const alertLowPure = () => {
const msg = 'I am now low on both keys and refs.';
if (opt.sendAlert.enable && opt.sendAlert.autokeys.lowPure) {
if (opt.discordWebhook.sendAlert.enable && opt.discordWebhook.sendAlert.url.main !== '')
sendAlert('lowPure', this.bot, msg);
else this.bot.messageAdmins(msg, []);
}
};

const common1 = () => {
this.setOverallStatus = [false, true, false, true, false, false];
this.setOldAmount = [0, 0, rKeysCanBankMin, rKeysCanBankMax, currKeys];
this.setActiveStatus = true;
};

const common2 = () => {
this.setOverallStatus = [true, false, false, false, true, false];
this.setOldAmount = [0, rKeysCanBankMax, 0, 0, currKeys];
this.setActiveStatus = true;
};

const common3 = () => {
this.setOverallStatus = [true, false, false, false, true, false];
this.setOldAmount = [0, rKeysCanBuy, 0, 0, currKeys];
this.setActiveStatus = true;
};

const common4 = () => {
this.setOverallStatus = [false, false, false, false, false, true];
this.setOldAmount = [rKeysCanSell, 0, 0, 0, currKeys];
this.setActiveStatus = true;
};

const common5 = () => {
this.setOverallStatus = [false, false, true, false, false, false];
this.setActiveStatus = false;
alertLowPure();
};

const isNotInPricelist = this.bot.pricelist.getPrice({ priceKey: '5021;6', onlyEnabled: false }) === null;

if (this.isActive || (!this.isActive && !isNotInPricelist)) {
// if Autokeys already running OR Not running and exist in pricelist
if (isBanking) {
// enable keys banking - if banking conditions to enable banking matched and banking is enabled
this.setOverallStatus = [false, true, false, true, false, false];
this.setOldAmount = [0, 0, rKeysCanBankMin, rKeysCanBankMax, currKeys];
this.setActiveStatus = true;
common1();
this.updateToBank(setMinKeys, setMaxKeys, currKeyPrice);
//
} else if (isTooManyRefWhileBanking) {
// enable keys banking - if refs > minRefs but Keys < minKeys, will buy keys.
this.setOverallStatus = [true, false, false, false, true, false];
this.setOldAmount = [0, rKeysCanBankMax, 0, 0, currKeys];
this.setActiveStatus = true;
common2();
this.update(setMinKeys, setMaxKeys, currKeyPrice, 'buy');
//
} else if (buyKeys) {
// enable Autokeys - Buying - if buying keys conditions matched
this.setOverallStatus = [true, false, false, false, true, false];
this.setOldAmount = [0, rKeysCanBuy, 0, 0, currKeys];
this.setActiveStatus = true;
common3();
this.update(setMinKeys, setMaxKeys, currKeyPrice, 'buy');
//
} else if (sellKeys) {
// enable Autokeys - Selling - if selling keys conditions matched
this.setOverallStatus = [false, false, false, false, false, true];
this.setOldAmount = [rKeysCanSell, 0, 0, 0, currKeys];
this.setActiveStatus = true;
common4();
this.update(setMinKeys, setMaxKeys, currKeyPrice, 'sell');
//
} else if (isRemoveBankingKeys && isEnableKeyBanking) {
} else if (
this.isActive &&
((isRemoveBankingKeys && isEnableKeyBanking) || (isRemoveAutoKeys && !isEnableKeyBanking))
) {
// disable keys banking - if to conditions to disable banking matched and banking is enabled
this.setOverallStatus = [false, false, false, false, false, false];
this.setActiveStatus = false;
void this.disable(currKeyPrice);
//
} else if (isRemoveAutoKeys && !isEnableKeyBanking) {
// disable Autokeys when conditions to disable Autokeys matched
this.setOverallStatus = [false, false, false, false, false, false];
this.setActiveStatus = false;
void this.disable(currKeyPrice);
//
} else if (isAlertAdmins && !this.status.checkAlertOnLowPure) {
// alert admins when low pure
this.setOverallStatus = [false, false, true, false, false, false];
this.setActiveStatus = false;

const msg = 'I am now low on both keys and refs.';
if (opt.sendAlert.enable && opt.sendAlert.autokeys.lowPure) {
if (opt.discordWebhook.sendAlert.enable && opt.discordWebhook.sendAlert.url.main !== '') {
sendAlert('lowPure', this.bot, msg);
} else {
this.bot.messageAdmins(msg, []);
}
}
common5();
}
} else {
// if Autokeys is not running/disabled
if (this.bot.pricelist.getPrice({ priceKey: '5021;6', onlyEnabled: false }) === null) {
// if Mann Co. Supply Crate Key entry does not exist in the pricelist.json
if (isBankingKeys && isEnableKeyBanking) {
//create new Key entry and enable keys banking - if banking conditions to enable banking matched and banking is enabled
this.setOverallStatus = [false, true, false, true, false, false];
this.setOldAmount = [0, 0, rKeysCanBankMin, rKeysCanBankMax, currKeys];
this.setActiveStatus = true;
this.createToBank(setMinKeys, setMaxKeys, currKeyPrice);
//
} else if (isBankingBuyKeysWithEnoughRefs && isEnableKeyBanking) {
// enable keys banking - if refs > minRefs but Keys < minKeys, will buy keys.
this.setOverallStatus = [true, false, false, false, true, false];
this.setOldAmount = [0, rKeysCanBankMax, 0, 0, currKeys];
this.setActiveStatus = true;
this.create(setMinKeys, setMaxKeys, currKeyPrice, 'buy');
//
} else if (isBuyingKeys) {
// create new Key entry and enable Autokeys - Buying - if buying keys conditions matched
this.setOverallStatus = [true, false, false, false, true, false];
this.setOldAmount = [0, rKeysCanBuy, 0, 0, currKeys];
this.setActiveStatus = true;
this.create(setMinKeys, setMaxKeys, currKeyPrice, 'buy');
//
} else if (isSellingKeys) {
// create new Key entry and enable Autokeys - Selling - if selling keys conditions matched
this.setOverallStatus = [false, false, false, false, false, true];
this.setOldAmount = [rKeysCanSell, 0, 0, 0, currKeys];
this.setActiveStatus = true;
this.create(setMinKeys, setMaxKeys, currKeyPrice, 'sell');
//
} else if (isAlertAdmins && !this.status.checkAlertOnLowPure) {
// alert admins when low pure
this.setOverallStatus = [false, false, true, false, false, false];
this.setActiveStatus = false;

const msg = 'I am now low on both keys and refs.';
if (opt.sendAlert.enable && opt.sendAlert.autokeys.lowPure) {
if (opt.discordWebhook.sendAlert.enable && opt.discordWebhook.sendAlert.url.main !== '') {
sendAlert('lowPure', this.bot, msg);
} else {
this.bot.messageAdmins(msg, []);
}
}
}
} else {
// if Mann Co. Supply Crate Key entry already in the pricelist.json
if (isBanking) {
// enable keys banking - if banking conditions to enable banking matched and banking is enabled
this.setOverallStatus = [false, true, false, true, false, false];
this.setOldAmount = [0, 0, rKeysCanBankMin, rKeysCanBankMax, currKeys];
this.setActiveStatus = true;
this.updateToBank(setMinKeys, setMaxKeys, currKeyPrice);
//
} else if (isTooManyRefWhileBanking) {
// enable keys banking - if refs > minRefs but Keys < minKeys, will buy keys.
this.setOverallStatus = [true, false, false, false, true, false];
this.setOldAmount = [0, rKeysCanBankMax, 0, 0, currKeys];
this.setActiveStatus = true;
this.update(setMinKeys, setMaxKeys, currKeyPrice, 'buy');
//
} else if (buyKeys) {
// enable Autokeys - Buying - if buying keys conditions matched
this.setOverallStatus = [true, false, false, false, true, false];
this.setOldAmount = [0, rKeysCanBuy, 0, 0, currKeys];
this.setActiveStatus = true;
this.update(setMinKeys, setMaxKeys, currKeyPrice, 'buy');
//
} else if (sellKeys) {
// enable Autokeys - Selling - if selling keys conditions matched
this.setOverallStatus = [false, false, false, false, false, true];
this.setOldAmount = [rKeysCanSell, 0, 0, 0, currKeys];
this.setActiveStatus = true;
this.update(setMinKeys, setMaxKeys, currKeyPrice, 'sell');
//
} else if (isAlertAdmins && !this.status.checkAlertOnLowPure) {
// alert admins when low pure
this.setOverallStatus = [false, false, true, false, false, false];
this.setActiveStatus = false;

const msg = 'I am now low on both keys and refs.';
if (opt.sendAlert.enable && opt.sendAlert.autokeys.lowPure) {
if (opt.discordWebhook.sendAlert.enable && opt.discordWebhook.sendAlert.url.main !== '') {
sendAlert('lowPure', this.bot, msg);
} else {
this.bot.messageAdmins(msg, []);
}
}
}
} else if (isNotInPricelist) {
// if Autokeys is not running/disabled AND not exist in pricelist
if (isBankingKeys && isEnableKeyBanking) {
//create new Key entry and enable keys banking - if banking conditions to enable banking matched and banking is enabled
common1();
this.createToBank(setMinKeys, setMaxKeys, currKeyPrice);
//
} else if (isBankingBuyKeysWithEnoughRefs && isEnableKeyBanking) {
// enable keys banking - if refs > minRefs but Keys < minKeys, will buy keys.
common2();
this.create(setMinKeys, setMaxKeys, currKeyPrice, 'buy');
//
} else if (isBuyingKeys) {
// create new Key entry and enable Autokeys - Buying - if buying keys conditions matched
common3();
this.create(setMinKeys, setMaxKeys, currKeyPrice, 'buy');
//
} else if (isSellingKeys) {
// create new Key entry and enable Autokeys - Selling - if selling keys conditions matched
common4();
this.create(setMinKeys, setMaxKeys, currKeyPrice, 'sell');
//
} else if (isAlertAdmins && !this.status.checkAlertOnLowPure) {
// alert admins when low pure
common5();
}
}
log.debug(
Expand Down Expand Up @@ -689,11 +641,7 @@ export default class Autokeys {
disable(keyPrices: KeyPrices): Promise<void> {
return new Promise((resolve, reject) => {
const match = this.bot.pricelist.getPrice({ priceKey: '5021;6', onlyEnabled: false });
if (match === null) {
return resolve();
}

if (!match.enabled) {
if (match === null || !match.enabled) {
return resolve();
}

Expand Down
Loading

0 comments on commit 2ffa33f

Please sign in to comment.