Skip to content

Commit 338d55b

Browse files
authored
🔀 Merge pull request #1777 from TF2Autobot/development
v5.13.0
2 parents b58b7b7 + 8d3d144 commit 338d55b

File tree

21 files changed

+415
-554
lines changed

21 files changed

+415
-554
lines changed

Diff for: package-lock.json

+123-160
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -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",
@@ -71,7 +71,7 @@
7171
"winston": "^3.13.0",
7272
"winston-daily-rotate-file": "^4.7.1",
7373
"write-file-atomic": "^5.0.0",
74-
"ws": "^7.5.9"
74+
"ws": "^7.5.10"
7575
},
7676
"devDependencies": {
7777
"@babel/preset-typescript": "^7.24.1",

Diff for: src/app.ts

+5-13
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) {

Diff for: src/classes/Autokeys/Autokeys.ts

+79-131
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

Diff for: src/classes/Bot.ts

+15-12
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import TF2 from '@tf2autobot/tf2';
1111
import dayjs, { Dayjs } from 'dayjs';
1212
import async from 'async';
1313
import semver from 'semver';
14-
import axios, { AxiosError } from 'axios';
14+
import { AxiosError } from 'axios';
1515
import pluralize from 'pluralize';
1616
import * as timersPromises from 'timers/promises';
1717
import fs from 'fs';
@@ -44,6 +44,7 @@ import { EventEmitter } from 'events';
4444
import { Blocked } from './MyHandler/interfaces';
4545
import filterAxiosError from '@tf2autobot/filter-axios-error';
4646
import { axiosAbortSignal } from '../lib/helpers';
47+
import { apiRequest } from '../lib/apiRequest';
4748

4849
export interface SteamTokens {
4950
refreshToken: string;
@@ -312,13 +313,12 @@ export default class Bot {
312313

313314
private getLocalizationFile(attempt: 'first' | 'retry' = 'first'): Promise<void> {
314315
return new Promise((resolve, reject) => {
315-
axios({
316-
method: 'get',
316+
apiRequest<string>({
317+
method: 'GET',
317318
url: `https://raw.githubusercontent.com/SteamDatabase/GameTracking-TF2/master/tf/resource/tf_${this.options.tf2Language}.txt`,
318319
signal: axiosAbortSignal(60000)
319320
})
320-
.then(response => {
321-
const content = response.data as string;
321+
.then(content => {
322322
this.tf2.setLang(content);
323323
return resolve();
324324
})
@@ -548,26 +548,23 @@ export default class Bot {
548548
attempt: 'first' | 'retry' = 'first'
549549
): Promise<{ version: string; canUpdateRepo: boolean; updateMessage: string }> {
550550
return new Promise((resolve, reject) => {
551-
void axios({
551+
apiRequest<GithubPackageJson>({
552552
method: 'GET',
553553
url: 'https://raw.githubusercontent.com/TF2Autobot/tf2autobot/master/package.json',
554554
signal: axiosAbortSignal(60000)
555555
})
556-
.then(response => {
557-
/*eslint-disable */
558-
const data = response.data;
556+
.then(data => {
559557
return resolve({
560558
version: data.version,
561559
canUpdateRepo: data.updaterepo,
562560
updateMessage: data.updateMessage
563561
});
564-
/*eslint-enable */
565562
})
566-
.catch((err: AxiosError) => {
563+
.catch(err => {
567564
if (err instanceof AbortSignal && attempt !== 'retry') {
568565
return this.getLatestVersion('retry');
569566
}
570-
reject(filterAxiosError(err));
567+
reject(err);
571568
});
572569
});
573570
}
@@ -1729,3 +1726,9 @@ export default class Bot {
17291726
return fs.existsSync(path.resolve(__dirname, '..', '..', '.git'));
17301727
}
17311728
}
1729+
1730+
interface GithubPackageJson {
1731+
version: string;
1732+
updaterepo: boolean;
1733+
updateMessage: string;
1734+
}

0 commit comments

Comments
 (0)