Skip to content

Commit 2ffa33f

Browse files
committed
Merge branch 'master' into IPC
2 parents e96df6f + f8d7ea5 commit 2ffa33f

File tree

21 files changed

+419
-558
lines changed

21 files changed

+419
-558
lines changed

package-lock.json

Lines changed: 125 additions & 162 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tf2autobot",
3-
"version": "5.12.2",
3+
"version": "5.13.0",
44
"description": "Fully automated TF2 trading bot advertising on www.backpack.tf using prices from www.prices.tf, Originally made by Nicklason.",
55
"main": "dist/app.js",
66
"scripts": {
@@ -23,7 +23,7 @@
2323
"url": "https://github.com/TF2Autobot/tf2autobot/issues"
2424
},
2525
"updaterepo": true,
26-
"updateMessage": "",
26+
"updateMessage": "Steam/TF2 is quite unstable right now, update/restart at your own will.",
2727
"homepage": "https://github.com/TF2Autobot/tf2autobot#readme",
2828
"dependencies": {
2929
"@tf2autobot/bptf-listings": "^5.7.7",
@@ -33,7 +33,7 @@
3333
"@tf2autobot/steamcommunity": "^3.48.2",
3434
"@tf2autobot/tf2": "^1.3.6",
3535
"@tf2autobot/tf2-currencies": "^2.0.1",
36-
"@tf2autobot/tf2-schema": "^4.4.4",
36+
"@tf2autobot/tf2-schema": "^4.5.0",
3737
"@tf2autobot/tf2-sku": "^2.0.4",
3838
"@tf2autobot/tradeoffer-manager": "^2.17.6",
3939
"async": "^3.2.5",
@@ -73,7 +73,7 @@
7373
"winston": "^3.13.0",
7474
"winston-daily-rotate-file": "^4.7.1",
7575
"write-file-atomic": "^5.0.0",
76-
"ws": "^7.5.9"
76+
"ws": "^7.5.10"
7777
},
7878
"devDependencies": {
7979
"@babel/preset-typescript": "^7.24.1",

src/app.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,12 @@ import { apiRequest } from './lib/apiRequest';
6464

6565
/*eslint-disable */
6666
SchemaManager.prototype.getSchema = function (callback): void {
67-
apiRequest('GET', 'https://schema.autobot.tf/schema')
67+
apiRequest({ method: 'GET', url: 'https://schema.autobot.tf/schema' })
6868
.then(schema => {
6969
this.setSchema(schema, true);
7070
callback(null, this.schema);
7171
})
72-
.catch(err => {
73-
callback(err);
74-
});
72+
.catch(err => callback(err));
7573
};
7674
/*eslint-enable */
7775

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

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

146-
void axios({
147-
method: 'POST',
148-
url: optDW.sendAlert.url.main,
149-
data: sendAlertWebhook // axios should automatically set Content-Type header to application/json
150-
}).catch((err: AxiosError) => {
151-
log.error('Error sending webhook on crash', filterAxiosError(err));
152-
});
142+
apiRequest({ method: 'POST', url: optDW.sendAlert.url.main, data: sendAlertWebhook }).catch(err =>
143+
log.error('Error sending webhook on crash', err)
144+
);
153145
}
154146

