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

Prepare v5.13.0 #1777

Merged
merged 14 commits into from
Jul 18, 2024
283 changes: 123 additions & 160 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -71,7 +71,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
27 changes: 15 additions & 12 deletions src/classes/Bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import TF2 from '@tf2autobot/tf2';
import dayjs, { Dayjs } from 'dayjs';
import async from 'async';
import semver from 'semver';
import axios, { AxiosError } from 'axios';
import { AxiosError } from 'axios';
import pluralize from 'pluralize';
import * as timersPromises from 'timers/promises';
import fs from 'fs';
Expand Down Expand Up @@ -44,6 +44,7 @@ import { EventEmitter } from 'events';
import { Blocked } from './MyHandler/interfaces';
import filterAxiosError from '@tf2autobot/filter-axios-error';
import { axiosAbortSignal } from '../lib/helpers';
import { apiRequest } from '../lib/apiRequest';

export interface SteamTokens {
refreshToken: string;
Expand Down Expand Up @@ -312,13 +313,12 @@ export default class Bot {

private getLocalizationFile(attempt: 'first' | 'retry' = 'first'): Promise<void> {
return new Promise((resolve, reject) => {
axios({
method: 'get',
apiRequest<string>({
method: 'GET',
url: `https://raw.githubusercontent.com/SteamDatabase/GameTracking-TF2/master/tf/resource/tf_${this.options.tf2Language}.txt`,
signal: axiosAbortSignal(60000)
})
.then(response => {
const content = response.data as string;
.then(content => {
this.tf2.setLang(content);
return resolve();
})
Expand Down Expand Up @@ -548,26 +548,23 @@ export default class Bot {
attempt: 'first' | 'retry' = 'first'
): Promise<{ version: string; canUpdateRepo: boolean; updateMessage: string }> {
return new Promise((resolve, reject) => {
void axios({
apiRequest<GithubPackageJson>({
method: 'GET',
url: 'https://raw.githubusercontent.com/TF2Autobot/tf2autobot/master/package.json',
signal: axiosAbortSignal(60000)
})
.then(response => {
/*eslint-disable */
const data = response.data;
.then(data => {
return resolve({
version: data.version,
canUpdateRepo: data.updaterepo,
updateMessage: data.updateMessage
});
/*eslint-enable */
})
.catch((err: AxiosError) => {
.catch(err => {
if (err instanceof AbortSignal && attempt !== 'retry') {
return this.getLatestVersion('retry');
}
reject(filterAxiosError(err));
reject(err);
});
});
}
Expand Down Expand Up @@ -1729,3 +1726,9 @@ export default class Bot {
return fs.existsSync(path.resolve(__dirname, '..', '..', '.git'));
}
}

interface GithubPackageJson {
version: string;
updaterepo: boolean;
updateMessage: string;
}
Loading
Loading