155147
if (botReady) {

src/classes/Autokeys/Autokeys.ts

Lines changed: 79 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,7 @@ export default class Autokeys {
124124

125125
check(): void {
126126
log.debug(`checking autokeys (Enabled: ${String(this.isEnabled)})`);
127-
if (this.isEnabled === false) {
128-
return;
129-
}
127+
if (this.isEnabled === false) return;
130128

131129
const userPure = this.userPure;
132130

@@ -319,7 +317,6 @@ export default class Autokeys {
319317
if (setMaxKeys === currKeys) {
320318
setMaxKeys += 1;
321319
}
322-
323320
if (currKeys >= setMaxKeys) {
324321
setMaxKeys = currKeys + 1;
325322
}
@@ -354,152 +351,107 @@ export default class Autokeys {
354351
rKeysCanSell !== this.oldAmount.keysCanSell ||
355352
currKeys !== this.oldAmount.ofKeys);
356353

357-
if (this.isActive) {
358-
// if Autokeys already running
354+
const alertLowPure = () => {
355+
const msg = 'I am now low on both keys and refs.';
356+
if (opt.sendAlert.enable && opt.sendAlert.autokeys.lowPure) {
357+
if (opt.discordWebhook.sendAlert.enable && opt.discordWebhook.sendAlert.url.main !== '')
358+
sendAlert('lowPure', this.bot, msg);
359+
else this.bot.messageAdmins(msg, []);
360+
}
361+
};
362+
363+
const common1 = () => {
364+
this.setOverallStatus = [false, true, false, true, false, false];
365+
this.setOldAmount = [0, 0, rKeysCanBankMin, rKeysCanBankMax, currKeys];
366+
this.setActiveStatus = true;
367+
};
368+
369+
const common2 = () => {
370+
this.setOverallStatus = [true, false, false, false, true, false];
371+
this.setOldAmount = [0, rKeysCanBankMax, 0, 0, currKeys];
372+
this.setActiveStatus = true;
373+
};
374+
375+
const common3 = () => {
376+
this.setOverallStatus = [true, false, false, false, true, false];
377+
this.setOldAmount = [0, rKeysCanBuy, 0, 0, currKeys];
378+
this.setActiveStatus = true;
379+
};
380+
381+
const common4 = () => {
382+
this.setOverallStatus = [false, false, false, false, false, true];
383+
this.setOldAmount = [rKeysCanSell, 0, 0, 0, currKeys];
384+
this.setActiveStatus = true;
385+
};
386+
387+
const common5 = () => {
388+
this.setOverallStatus = [false, false, true, false, false, false];
389+
this.setActiveStatus = false;
390+
alertLowPure();
391+
};
392+
393+
const isNotInPricelist = this.bot.pricelist.getPrice({ priceKey: '5021;6', onlyEnabled: false }) === null;
394+
395+
if (this.isActive || (!this.isActive && !isNotInPricelist)) {
396+
// if Autokeys already running OR Not running and exist in pricelist
359397
if (isBanking) {
360398
// enable keys banking - if banking conditions to enable banking matched and banking is enabled
361-
this.setOverallStatus = [false, true, false, true, false, false];
362-
this.setOldAmount = [0, 0, rKeysCanBankMin, rKeysCanBankMax, currKeys];
363-
this.setActiveStatus = true;
399+
common1();
364400
this.updateToBank(setMinKeys, setMaxKeys, currKeyPrice);
365401
//
366402
} else if (isTooManyRefWhileBanking) {
367403
// enable keys banking - if refs > minRefs but Keys < minKeys, will buy keys.
368-
this.setOverallStatus = [true, false, false, false, true, false];
369-
this.setOldAmount = [0, rKeysCanBankMax, 0, 0, currKeys];
370-
this.setActiveStatus = true;
404+
common2();
371405
this.update(setMinKeys, setMaxKeys, currKeyPrice, 'buy');
372406
//
373407
} else if (buyKeys) {
374408
// enable Autokeys - Buying - if buying keys conditions matched
375-
this.setOverallStatus = [true, false, false, false, true, false];
376-
this.setOldAmount = [0, rKeysCanBuy, 0, 0, currKeys];
377-
this.setActiveStatus = true;
409+
common3();
378410
this.update(setMinKeys, setMaxKeys, currKeyPrice, 'buy');
379411
//
380412
} else if (sellKeys) {
381413
// enable Autokeys - Selling - if selling keys conditions matched
382-
this.setOverallStatus = [false, false, false, false, false, true];
383-
this.setOldAmount = [rKeysCanSell, 0, 0, 0, currKeys];
384-
this.setActiveStatus = true;
414+
common4();
385415
this.update(setMinKeys, setMaxKeys, currKeyPrice, 'sell');
386416
//
387-
} else if (isRemoveBankingKeys && isEnableKeyBanking) {
417+
} else if (
418+
this.isActive &&
419+
((isRemoveBankingKeys && isEnableKeyBanking) || (isRemoveAutoKeys && !isEnableKeyBanking))
420+
) {
388421
// disable keys banking - if to conditions to disable banking matched and banking is enabled
389422
this.setOverallStatus = [false, false, false, false, false, false];
390423
this.setActiveStatus = false;
391424
void this.disable(currKeyPrice);
392425
//
393-
} else if (isRemoveAutoKeys && !isEnableKeyBanking) {
394-
// disable Autokeys when conditions to disable Autokeys matched
395-
this.setOverallStatus = [false, false, false, false, false, false];
396-
this.setActiveStatus = false;
397-
void this.disable(currKeyPrice);
398-
//
399426
} else if (isAlertAdmins && !this.status.checkAlertOnLowPure) {
400427
// alert admins when low pure
401-
this.setOverallStatus = [false, false, true, false, false, false];
402-
this.setActiveStatus = false;
403-
404-
const msg = 'I am now low on both keys and refs.';
405-
if (opt.sendAlert.enable && opt.sendAlert.autokeys.lowPure) {
406-
if (opt.discordWebhook.sendAlert.enable && opt.discordWebhook.sendAlert.url.main !== '') {
407-
sendAlert('lowPure', this.bot, msg);
408-
} else {
409-
this.bot.messageAdmins(msg, []);
410-
}
411-
}
428+
common5();
412429
}
413-
} else {
414-
// if Autokeys is not running/disabled
415-
if (this.bot.pricelist.getPrice({ priceKey: '5021;6', onlyEnabled: false }) === null) {
416-
// if Mann Co. Supply Crate Key entry does not exist in the pricelist.json
417-
if (isBankingKeys && isEnableKeyBanking) {
418-
//create new Key entry and enable keys banking - if banking conditions to enable banking matched and banking is enabled
419-
this.setOverallStatus = [false, true, false, true, false, false];
420-
this.setOldAmount = [0, 0, rKeysCanBankMin, rKeysCanBankMax, currKeys];
421-
this.setActiveStatus = true;
422-
this.createToBank(setMinKeys, setMaxKeys, currKeyPrice);
423-
//
424-
} else if (isBankingBuyKeysWithEnoughRefs && isEnableKeyBanking) {
425-
// enable keys banking - if refs > minRefs but Keys < minKeys, will buy keys.
426-
this.setOverallStatus = [true, false, false, false, true, false];
427-
this.setOldAmount = [0, rKeysCanBankMax, 0, 0, currKeys];
428-
this.setActiveStatus = true;
429-
this.create(setMinKeys, setMaxKeys, currKeyPrice, 'buy');
430-
//
431-
} else if (isBuyingKeys) {
432-
// create new Key entry and enable Autokeys - Buying - if buying keys conditions matched
433-
this.setOverallStatus = [true, false, false, false, true, false];
434-
this.setOldAmount = [0, rKeysCanBuy, 0, 0, currKeys];
435-
this.setActiveStatus = true;
436-
this.create(setMinKeys, setMaxKeys, currKeyPrice, 'buy');
437-
//
438-
} else if (isSellingKeys) {
439-
// create new Key entry and enable Autokeys - Selling - if selling keys conditions matched
440-
this.setOverallStatus = [false, false, false, false, false, true];
441-
this.setOldAmount = [rKeysCanSell, 0, 0, 0, currKeys];
442-
this.setActiveStatus = true;
443-
this.create(setMinKeys, setMaxKeys, currKeyPrice, 'sell');
444-
//
445-
} else if (isAlertAdmins && !this.status.checkAlertOnLowPure) {
446-
// alert admins when low pure
447-
this.setOverallStatus = [false, false, true, false, false, false];
448-
this.setActiveStatus = false;
449-
450-
const msg = 'I am now low on both keys and refs.';
451-
if (opt.sendAlert.enable && opt.sendAlert.autokeys.lowPure) {
452-
if (opt.discordWebhook.sendAlert.enable && opt.discordWebhook.sendAlert.url.main !== '') {
453-
sendAlert('lowPure', this.bot, msg);
454-
} else {
455-
this.bot.messageAdmins(msg, []);
456-
}
457-
}
458-
}
459-
} else {
460-
// if Mann Co. Supply Crate Key entry already in the pricelist.json
461-
if (isBanking) {
462-
// enable keys banking - if banking conditions to enable banking matched and banking is enabled
463-
this.setOverallStatus = [false, true, false, true, false, false];
464-
this.setOldAmount = [0, 0, rKeysCanBankMin, rKeysCanBankMax, currKeys];
465-
this.setActiveStatus = true;
466-
this.updateToBank(setMinKeys, setMaxKeys, currKeyPrice);
467-
//
468-
} else if (isTooManyRefWhileBanking) {
469-
// enable keys banking - if refs > minRefs but Keys < minKeys, will buy keys.
470-
this.setOverallStatus = [true, false, false, false, true, false];
471-
this.setOldAmount = [0, rKeysCanBankMax, 0, 0, currKeys];
472-
this.setActiveStatus = true;
473-
this.update(setMinKeys, setMaxKeys, currKeyPrice, 'buy');
474-
//
475-
} else if (buyKeys) {
476-
// enable Autokeys - Buying - if buying keys conditions matched
477-
this.setOverallStatus = [true, false, false, false, true, false];
478-
this.setOldAmount = [0, rKeysCanBuy, 0, 0, currKeys];
479-
this.setActiveStatus = true;
480-
this.update(setMinKeys, setMaxKeys, currKeyPrice, 'buy');
481-
//
482-
} else if (sellKeys) {
483-
// enable Autokeys - Selling - if selling keys conditions matched
484-
this.setOverallStatus = [false, false, false, false, false, true];
485-
this.setOldAmount = [rKeysCanSell, 0, 0, 0, currKeys];
486-
this.setActiveStatus = true;
487-
this.update(setMinKeys, setMaxKeys, currKeyPrice, 'sell');
488-
//
489-
} else if (isAlertAdmins && !this.status.checkAlertOnLowPure) {
490-
// alert admins when low pure
491-
this.setOverallStatus = [false, false, true, false, false, false];
492-
this.setActiveStatus = false;
493-
494-
const msg = 'I am now low on both keys and refs.';
495-
if (opt.sendAlert.enable && opt.sendAlert.autokeys.lowPure) {
496-
if (opt.discordWebhook.sendAlert.enable && opt.discordWebhook.sendAlert.url.main !== '') {
497-
sendAlert('lowPure', this.bot, msg);
498-
} else {
499-
this.bot.messageAdmins(msg, []);
500-
}
501-
}
502-
}
430+
} else if (isNotInPricelist) {
431+
// if Autokeys is not running/disabled AND not exist in pricelist
432+
if (isBankingKeys && isEnableKeyBanking) {
433+
//create new Key entry and enable keys banking - if banking conditions to enable banking matched and banking is enabled
434+
common1();
435+
this.createToBank(setMinKeys, setMaxKeys, currKeyPrice);
436+
//
437+
} else if (isBankingBuyKeysWithEnoughRefs && isEnableKeyBanking) {
438+
// enable keys banking - if refs > minRefs but Keys < minKeys, will buy keys.
439+
common2();
440+
this.create(setMinKeys, setMaxKeys, currKeyPrice, 'buy');
441+
//
442+
} else if (isBuyingKeys) {
443+
// create new Key entry and enable Autokeys - Buying - if buying keys conditions matched
444+
common3();
445+
this.create(setMinKeys, setMaxKeys, currKeyPrice, 'buy');
446+
//
447+
} else if (isSellingKeys) {
448+
// create new Key entry and enable Autokeys - Selling - if selling keys conditions matched
449+
common4();
450+
this.create(setMinKeys, setMaxKeys, currKeyPrice, 'sell');
451+
//
452+
} else if (isAlertAdmins && !this.status.checkAlertOnLowPure) {
453+
// alert admins when low pure
454+
common5();
503455
}
504456
}
505457
log.debug(
@@ -689,11 +641,7 @@ export default class Autokeys {
689641
disable(keyPrices: KeyPrices): Promise<void> {
690642
return new Promise((resolve, reject) => {
691643
const match = this.bot.pricelist.getPrice({ priceKey: '5021;6', onlyEnabled: false });
692-
if (match === null) {
693-
return resolve();
694-
}
695-
696-
if (!match.enabled) {
644+
if (match === null || !match.enabled) {
697645
return resolve();
698646
}
699647

0 commit comments

Comments
 (0)