From 6bcd6b53f139b13dcd9bb42132b061fba76a67b0 Mon Sep 17 00:00:00 2001 From: IdiNium <47635037+idinium96@users.noreply.github.com> Date: Wed, 25 Oct 2023 01:43:19 +0800 Subject: [PATCH 01/14] =?UTF-8?q?=F0=9F=94=84=EF=B8=8F=20bump=20@tf2autobo?= =?UTF-8?q?t/steamcommunity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 39 +++++++++++++++++++++++---------------- package.json | 2 +- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0c9c4bb26..24eae42b6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "@tf2autobot/bptf-login": "^2.3.6", "@tf2autobot/filter-axios-error": "^1.5.2", "@tf2autobot/jsonlint": "^1.0.0", - "@tf2autobot/steamcommunity": "^3.47.0", + "@tf2autobot/steamcommunity": "^3.47.1", "@tf2autobot/tf2": "^1.3.5", "@tf2autobot/tf2-currencies": "^2.0.1", "@tf2autobot/tf2-schema": "^4.2.15", @@ -910,6 +910,11 @@ "resolved": "https://registry.npmjs.org/@doctormckay/steam-crypto/-/steam-crypto-1.2.0.tgz", "integrity": "sha512-lsxgLw640gEdZBOXpVIcYWcYD+V+QbtEsMPzRvjmjz2XXKc7QeEMyHL07yOFRmay+cUwO4ObKTJO0dSInEuq5g==" }, + "node_modules/@doctormckay/user-agents": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@doctormckay/user-agents/-/user-agents-1.0.0.tgz", + "integrity": "sha512-F+sL1YmebZTY2CnjoR9BXFEULpq7y8dxyLx48LZVa0BSDseXdLG/DtPISfM1iNv1XKCeiBzVNfAT/MOQ69v1Zw==" + }, "node_modules/@eslint-community/eslint-utils": { "version": "4.4.0", "resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.4.0.tgz", @@ -2359,18 +2364,19 @@ } }, "node_modules/@tf2autobot/steamcommunity": { - "version": "3.47.0", - "resolved": "https://registry.npmjs.org/@tf2autobot/steamcommunity/-/steamcommunity-3.47.0.tgz", - "integrity": "sha512-sVGBPVB2riHb/wC6+JeXFSDxJps8FDVyefwupZAZgyLyIwO7nCwKAQ5Oqez6ZrBL+eu0XVmvMDjeZArlNme+lQ==", + "version": "3.47.1", + "resolved": "https://registry.npmjs.org/@tf2autobot/steamcommunity/-/steamcommunity-3.47.1.tgz", + "integrity": "sha512-CBLKj4DzskMJERU+/oh5Eo19jyiPBG3G1CYk6FFZg7QoTdH1nbTFgy7/A15mk7SGML1nLQUnZBqtNOWL25fIlg==", "dependencies": { + "@doctormckay/user-agents": "^1.0.0", "async": "^3.2.4", "cheerio": "^1.0.0-rc.12", "image-size": "^0.8.2", - "node-bignumber": "^1.2.1", "request": "^2.88.2", + "steam-session": "^1.6.0", "steam-totp": "^2.1.2", "steamid": "^2.0.0", - "xml2js": "^0.6.0" + "xml2js": "^0.6.2" }, "engines": { "node": ">=4.0.0" @@ -10160,11 +10166,12 @@ } }, "node_modules/steam-session": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/steam-session/-/steam-session-1.4.1.tgz", - "integrity": "sha512-NGImvAoJHq7I6jtlrsrWYAtIPM3arnj8ZEcAe0M2514eBmCdJIoJdzz5xr/uLUdvuPUwreqq6n5aP4BlLxdfow==", + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/steam-session/-/steam-session-1.6.0.tgz", + "integrity": "sha512-28bTCqxP27hcVRSwMW60tVKQeosFJiNcjJYGJ3yb15IrGFWQAJqHFTRmVZIUYTTMxUiFgv+5ns9dpLXz+eA7DA==", "dependencies": { - "@doctormckay/stdlib": "^2.8.1", + "@doctormckay/stdlib": "^2.9.0", + "@doctormckay/user-agents": "^1.0.0", "debug": "^4.3.4", "kvparser": "^1.0.1", "node-bignumber": "^1.2.2", @@ -10179,9 +10186,9 @@ } }, "node_modules/steam-session/node_modules/@doctormckay/stdlib": { - "version": "2.8.1", - "resolved": "https://registry.npmjs.org/@doctormckay/stdlib/-/stdlib-2.8.1.tgz", - "integrity": "sha512-QgUfglKSOECKLnWXhqLvcNB0NTozBRcep8I9514mesEexZ/M6zwN5AvBXsXnDknwY/cme4nvAyGfaSO5P/UGXg==", + "version": "2.9.1", + "resolved": "https://registry.npmjs.org/@doctormckay/stdlib/-/stdlib-2.9.1.tgz", + "integrity": "sha512-o/gEe6iTMMLQgJytfpYehAQVTvUsEyPiOOM66ATmzRlHgXdvj9XD5SWjd+DqHZqd5zv6RCC2pO4ktqfMnFU7vA==", "dependencies": { "psl": "^1.9.0" }, @@ -11202,9 +11209,9 @@ } }, "node_modules/xml2js": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.6.0.tgz", - "integrity": "sha512-eLTh0kA8uHceqesPqSE+VvO1CDDJWMwlQfB6LuN6T8w6MaDJ8Txm8P7s5cHD0miF0V+GGTZrDQfxPZQVsur33w==", + "version": "0.6.2", + "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.6.2.tgz", + "integrity": "sha512-T4rieHaC1EXcES0Kxxj4JWgaUQHDk+qwHcYOCFHfiwKz7tOVPLq7Hjq9dM1WCMhylqMEfP7hMcOIChvotiZegA==", "dependencies": { "sax": ">=0.6.0", "xmlbuilder": "~11.0.0" diff --git a/package.json b/package.json index 33e4f6f6e..f52b22977 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "@tf2autobot/bptf-login": "^2.3.6", "@tf2autobot/filter-axios-error": "^1.5.2", "@tf2autobot/jsonlint": "^1.0.0", - "@tf2autobot/steamcommunity": "^3.47.0", + "@tf2autobot/steamcommunity": "^3.47.1", "@tf2autobot/tf2": "^1.3.5", "@tf2autobot/tf2-currencies": "^2.0.1", "@tf2autobot/tf2-schema": "^4.2.15", From 550f1d5417c59bfae69ee18847e23af8c22daf33 Mon Sep 17 00:00:00 2001 From: IdiNium <47635037+idinium96@users.noreply.github.com> Date: Wed, 25 Oct 2023 01:45:13 +0800 Subject: [PATCH 02/14] =?UTF-8?q?=F0=9F=9A=AE=20remove=20`--no-audit`=20ta?= =?UTF-8?q?g?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/classes/Commands/sub-classes/Manager.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/classes/Commands/sub-classes/Manager.ts b/src/classes/Commands/sub-classes/Manager.ts index 1b55ad7bb..1d58e3522 100644 --- a/src/classes/Commands/sub-classes/Manager.ts +++ b/src/classes/Commands/sub-classes/Manager.ts @@ -969,11 +969,7 @@ export default class ManagerCommands { ); this.bot.sendMessage(steamID, '⌛ Installing packages...'); - await exec( - `npm install${ - process.env.RUN_ON_ANDROID === 'true' ? ' --no-bin-links --force' : '' - } --no-audit` - ); + await exec(`npm install${process.env.RUN_ON_ANDROID === 'true' ? ' --no-bin-links --force' : ''}`); this.bot.sendMessage(steamID, '⌛ Compiling TypeScript codes into JavaScript...'); await exec('npm run build'); From b77307d4bde96c997b8df78ceb61a2164dfded96 Mon Sep 17 00:00:00 2001 From: IdiNium <47635037+idinium96@users.noreply.github.com> Date: Thu, 26 Oct 2023 07:00:22 +0800 Subject: [PATCH 03/14] =?UTF-8?q?=F0=9F=94=84=EF=B8=8F=20bump=20@tf2autobo?= =?UTF-8?q?t/tradeoffer-manager?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 10 +++++----- package.json | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 24eae42b6..2ad5958dd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,7 +18,7 @@ "@tf2autobot/tf2-currencies": "^2.0.1", "@tf2autobot/tf2-schema": "^4.2.15", "@tf2autobot/tf2-sku": "^2.0.4", - "@tf2autobot/tradeoffer-manager": "^2.15.0", + "@tf2autobot/tradeoffer-manager": "^2.15.1", "async": "^3.2.4", "axios": "^1.4.0", "bluebird": "^3.7.2", @@ -2432,12 +2432,12 @@ } }, "node_modules/@tf2autobot/tradeoffer-manager": { - "version": "2.15.0", - "resolved": "https://registry.npmjs.org/@tf2autobot/tradeoffer-manager/-/tradeoffer-manager-2.15.0.tgz", - "integrity": "sha512-p46OUVD7a/uHwjep3hQ57fR0+6lqkPxq2o6r17BedMkBDpVDTXBEqBRehF7lqPM0VI/yPJaHr9fGfl7mEJdjgQ==", + "version": "2.15.1", + "resolved": "https://registry.npmjs.org/@tf2autobot/tradeoffer-manager/-/tradeoffer-manager-2.15.1.tgz", + "integrity": "sha512-R6uM5TIShPY4XRJ5YU7HEVMcyLbjyMa/20EzbZIog0SUuRjKuLKdt+Lj1fvIqTkm2uH/lFPIOFAXvrnzy79y8g==", "dependencies": { "@doctormckay/stdlib": "^1.16.0", - "@tf2autobot/steamcommunity": "^3.47.0", + "@tf2autobot/steamcommunity": "^3.47.1", "async": "^3.2.4", "file-manager": "^2.0.1", "languages": "^0.1.3", diff --git a/package.json b/package.json index f52b22977..ab3adc385 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "@tf2autobot/tf2-currencies": "^2.0.1", "@tf2autobot/tf2-schema": "^4.2.15", "@tf2autobot/tf2-sku": "^2.0.4", - "@tf2autobot/tradeoffer-manager": "^2.15.0", + "@tf2autobot/tradeoffer-manager": "^2.15.1", "async": "^3.2.4", "axios": "^1.4.0", "bluebird": "^3.7.2", From 1ef1b01b2487d014f4fa4e4b0039f9989213b047 Mon Sep 17 00:00:00 2001 From: IdiNium <47635037+idinium96@users.noreply.github.com> Date: Fri, 27 Oct 2023 09:04:53 +0800 Subject: [PATCH 04/14] =?UTF-8?q?=E2=9C=A8=20add=20`rewriteFile.count`=20o?= =?UTF-8?q?ption?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/classes/Options.ts | 8 ++++++++ src/classes/Pricelist.ts | 9 ++++++++- src/schemas/options-json/options.ts | 14 +++++++++++++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/classes/Options.ts b/src/classes/Options.ts index 5b2744f22..112832d2e 100644 --- a/src/classes/Options.ts +++ b/src/classes/Options.ts @@ -129,6 +129,9 @@ export const DEFAULTS: JsonOptions = { }, priceAge: { maxInSeconds: 28800 + }, + rewriteFile: { + count: 1 } }, @@ -1284,6 +1287,7 @@ interface Pricelist { autoAddInvalidUnusual?: OnlyEnable; autoAddPaintedItems?: OnlyEnable; priceAge?: PriceAge; + rewriteFile?: RewriteFile; } interface PartialPriceUpdate extends OnlyEnable { @@ -1295,6 +1299,10 @@ interface PriceAge { maxInSeconds?: number; } +interface RewriteFile { + count: number; +} + // ------------ Bypass ------------ interface Bypass { diff --git a/src/classes/Pricelist.ts b/src/classes/Pricelist.ts index f446c6b27..702d5be0f 100644 --- a/src/classes/Pricelist.ts +++ b/src/classes/Pricelist.ts @@ -230,6 +230,8 @@ export default class Pricelist extends EventEmitter { autoResetPartialPriceBulk: string[] = []; + private priceChangeCounter = 0; + assetidInPricelist: AssetidInPricelist = {}; checkAssetidInPricelistInterval: NodeJS.Timeout; @@ -1337,7 +1339,12 @@ export default class Pricelist extends EventEmitter { private priceChanged(priceKey: string | number, entry: Entry): void { this.emit('price', priceKey, entry); - this.emit('pricelist', this.prices); + + if (++this.priceChangeCounter % 100 === 0) { + this.emit('pricelist', this.prices); + + this.priceChangeCounter = 0; + } } private get getOld(): PricesObject { diff --git a/src/schemas/options-json/options.ts b/src/schemas/options-json/options.ts index a5afd9c7e..20ab7345e 100644 --- a/src/schemas/options-json/options.ts +++ b/src/schemas/options-json/options.ts @@ -693,6 +693,17 @@ export const optionsSchema: jsonschema.Schema = { }, required: ['maxInSeconds'], additionalProperties: false + }, + rewriteFile: { + type: 'object', + properties: { + count: { + type: 'integer', + minimum: 1 + } + }, + required: ['count'], + additionalProperties: false } }, required: [ @@ -703,7 +714,8 @@ export const optionsSchema: jsonschema.Schema = { 'autoAddInvalidItems', 'autoAddInvalidUnusual', 'autoAddPaintedItems', - 'priceAge' + 'priceAge', + 'rewriteFile' ], additionalProperties: false }, From fd77438175b85dbdca86327032280eeffb8a987d Mon Sep 17 00:00:00 2001 From: IdiNium <47635037+idinium96@users.noreply.github.com> Date: Fri, 27 Oct 2023 09:19:50 +0800 Subject: [PATCH 05/14] =?UTF-8?q?=F0=9F=94=A8=20update=20to=20variable=20v?= =?UTF-8?q?alue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/classes/Pricelist.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/classes/Pricelist.ts b/src/classes/Pricelist.ts index 702d5be0f..cf6185523 100644 --- a/src/classes/Pricelist.ts +++ b/src/classes/Pricelist.ts @@ -1340,7 +1340,8 @@ export default class Pricelist extends EventEmitter { private priceChanged(priceKey: string | number, entry: Entry): void { this.emit('price', priceKey, entry); - if (++this.priceChangeCounter % 100 === 0) { + if (++this.priceChangeCounter % this.options.pricelist.rewriteFile.count === 0) { + // reference: https://github.com/Hhanuska/tf2autobot/commit/54c408936cc923d56d525f01726c042a84e1ec75 this.emit('pricelist', this.prices); this.priceChangeCounter = 0; From 4101d0f1e9acfd7ebf255367a03b9c0d99ba1964 Mon Sep 17 00:00:00 2001 From: Purple <87976511+purplebarber@users.noreply.github.com> Date: Fri, 27 Oct 2023 14:02:48 +0800 Subject: [PATCH 06/14] Fix sell commands not working for generic unusuals Add findByPartialSku() for Inventory.ts which is called when an unusual object has no effect. Is called when searching for generic unusuals in other player's inventory. --- src/classes/Carts/UserCart.ts | 42 +++++++++++++++++++++++++++++++---- src/classes/Inventory.ts | 39 ++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 4 deletions(-) diff --git a/src/classes/Carts/UserCart.ts b/src/classes/Carts/UserCart.ts index 1adadb43e..aba9f8722 100644 --- a/src/classes/Carts/UserCart.ts +++ b/src/classes/Carts/UserCart.ts @@ -514,15 +514,34 @@ export default class UserCart extends Cart { }; // Add their items - for (const sku in this.their) { + for (let sku in this.their) { if (!Object.prototype.hasOwnProperty.call(this.their, sku)) { continue; } - let alteredMessage: string; + let findByPartialSku = false; + let elevatedStrange = false; + const item_object = SKU.fromString(sku); + if (item_object.quality == 5 && !item_object.effect) { + log.debug('Generic Unusual in their cart, finding by partial sku'); + findByPartialSku = true; + if (item_object.quality2 == 11) { + elevatedStrange = true; + } + } + let theirAssetids: string[]; let amount = this.getTheirCount(sku); - const theirAssetids = theirInventory.findBySKU(sku, true); + if (findByPartialSku) { + theirAssetids = theirInventory.findByPartialSku(sku, true, elevatedStrange); + if (theirAssetids.length > 0) { + sku = theirInventory.findByAssetid(theirAssetids[0]); + } + } else { + theirAssetids = theirInventory.findBySKU(sku, true); + } + + let alteredMessage: string; const theirAssetidsCount = theirAssetids.length; if (amount > theirAssetidsCount) { @@ -745,8 +764,23 @@ export default class UserCart extends Cart { continue; } + const item_object = SKU.fromString(sku); + let findByPartialSku = false; + let elevatedStrange = false; + if (item_object.quality == 5 && !item_object.effect) { + findByPartialSku = true; + if (item_object.quality2 == 11) { + elevatedStrange = true; + } + } + + let assetids: string[]; const amount = this.their[sku]; - let assetids = theirInventory.findBySKU(sku, true); + if (findByPartialSku) { + assetids = theirInventory.findByPartialSku(sku, true, elevatedStrange); + } else { + assetids = theirInventory.findBySKU(sku, true); + } const addToDupeCheckList = this.bot.pricelist diff --git a/src/classes/Inventory.ts b/src/classes/Inventory.ts index 166bdfe03..5ccb62d10 100644 --- a/src/classes/Inventory.ts +++ b/src/classes/Inventory.ts @@ -6,6 +6,7 @@ import { HighValue } from './Options'; import Bot from './Bot'; import { noiseMakers, spellsData, killstreakersData, sheensData } from '../lib/data'; import Pricelist from './Pricelist'; +import log from '../lib/logger'; export default class Inventory { private readonly steamID: SteamID; @@ -195,6 +196,44 @@ export default class Inventory { return nonTradable.concat(tradable).slice(0); } + findByPartialSku(partialSku: string, tradableOnly = true, elevatedStrange = false): string[] { + const matchingSkus: string[] = []; + + if (elevatedStrange) { + partialSku = partialSku.replace(';strange', ''); + + for (const sku in this.tradable) { + if (sku.startsWith(partialSku) && sku.includes(';strange')) { + matchingSkus.push(...this.tradable[sku].map(item => item?.id)); + } + } + + if (!tradableOnly) { + for (const sku in this.nonTradable) { + if (sku.startsWith(partialSku) && sku.includes(';strange')) { + matchingSkus.push(...this.nonTradable[sku].map(item => item?.id)); + } + } + } + + } else { + for (const sku in this.tradable) { + if (sku.startsWith(partialSku)) { + matchingSkus.push(...this.tradable[sku].map(item => item?.id)); + } + } + + if (!tradableOnly) { + for (const sku in this.nonTradable) { + if (sku.startsWith(partialSku)) { + matchingSkus.push(...this.nonTradable[sku].map(item => item?.id)); + } + } + } + } + return matchingSkus.slice(0); + } + getAmount({ priceKey, includeNonNormalized, From 2e766cb2f1c812eb5a5816377d3494d10c0dd8fe Mon Sep 17 00:00:00 2001 From: IdiNium <47635037+idinium96@users.noreply.github.com> Date: Fri, 27 Oct 2023 14:44:39 +0800 Subject: [PATCH 07/14] =?UTF-8?q?=F0=9F=94=A8=20change=20logic=20`=3F=3F`?= =?UTF-8?q?=20->=20`||`,=20refactor=20codes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/classes/MyHandler/MyHandler.ts | 2 +- src/classes/Pricelist.ts | 11 +++++++++-- src/lib/DiscordWebhook/pricelistUpdate.ts | 8 +++++--- src/lib/DiscordWebhook/pricelistUpdateFailed.ts | 8 +++++--- src/lib/DiscordWebhook/sendAdminMessage.ts | 4 ++-- src/lib/DiscordWebhook/sendAlert.ts | 4 ++-- src/lib/DiscordWebhook/sendOfferReview.ts | 4 ++-- src/lib/DiscordWebhook/sendPartnerMessage.ts | 4 ++-- src/lib/DiscordWebhook/sendStats.ts | 6 +++--- src/lib/DiscordWebhook/sendTf2DisplayNotification.ts | 4 ++-- src/lib/DiscordWebhook/sendTf2ItemBroadcast.ts | 4 ++-- src/lib/DiscordWebhook/sendTf2SystemMessage.ts | 4 ++-- src/lib/DiscordWebhook/sendTradeDeclined.ts | 4 ++-- src/lib/DiscordWebhook/sendTradeSummary.ts | 4 ++-- 14 files changed, 41 insertions(+), 30 deletions(-) diff --git a/src/classes/MyHandler/MyHandler.ts b/src/classes/MyHandler/MyHandler.ts index 21ab57e63..54180d8e6 100644 --- a/src/classes/MyHandler/MyHandler.ts +++ b/src/classes/MyHandler/MyHandler.ts @@ -2760,7 +2760,7 @@ interface OnNewTradeOffer { meta?: Meta; } -interface BotInfo { +export interface BotInfo { name: string; avatarURL: string; steamID: SteamID; diff --git a/src/classes/Pricelist.ts b/src/classes/Pricelist.ts index cf6185523..634f42e2a 100644 --- a/src/classes/Pricelist.ts +++ b/src/classes/Pricelist.ts @@ -1143,7 +1143,13 @@ export default class Pricelist extends EventEmitter { }); if (isDwEnabled && dw.showFailedToUpdate) { - sendFailedPriceUpdate(data, err as Error, this.isUseCustomPricer, this.options); + sendFailedPriceUpdate( + data, + err as Error, + this.isUseCustomPricer, + this.options, + this.bot.handler.getBotInfo + ); } return; @@ -1330,7 +1336,8 @@ export default class Pricelist extends EventEmitter { match.sku === '5021;6' ? undefined : keyPrice, buyChangesValue, sellChangesValue, - this.isUseCustomPricer + this.isUseCustomPricer, + this.bot.handler.getBotInfo ); } } diff --git a/src/lib/DiscordWebhook/pricelistUpdate.ts b/src/lib/DiscordWebhook/pricelistUpdate.ts index d3a747ff8..b3f7d58af 100644 --- a/src/lib/DiscordWebhook/pricelistUpdate.ts +++ b/src/lib/DiscordWebhook/pricelistUpdate.ts @@ -9,6 +9,7 @@ import log from '../logger'; import { BuyAndSell } from '../../classes/Pricelist'; import Options from '../../classes/Options'; import { WebhookError } from './utils'; +import { BotInfo } from '../../classes/MyHandler/MyHandler'; const australiumImageURL: { [defindex: number]: string } = { // Australium Ambassador @@ -1789,7 +1790,8 @@ export default function sendWebHookPriceUpdateV1( conversion: number, buyChangesValue: number | null, sellChangesValue: number | null, - isCustomPricer: boolean + isCustomPricer: boolean, + botInfo: BotInfo ): void { const baseItemData = schema.getItemBySKU(sku); const item = SKU.fromString(sku); @@ -1884,8 +1886,8 @@ export default function sendWebHookPriceUpdateV1( const opt = options.discordWebhook; const priceUpdate: Webhook = { - username: opt.displayName, - avatar_url: opt.avatarURL, + username: opt.displayName || botInfo.name, + avatar_url: opt.avatarURL || botInfo.avatarURL, content: '', embeds: [ { diff --git a/src/lib/DiscordWebhook/pricelistUpdateFailed.ts b/src/lib/DiscordWebhook/pricelistUpdateFailed.ts index 2bf395b17..efb179572 100644 --- a/src/lib/DiscordWebhook/pricelistUpdateFailed.ts +++ b/src/lib/DiscordWebhook/pricelistUpdateFailed.ts @@ -5,17 +5,19 @@ import { GetItemPriceResponse } from '../../classes/IPricer'; import * as timersPromises from 'timers/promises'; import { UnknownDictionary } from '../../types/common'; import Options from '../../classes/Options'; +import { BotInfo } from '../../classes/MyHandler/MyHandler'; export default function sendFailedPriceUpdate( data: GetItemPriceResponse, err: Error, isCustomPricer: boolean, - options: Options + options: Options, + botInfo: BotInfo ): void { const opt = options.discordWebhook; const priceUpdate: Webhook = { - username: opt.displayName, - avatar_url: opt.avatarURL, + username: opt.displayName || botInfo.name, + avatar_url: opt.avatarURL || botInfo.avatarURL, content: '', embeds: [ { diff --git a/src/lib/DiscordWebhook/sendAdminMessage.ts b/src/lib/DiscordWebhook/sendAdminMessage.ts index 990268d10..f1257d021 100644 --- a/src/lib/DiscordWebhook/sendAdminMessage.ts +++ b/src/lib/DiscordWebhook/sendAdminMessage.ts @@ -15,8 +15,8 @@ export default function sendAdminMessage( const botInfo = bot.handler.getBotInfo; const discordAdminMsg: Webhook = { - username: opt.displayName ? opt.displayName : botInfo.name, - avatar_url: opt.avatarURL ? opt.avatarURL : botInfo.avatarURL, + username: opt.displayName || botInfo.name, + avatar_url: opt.avatarURL || botInfo.avatarURL, content: `Message sent!`, embeds: [ { diff --git a/src/lib/DiscordWebhook/sendAlert.ts b/src/lib/DiscordWebhook/sendAlert.ts index a282c9a9e..89f5fd2d7 100644 --- a/src/lib/DiscordWebhook/sendAlert.ts +++ b/src/lib/DiscordWebhook/sendAlert.ts @@ -239,8 +239,8 @@ export default function sendAlert( const optDW = bot.options.discordWebhook; const sendAlertWebhook: Webhook = { - username: optDW.displayName ? optDW.displayName : botInfo.name, - avatar_url: optDW.avatarURL ? optDW.avatarURL : botInfo.avatarURL, + username: optDW.displayName || botInfo.name, + avatar_url: optDW.avatarURL || botInfo.avatarURL, content: ([ 'highValue', diff --git a/src/lib/DiscordWebhook/sendOfferReview.ts b/src/lib/DiscordWebhook/sendOfferReview.ts index 75bcb73b5..f9197142e 100644 --- a/src/lib/DiscordWebhook/sendOfferReview.ts +++ b/src/lib/DiscordWebhook/sendOfferReview.ts @@ -101,8 +101,8 @@ export default function sendOfferReview( const isShowInventory = opt.offerReview.misc.showInventory; const webhookReview: Webhook = { - username: opt.displayName ? opt.displayName : botInfo.name, - avatar_url: opt.avatarURL ? opt.avatarURL : botInfo.avatarURL, + username: opt.displayName || botInfo.name, + avatar_url: opt.avatarURL || botInfo.avatarURL, content: mentionOwner, embeds: [ { diff --git a/src/lib/DiscordWebhook/sendPartnerMessage.ts b/src/lib/DiscordWebhook/sendPartnerMessage.ts index f8a0ef6f2..1ab576d0c 100644 --- a/src/lib/DiscordWebhook/sendPartnerMessage.ts +++ b/src/lib/DiscordWebhook/sendPartnerMessage.ts @@ -15,8 +15,8 @@ export default function sendPartnerMessage( const botInfo = bot.handler.getBotInfo; const discordPartnerMsg: Webhook = { - username: opt.displayName ? opt.displayName : botInfo.name, - avatar_url: opt.avatarURL ? opt.avatarURL : botInfo.avatarURL, + username: opt.displayName || botInfo.name, + avatar_url: opt.avatarURL || botInfo.avatarURL, content: `${ opt.messages.isMention && opt.ownerID.length > 0 ? opt.ownerID.map(id => `<@!${id}>`).join(', ') + `, ` : '' }new message! - ${steamID}`, diff --git a/src/lib/DiscordWebhook/sendStats.ts b/src/lib/DiscordWebhook/sendStats.ts index 0b85b45f2..3e4c829e8 100644 --- a/src/lib/DiscordWebhook/sendStats.ts +++ b/src/lib/DiscordWebhook/sendStats.ts @@ -37,14 +37,14 @@ export default async function sendStats(bot: Bot, forceSend = false, steamID?: S : ''; const discordStats: Webhook = { - username: optDW.displayName ? optDW.displayName : botInfo.name, - avatar_url: optDW.avatarURL ? optDW.avatarURL : botInfo.avatarURL, + username: optDW.displayName || botInfo.name, + avatar_url: optDW.avatarURL || botInfo.avatarURL, content: '', embeds: [ { footer: { text: `${timeNow(bot.options).time} • v${process.env.BOT_VERSION}`, - icon_url: optDW.avatarURL ? optDW.avatarURL : botInfo.avatarURL + icon_url: optDW.avatarURL || botInfo.avatarURL }, title: '📊 Statistics 📊', description: diff --git a/src/lib/DiscordWebhook/sendTf2DisplayNotification.ts b/src/lib/DiscordWebhook/sendTf2DisplayNotification.ts index b584a4052..84dad9c86 100644 --- a/src/lib/DiscordWebhook/sendTf2DisplayNotification.ts +++ b/src/lib/DiscordWebhook/sendTf2DisplayNotification.ts @@ -9,8 +9,8 @@ export default function sendTf2DisplayNotification(bot: Bot, title: string, body const botInfo = bot.handler.getBotInfo; const webhook: Webhook = { - username: opt.displayName ? opt.displayName : botInfo.name, - avatar_url: opt.avatarURL ? opt.avatarURL : botInfo.avatarURL, + username: opt.displayName || botInfo.name, + avatar_url: opt.avatarURL || botInfo.avatarURL, content: opt.sendTf2Events.displayNotification.custom.content || '', embeds: [ { diff --git a/src/lib/DiscordWebhook/sendTf2ItemBroadcast.ts b/src/lib/DiscordWebhook/sendTf2ItemBroadcast.ts index c21a2e342..23a19b178 100644 --- a/src/lib/DiscordWebhook/sendTf2ItemBroadcast.ts +++ b/src/lib/DiscordWebhook/sendTf2ItemBroadcast.ts @@ -15,8 +15,8 @@ export default function sendTf2ItemBroadcast( const botInfo = bot.handler.getBotInfo; const webhook: Webhook = { - username: opt.displayName ? opt.displayName : botInfo.name, - avatar_url: opt.avatarURL ? opt.avatarURL : botInfo.avatarURL, + username: opt.displayName || botInfo.name, + avatar_url: opt.avatarURL || botInfo.avatarURL, content: opt.sendTf2Events.itemBroadcast.custom.content || '', embeds: [ { diff --git a/src/lib/DiscordWebhook/sendTf2SystemMessage.ts b/src/lib/DiscordWebhook/sendTf2SystemMessage.ts index 13f6de299..dbc51a552 100644 --- a/src/lib/DiscordWebhook/sendTf2SystemMessage.ts +++ b/src/lib/DiscordWebhook/sendTf2SystemMessage.ts @@ -9,8 +9,8 @@ export default function sendTf2SystemMessage(bot: Bot, message: string): void { const botInfo = bot.handler.getBotInfo; const webhook: Webhook = { - username: opt.displayName ? opt.displayName : botInfo.name, - avatar_url: opt.avatarURL ? opt.avatarURL : botInfo.avatarURL, + username: opt.displayName || botInfo.name, + avatar_url: opt.avatarURL || botInfo.avatarURL, content: opt.sendTf2Events.systemMessage.custom.content || '', embeds: [ { diff --git a/src/lib/DiscordWebhook/sendTradeDeclined.ts b/src/lib/DiscordWebhook/sendTradeDeclined.ts index 4dda6715f..e1c07e501 100644 --- a/src/lib/DiscordWebhook/sendTradeDeclined.ts +++ b/src/lib/DiscordWebhook/sendTradeDeclined.ts @@ -70,8 +70,8 @@ export default async function sendTradeDeclined( const declinedDescription = declined.reasonDescription; const declinedTradeSummary: Webhook = { - username: optDW.displayName ?? botInfo.name, - avatar_url: optDW.avatarURL ?? optDW.avatarURL, + username: optDW.displayName || botInfo.name, + avatar_url: optDW.avatarURL || optDW.avatarURL, content: '', embeds: [ { diff --git a/src/lib/DiscordWebhook/sendTradeSummary.ts b/src/lib/DiscordWebhook/sendTradeSummary.ts index 95198fae8..c98759c9e 100644 --- a/src/lib/DiscordWebhook/sendTradeSummary.ts +++ b/src/lib/DiscordWebhook/sendTradeSummary.ts @@ -121,8 +121,8 @@ export default async function sendTradeSummary( const isCustomPricer = bot.pricelist.isUseCustomPricer; const acceptedTradeSummary: Webhook = { - username: optDW.displayName ? optDW.displayName : botInfo.name, - avatar_url: optDW.avatarURL ? optDW.avatarURL : botInfo.avatarURL, + username: optDW.displayName || botInfo.name, + avatar_url: optDW.avatarURL || botInfo.avatarURL, content: mentionOwner, embeds: [ { From 687c8a1ccad782834cd6a8f77a8713d7599feaf6 Mon Sep 17 00:00:00 2001 From: IdiNium <47635037+idinium96@users.noreply.github.com> Date: Fri, 27 Oct 2023 14:45:56 +0800 Subject: [PATCH 08/14] =?UTF-8?q?=F0=9F=94=84=EF=B8=8F=20move=20DiscordWeb?= =?UTF-8?q?hook=20to=20classes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app.ts | 2 +- src/classes/Autokeys/Autokeys.ts | 2 +- src/classes/Bot.ts | 2 +- src/classes/Carts/Cart.ts | 2 +- src/classes/Carts/CartQueue.ts | 2 +- src/classes/Commands/sub-classes/Message.ts | 2 +- src/classes/Commands/sub-classes/Status.ts | 2 +- src/{lib => classes}/DiscordWebhook/export.ts | 0 src/{lib => classes}/DiscordWebhook/interfaces.ts | 0 src/{lib => classes}/DiscordWebhook/pricelistUpdate.ts | 8 ++++---- .../DiscordWebhook/pricelistUpdateFailed.ts | 8 ++++---- .../DiscordWebhook/sendAdminMessage.ts | 4 ++-- src/{lib => classes}/DiscordWebhook/sendAlert.ts | 4 ++-- src/{lib => classes}/DiscordWebhook/sendOfferReview.ts | 10 +++++----- .../DiscordWebhook/sendPartnerMessage.ts | 4 ++-- src/{lib => classes}/DiscordWebhook/sendStats.ts | 6 +++--- .../DiscordWebhook/sendTf2DisplayNotification.ts | 6 +++--- .../DiscordWebhook/sendTf2ItemBroadcast.ts | 6 +++--- .../DiscordWebhook/sendTf2SystemMessage.ts | 6 +++--- .../DiscordWebhook/sendTradeDeclined.ts | 8 ++++---- .../DiscordWebhook/sendTradeSummary.ts | 8 ++++---- src/{lib => classes}/DiscordWebhook/utils.ts | 4 ++-- src/classes/MyHandler/MyHandler.ts | 8 ++++---- .../MyHandler/offer/accepted/processAccepted.ts | 2 +- src/classes/MyHandler/offer/accepted/updateListings.ts | 2 +- src/classes/MyHandler/offer/processDeclined.ts | 2 +- src/classes/MyHandler/offer/review/send-review.ts | 2 +- src/classes/Pricelist.ts | 2 +- src/classes/Trades.ts | 2 +- 29 files changed, 58 insertions(+), 58 deletions(-) rename src/{lib => classes}/DiscordWebhook/export.ts (100%) rename src/{lib => classes}/DiscordWebhook/interfaces.ts (100%) rename src/{lib => classes}/DiscordWebhook/pricelistUpdate.ts (99%) rename src/{lib => classes}/DiscordWebhook/pricelistUpdateFailed.ts (93%) rename src/{lib => classes}/DiscordWebhook/sendAdminMessage.ts (95%) rename src/{lib => classes}/DiscordWebhook/sendAlert.ts (99%) rename src/{lib => classes}/DiscordWebhook/sendOfferReview.ts (97%) rename src/{lib => classes}/DiscordWebhook/sendPartnerMessage.ts (96%) rename src/{lib => classes}/DiscordWebhook/sendStats.ts (98%) rename src/{lib => classes}/DiscordWebhook/sendTf2DisplayNotification.ts (92%) rename src/{lib => classes}/DiscordWebhook/sendTf2ItemBroadcast.ts (93%) rename src/{lib => classes}/DiscordWebhook/sendTf2SystemMessage.ts (91%) rename src/{lib => classes}/DiscordWebhook/sendTradeDeclined.ts (98%) rename src/{lib => classes}/DiscordWebhook/sendTradeSummary.ts (98%) rename src/{lib => classes}/DiscordWebhook/utils.ts (97%) diff --git a/src/app.ts b/src/app.ts index 0337d82c3..ced1233ba 100644 --- a/src/app.ts +++ b/src/app.ts @@ -67,7 +67,7 @@ const botManager = new BotManager( import ON_DEATH from 'death'; import * as inspect from 'util'; -import { Webhook } from './lib/DiscordWebhook/interfaces'; +import { Webhook } from './classes/DiscordWebhook/interfaces'; import axios, { AxiosError } from 'axios'; import { uptime } from './lib/tools/time'; import filterAxiosError from '@tf2autobot/filter-axios-error'; diff --git a/src/classes/Autokeys/Autokeys.ts b/src/classes/Autokeys/Autokeys.ts index 063162bda..60f7b2595 100644 --- a/src/classes/Autokeys/Autokeys.ts +++ b/src/classes/Autokeys/Autokeys.ts @@ -4,7 +4,7 @@ import Bot from '../Bot'; import { EntryData, KeyPrices, PricelistChangedSource } from '../Pricelist'; import log from '../../lib/logger'; import { currPure } from '../../lib/tools/pure'; -import sendAlert from '../../lib/DiscordWebhook/sendAlert'; +import sendAlert from '../DiscordWebhook/sendAlert'; export interface OverallStatus { isBuyingKeys: boolean; diff --git a/src/classes/Bot.ts b/src/classes/Bot.ts index bc5f4394c..3474bfe3c 100644 --- a/src/classes/Bot.ts +++ b/src/classes/Bot.ts @@ -39,7 +39,7 @@ import Groups from './Groups'; import log from '../lib/logger'; import Bans, { IsBanned } from '../lib/bans'; -import { sendStats } from '../lib/DiscordWebhook/export'; +import { sendStats } from './DiscordWebhook/export'; import Options from './Options'; import IPricer from './IPricer'; diff --git a/src/classes/Carts/Cart.ts b/src/classes/Carts/Cart.ts index da513f359..343eb95bd 100644 --- a/src/classes/Carts/Cart.ts +++ b/src/classes/Carts/Cart.ts @@ -9,7 +9,7 @@ import Bot from '../Bot'; import Pricelist from '../Pricelist'; import { BPTFGetUserInfo } from '../MyHandler/interfaces'; import log from '../../lib/logger'; -import { sendAlert } from '../../lib/DiscordWebhook/export'; +import { sendAlert } from '../DiscordWebhook/export'; import filterAxiosError from '@tf2autobot/filter-axios-error'; /** diff --git a/src/classes/Carts/CartQueue.ts b/src/classes/Carts/CartQueue.ts index f3abfdb88..00cc10800 100644 --- a/src/classes/Carts/CartQueue.ts +++ b/src/classes/Carts/CartQueue.ts @@ -5,7 +5,7 @@ import pluralize from 'pluralize'; import Cart from './Cart'; import Bot from '../Bot'; import log from '../../lib/logger'; -import { sendAlert } from '../../lib/DiscordWebhook/export'; +import { sendAlert } from '../DiscordWebhook/export'; import { uptime } from '../../lib/tools/export'; import { isBptfBanned } from '../../lib/bans'; diff --git a/src/classes/Commands/sub-classes/Message.ts b/src/classes/Commands/sub-classes/Message.ts index 2f0b1bf13..e7ada80b8 100644 --- a/src/classes/Commands/sub-classes/Message.ts +++ b/src/classes/Commands/sub-classes/Message.ts @@ -3,7 +3,7 @@ import Bot from '../../Bot'; import CommandParser from '../../CommandParser'; import log from '../../../lib/logger'; import { generateLinks, timeNow } from '../../../lib/tools/export'; -import { sendPartnerMessage, sendAdminMessage } from '../../../lib/DiscordWebhook/export'; +import { sendPartnerMessage, sendAdminMessage } from '../../DiscordWebhook/export'; export default class MessageCommand { constructor(private readonly bot: Bot) { diff --git a/src/classes/Commands/sub-classes/Status.ts b/src/classes/Commands/sub-classes/Status.ts index c93e6683d..4457dab52 100644 --- a/src/classes/Commands/sub-classes/Status.ts +++ b/src/classes/Commands/sub-classes/Status.ts @@ -6,7 +6,7 @@ import * as timersPromises from 'timers/promises'; import Bot from '../../Bot'; import CommandParser from '../../CommandParser'; import { stats, profit, itemStats, testPriceKey } from '../../../lib/tools/export'; -import { sendStats } from '../../../lib/DiscordWebhook/export'; +import { sendStats } from '../../DiscordWebhook/export'; import loadPollData, { deletePollData } from '../../../lib/tools/polldata'; import SteamTradeOfferManager from '@tf2autobot/tradeoffer-manager'; diff --git a/src/lib/DiscordWebhook/export.ts b/src/classes/DiscordWebhook/export.ts similarity index 100% rename from src/lib/DiscordWebhook/export.ts rename to src/classes/DiscordWebhook/export.ts diff --git a/src/lib/DiscordWebhook/interfaces.ts b/src/classes/DiscordWebhook/interfaces.ts similarity index 100% rename from src/lib/DiscordWebhook/interfaces.ts rename to src/classes/DiscordWebhook/interfaces.ts diff --git a/src/lib/DiscordWebhook/pricelistUpdate.ts b/src/classes/DiscordWebhook/pricelistUpdate.ts similarity index 99% rename from src/lib/DiscordWebhook/pricelistUpdate.ts rename to src/classes/DiscordWebhook/pricelistUpdate.ts index b3f7d58af..ee0903821 100644 --- a/src/lib/DiscordWebhook/pricelistUpdate.ts +++ b/src/classes/DiscordWebhook/pricelistUpdate.ts @@ -5,11 +5,11 @@ import * as timersPromises from 'timers/promises'; import { UnknownDictionary } from '../../types/common'; import { Webhook, sendWebhook } from './export'; -import log from '../logger'; -import { BuyAndSell } from '../../classes/Pricelist'; -import Options from '../../classes/Options'; +import log from '../../lib/logger'; +import { BuyAndSell } from '../Pricelist'; +import Options from '../Options'; import { WebhookError } from './utils'; -import { BotInfo } from '../../classes/MyHandler/MyHandler'; +import { BotInfo } from '../MyHandler/MyHandler'; const australiumImageURL: { [defindex: number]: string } = { // Australium Ambassador diff --git a/src/lib/DiscordWebhook/pricelistUpdateFailed.ts b/src/classes/DiscordWebhook/pricelistUpdateFailed.ts similarity index 93% rename from src/lib/DiscordWebhook/pricelistUpdateFailed.ts rename to src/classes/DiscordWebhook/pricelistUpdateFailed.ts index efb179572..b3ef66b7b 100644 --- a/src/lib/DiscordWebhook/pricelistUpdateFailed.ts +++ b/src/classes/DiscordWebhook/pricelistUpdateFailed.ts @@ -1,11 +1,11 @@ import { sendWebhook } from './utils'; import { Webhook } from './interfaces'; -import log from '../logger'; -import { GetItemPriceResponse } from '../../classes/IPricer'; +import log from '../../lib/logger'; +import { GetItemPriceResponse } from '../IPricer'; import * as timersPromises from 'timers/promises'; import { UnknownDictionary } from '../../types/common'; -import Options from '../../classes/Options'; -import { BotInfo } from '../../classes/MyHandler/MyHandler'; +import Options from '../Options'; +import { BotInfo } from '../MyHandler/MyHandler'; export default function sendFailedPriceUpdate( data: GetItemPriceResponse, diff --git a/src/lib/DiscordWebhook/sendAdminMessage.ts b/src/classes/DiscordWebhook/sendAdminMessage.ts similarity index 95% rename from src/lib/DiscordWebhook/sendAdminMessage.ts rename to src/classes/DiscordWebhook/sendAdminMessage.ts index f1257d021..5ce3c5d3c 100644 --- a/src/lib/DiscordWebhook/sendAdminMessage.ts +++ b/src/classes/DiscordWebhook/sendAdminMessage.ts @@ -1,7 +1,7 @@ import { quickLinks, sendWebhook } from './utils'; import { Webhook } from './interfaces'; -import log from '../logger'; -import Bot from '../../classes/Bot'; +import log from '../../lib/logger'; +import Bot from '../Bot'; export default function sendAdminMessage( steamID: string, diff --git a/src/lib/DiscordWebhook/sendAlert.ts b/src/classes/DiscordWebhook/sendAlert.ts similarity index 99% rename from src/lib/DiscordWebhook/sendAlert.ts rename to src/classes/DiscordWebhook/sendAlert.ts index 89f5fd2d7..b6518712f 100644 --- a/src/lib/DiscordWebhook/sendAlert.ts +++ b/src/classes/DiscordWebhook/sendAlert.ts @@ -1,8 +1,8 @@ import TradeOfferManager, { CustomError } from '@tf2autobot/tradeoffer-manager'; import { sendWebhook, WebhookError } from './utils'; import { Webhook } from './interfaces'; -import { timeNow, uptime } from '../tools/time'; -import Bot from '../../classes/Bot'; +import { timeNow, uptime } from '../../lib/tools/time'; +import Bot from '../Bot'; import * as timersPromises from 'timers/promises'; type AlertType = diff --git a/src/lib/DiscordWebhook/sendOfferReview.ts b/src/classes/DiscordWebhook/sendOfferReview.ts similarity index 97% rename from src/lib/DiscordWebhook/sendOfferReview.ts rename to src/classes/DiscordWebhook/sendOfferReview.ts index f9197142e..a512bdd27 100644 --- a/src/lib/DiscordWebhook/sendOfferReview.ts +++ b/src/classes/DiscordWebhook/sendOfferReview.ts @@ -1,12 +1,12 @@ import { TradeOffer } from '@tf2autobot/tradeoffer-manager'; import { quickLinks, sendWebhook } from './utils'; import { Webhook } from './interfaces'; -import log from '../logger'; -import { pure, summarizeToChat, listItems, replace, ValueDiff } from '../tools/export'; +import log from '../../lib/logger'; +import { pure, summarizeToChat, listItems, replace, ValueDiff } from '../../lib/tools/export'; -import Bot from '../../classes/Bot'; -import { KeyPrices } from '../../classes/Pricelist'; -import { sendToAdmin } from '../../classes/MyHandler/offer/review/send-review'; +import Bot from '../Bot'; +import { KeyPrices } from '../Pricelist'; +import { sendToAdmin } from '../MyHandler/offer/review/send-review'; export default function sendOfferReview( offer: TradeOffer, diff --git a/src/lib/DiscordWebhook/sendPartnerMessage.ts b/src/classes/DiscordWebhook/sendPartnerMessage.ts similarity index 96% rename from src/lib/DiscordWebhook/sendPartnerMessage.ts rename to src/classes/DiscordWebhook/sendPartnerMessage.ts index 1ab576d0c..742609168 100644 --- a/src/lib/DiscordWebhook/sendPartnerMessage.ts +++ b/src/classes/DiscordWebhook/sendPartnerMessage.ts @@ -1,7 +1,7 @@ import { quickLinks, sendWebhook } from './utils'; import { Webhook } from './interfaces'; -import log from '../logger'; -import Bot from '../../classes/Bot'; +import log from '../../lib/logger'; +import Bot from '../Bot'; export default function sendPartnerMessage( steamID: string, diff --git a/src/lib/DiscordWebhook/sendStats.ts b/src/classes/DiscordWebhook/sendStats.ts similarity index 98% rename from src/lib/DiscordWebhook/sendStats.ts rename to src/classes/DiscordWebhook/sendStats.ts index 3e4c829e8..4bd20d89e 100644 --- a/src/lib/DiscordWebhook/sendStats.ts +++ b/src/classes/DiscordWebhook/sendStats.ts @@ -3,10 +3,10 @@ import pluralize from 'pluralize'; import SteamID from 'steamid'; import { sendWebhook } from './utils'; import { Webhook } from './interfaces'; -import log from '../logger'; +import log from '../../lib/logger'; import { stats, profit, timeNow } from '../../lib/tools/export'; -import Bot from '../../classes/Bot'; -import loadPollData from '../tools/polldata'; +import Bot from '../Bot'; +import loadPollData from '../../lib/tools/polldata'; export default async function sendStats(bot: Bot, forceSend = false, steamID?: SteamID): Promise { const optDW = bot.options.discordWebhook; diff --git a/src/lib/DiscordWebhook/sendTf2DisplayNotification.ts b/src/classes/DiscordWebhook/sendTf2DisplayNotification.ts similarity index 92% rename from src/lib/DiscordWebhook/sendTf2DisplayNotification.ts rename to src/classes/DiscordWebhook/sendTf2DisplayNotification.ts index 84dad9c86..be59051cf 100644 --- a/src/lib/DiscordWebhook/sendTf2DisplayNotification.ts +++ b/src/classes/DiscordWebhook/sendTf2DisplayNotification.ts @@ -1,8 +1,8 @@ import { sendWebhook } from './utils'; import { Webhook } from './interfaces'; -import log from '../logger'; -import Bot from '../../classes/Bot'; -import { timeNow } from '../tools/time'; +import log from '../../lib/logger'; +import Bot from '../Bot'; +import { timeNow } from '../../lib/tools/time'; export default function sendTf2DisplayNotification(bot: Bot, title: string, body: string): void { const opt = bot.options.discordWebhook; diff --git a/src/lib/DiscordWebhook/sendTf2ItemBroadcast.ts b/src/classes/DiscordWebhook/sendTf2ItemBroadcast.ts similarity index 93% rename from src/lib/DiscordWebhook/sendTf2ItemBroadcast.ts rename to src/classes/DiscordWebhook/sendTf2ItemBroadcast.ts index 23a19b178..09767c15a 100644 --- a/src/lib/DiscordWebhook/sendTf2ItemBroadcast.ts +++ b/src/classes/DiscordWebhook/sendTf2ItemBroadcast.ts @@ -1,8 +1,8 @@ import { sendWebhook } from './utils'; import { Webhook } from './interfaces'; -import log from '../logger'; -import Bot from '../../classes/Bot'; -import { timeNow } from '../tools/time'; +import log from '../../lib/logger'; +import Bot from '../Bot'; +import { timeNow } from '../../lib/tools/time'; export default function sendTf2ItemBroadcast( bot: Bot, diff --git a/src/lib/DiscordWebhook/sendTf2SystemMessage.ts b/src/classes/DiscordWebhook/sendTf2SystemMessage.ts similarity index 91% rename from src/lib/DiscordWebhook/sendTf2SystemMessage.ts rename to src/classes/DiscordWebhook/sendTf2SystemMessage.ts index dbc51a552..1decbc54a 100644 --- a/src/lib/DiscordWebhook/sendTf2SystemMessage.ts +++ b/src/classes/DiscordWebhook/sendTf2SystemMessage.ts @@ -1,8 +1,8 @@ import { sendWebhook } from './utils'; import { Webhook } from './interfaces'; -import log from '../logger'; -import Bot from '../../classes/Bot'; -import { timeNow } from '../tools/time'; +import log from '../../lib/logger'; +import Bot from '../Bot'; +import { timeNow } from '../../lib/tools/time'; export default function sendTf2SystemMessage(bot: Bot, message: string): void { const opt = bot.options.discordWebhook; diff --git a/src/lib/DiscordWebhook/sendTradeDeclined.ts b/src/classes/DiscordWebhook/sendTradeDeclined.ts similarity index 98% rename from src/lib/DiscordWebhook/sendTradeDeclined.ts rename to src/classes/DiscordWebhook/sendTradeDeclined.ts index e1c07e501..c0e2efdc6 100644 --- a/src/lib/DiscordWebhook/sendTradeDeclined.ts +++ b/src/classes/DiscordWebhook/sendTradeDeclined.ts @@ -1,10 +1,10 @@ import { Action, TradeOffer } from '@tf2autobot/tradeoffer-manager'; import { getPartnerDetails, quickLinks, sendWebhook } from './utils'; -import Bot from '../../classes/Bot'; -import * as t from '../tools/export'; -import log from '../logger'; +import Bot from '../Bot'; +import * as t from '../../lib/tools/export'; +import log from '../../lib/logger'; import { Webhook } from './export'; -import { sendToAdmin } from '../../classes/MyHandler/offer/processDeclined'; +import { sendToAdmin } from '../MyHandler/offer/processDeclined'; export default async function sendTradeDeclined( offer: TradeOffer, diff --git a/src/lib/DiscordWebhook/sendTradeSummary.ts b/src/classes/DiscordWebhook/sendTradeSummary.ts similarity index 98% rename from src/lib/DiscordWebhook/sendTradeSummary.ts rename to src/classes/DiscordWebhook/sendTradeSummary.ts index c98759c9e..d2d2231ad 100644 --- a/src/lib/DiscordWebhook/sendTradeSummary.ts +++ b/src/classes/DiscordWebhook/sendTradeSummary.ts @@ -3,10 +3,10 @@ import pluralize from 'pluralize'; import Currencies from '@tf2autobot/tf2-currencies'; import { getPartnerDetails, quickLinks, sendWebhook } from './utils'; import { Webhook } from './interfaces'; -import log from '../logger'; -import * as t from '../tools/export'; -import Bot from '../../classes/Bot'; -import { sendToAdmin } from '../../classes/MyHandler/offer/accepted/processAccepted'; +import log from '../../lib/logger'; +import * as t from '../../lib/tools/export'; +import Bot from '../Bot'; +import { sendToAdmin } from '../MyHandler/offer/accepted/processAccepted'; export default async function sendTradeSummary( offer: TradeOffer, diff --git a/src/lib/DiscordWebhook/utils.ts b/src/classes/DiscordWebhook/utils.ts similarity index 97% rename from src/lib/DiscordWebhook/utils.ts rename to src/classes/DiscordWebhook/utils.ts index 38eaa987b..f7ca43444 100644 --- a/src/lib/DiscordWebhook/utils.ts +++ b/src/classes/DiscordWebhook/utils.ts @@ -1,8 +1,8 @@ import TradeOfferManager, { TradeOffer } from '@tf2autobot/tradeoffer-manager'; import axios, { AxiosError } from 'axios'; import { Webhook } from './interfaces'; -import Bot from '../../classes/Bot'; -import log from '../logger'; +import Bot from '../Bot'; +import log from '../../lib/logger'; import filterAxiosError, { ErrorFiltered } from '@tf2autobot/filter-axios-error'; export function getPartnerDetails(offer: TradeOffer, bot: Bot): Promise<{ personaName: string; avatarFull: any }> { diff --git a/src/classes/MyHandler/MyHandler.ts b/src/classes/MyHandler/MyHandler.ts index 54180d8e6..4d9c149db 100644 --- a/src/classes/MyHandler/MyHandler.ts +++ b/src/classes/MyHandler/MyHandler.ts @@ -40,7 +40,7 @@ import * as files from '../../lib/files'; import { exponentialBackoff } from '../../lib/helpers'; import { noiseMakers } from '../../lib/data'; -import { sendAlert } from '../../lib/DiscordWebhook/export'; +import { sendAlert } from '../DiscordWebhook/export'; import { summarize, uptime, getHighValueItems, testPriceKey } from '../../lib/tools/export'; import genPaths from '../../resources/paths'; @@ -49,9 +49,9 @@ import Options, { OfferType } from '../Options'; import SteamTradeOfferManager from '@tf2autobot/tradeoffer-manager'; import filterAxiosError from '@tf2autobot/filter-axios-error'; -import sendTf2SystemMessage from '../../lib/DiscordWebhook/sendTf2SystemMessage'; -import sendTf2DisplayNotification from '../../lib/DiscordWebhook/sendTf2DisplayNotification'; -import sendTf2ItemBroadcast from '../../lib/DiscordWebhook/sendTf2ItemBroadcast'; +import sendTf2SystemMessage from '../DiscordWebhook/sendTf2SystemMessage'; +import sendTf2DisplayNotification from '../DiscordWebhook/sendTf2DisplayNotification'; +import sendTf2ItemBroadcast from '../DiscordWebhook/sendTf2ItemBroadcast'; const filterReasons = (reasons: string[]) => { const filtered = new Set(reasons); diff --git a/src/classes/MyHandler/offer/accepted/processAccepted.ts b/src/classes/MyHandler/offer/accepted/processAccepted.ts index d4c8bfb9e..e4eeaa701 100644 --- a/src/classes/MyHandler/offer/accepted/processAccepted.ts +++ b/src/classes/MyHandler/offer/accepted/processAccepted.ts @@ -5,7 +5,7 @@ import Bot from '../../../Bot'; import { KeyPrices } from '../../../Pricelist'; import log from '../../../../lib/logger'; import * as t from '../../../../lib/tools/export'; -import { sendTradeSummary } from '../../../../lib/DiscordWebhook/export'; +import { sendTradeSummary } from '../../../DiscordWebhook/export'; export default function processAccepted( offer: i.TradeOffer, diff --git a/src/classes/MyHandler/offer/accepted/updateListings.ts b/src/classes/MyHandler/offer/accepted/updateListings.ts index c5515eb81..19c6d69d7 100644 --- a/src/classes/MyHandler/offer/accepted/updateListings.ts +++ b/src/classes/MyHandler/offer/accepted/updateListings.ts @@ -9,7 +9,7 @@ import Bot from '../../../Bot'; import Pricelist, { EntryData } from '../../../Pricelist'; import { Attributes } from '../../../TF2GC'; import log from '../../../../lib/logger'; -import { sendAlert } from '../../../../lib/DiscordWebhook/export'; +import { sendAlert } from '../../../DiscordWebhook/export'; import { PaintedNames } from '../../../Options'; import { testPriceKey } from '../../../../lib/tools/export'; diff --git a/src/classes/MyHandler/offer/processDeclined.ts b/src/classes/MyHandler/offer/processDeclined.ts index cc76c1465..f90b27911 100644 --- a/src/classes/MyHandler/offer/processDeclined.ts +++ b/src/classes/MyHandler/offer/processDeclined.ts @@ -2,7 +2,7 @@ import * as i from '@tf2autobot/tradeoffer-manager'; import SKU from '@tf2autobot/tf2-sku'; import Bot from '../../Bot'; import * as t from '../../../lib/tools/export'; -import sendTradeDeclined from '../../../lib/DiscordWebhook/sendTradeDeclined'; +import sendTradeDeclined from '../../DiscordWebhook/sendTradeDeclined'; import { KeyPrices } from '../../../classes/Pricelist'; export default function processDeclined(offer: i.TradeOffer, bot: Bot): void { diff --git a/src/classes/MyHandler/offer/review/send-review.ts b/src/classes/MyHandler/offer/review/send-review.ts index f7a993b0a..b15127835 100644 --- a/src/classes/MyHandler/offer/review/send-review.ts +++ b/src/classes/MyHandler/offer/review/send-review.ts @@ -3,7 +3,7 @@ import processReview from './process-review'; import * as timersPromises from 'timers/promises'; import Bot from '../../../Bot'; import log from '../../../../lib/logger'; -import { sendOfferReview } from '../../../../lib/DiscordWebhook/export'; +import { sendOfferReview } from '../../../DiscordWebhook/export'; import * as t from '../../../../lib/tools/export'; import { KeyPrices } from 'src/classes/Pricelist'; import { Links } from '../../../../lib/tools/export'; diff --git a/src/classes/Pricelist.ts b/src/classes/Pricelist.ts index 634f42e2a..e3d8f676b 100644 --- a/src/classes/Pricelist.ts +++ b/src/classes/Pricelist.ts @@ -8,7 +8,7 @@ import Options from './Options'; import Bot from './Bot'; import log from '../lib/logger'; import validator from '../lib/validator'; -import { sendWebHookPriceUpdateV1, sendAlert, sendFailedPriceUpdate } from '../lib/DiscordWebhook/export'; +import { sendWebHookPriceUpdateV1, sendAlert, sendFailedPriceUpdate } from './DiscordWebhook/export'; import IPricer, { GetItemPriceResponse, Item } from './IPricer'; export enum PricelistChangedSource { diff --git a/src/classes/Trades.ts b/src/classes/Trades.ts index 915cc71ce..ec96333dc 100644 --- a/src/classes/Trades.ts +++ b/src/classes/Trades.ts @@ -21,7 +21,7 @@ import Inventory, { Dict } from './Inventory'; import log from '../lib/logger'; import { exponentialBackoff } from '../lib/helpers'; -import { sendAlert } from '../lib/DiscordWebhook/export'; +import { sendAlert } from './DiscordWebhook/export'; import { isBptfBanned } from '../lib/bans'; import * as t from '../lib/tools/export'; From 3552341954b1be2983fd30dbfe9c91a9a6c41f9c Mon Sep 17 00:00:00 2001 From: Purple <87976511+purplebarber@users.noreply.github.com> Date: Fri, 27 Oct 2023 15:55:56 +0800 Subject: [PATCH 09/14] remove tradableOnly check for findByPartialSku --- src/classes/Carts/UserCart.ts | 4 ++-- src/classes/Inventory.ts | 19 +------------------ 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/src/classes/Carts/UserCart.ts b/src/classes/Carts/UserCart.ts index aba9f8722..b8eabc64d 100644 --- a/src/classes/Carts/UserCart.ts +++ b/src/classes/Carts/UserCart.ts @@ -533,7 +533,7 @@ export default class UserCart extends Cart { let theirAssetids: string[]; let amount = this.getTheirCount(sku); if (findByPartialSku) { - theirAssetids = theirInventory.findByPartialSku(sku, true, elevatedStrange); + theirAssetids = theirInventory.findByPartialSku(sku, elevatedStrange); if (theirAssetids.length > 0) { sku = theirInventory.findByAssetid(theirAssetids[0]); } @@ -777,7 +777,7 @@ export default class UserCart extends Cart { let assetids: string[]; const amount = this.their[sku]; if (findByPartialSku) { - assetids = theirInventory.findByPartialSku(sku, true, elevatedStrange); + assetids = theirInventory.findByPartialSku(sku, elevatedStrange); } else { assetids = theirInventory.findBySKU(sku, true); } diff --git a/src/classes/Inventory.ts b/src/classes/Inventory.ts index 5ccb62d10..0469bf037 100644 --- a/src/classes/Inventory.ts +++ b/src/classes/Inventory.ts @@ -196,7 +196,7 @@ export default class Inventory { return nonTradable.concat(tradable).slice(0); } - findByPartialSku(partialSku: string, tradableOnly = true, elevatedStrange = false): string[] { + findByPartialSku(partialSku: string, elevatedStrange = false): string[] { const matchingSkus: string[] = []; if (elevatedStrange) { @@ -207,29 +207,12 @@ export default class Inventory { matchingSkus.push(...this.tradable[sku].map(item => item?.id)); } } - - if (!tradableOnly) { - for (const sku in this.nonTradable) { - if (sku.startsWith(partialSku) && sku.includes(';strange')) { - matchingSkus.push(...this.nonTradable[sku].map(item => item?.id)); - } - } - } - } else { for (const sku in this.tradable) { if (sku.startsWith(partialSku)) { matchingSkus.push(...this.tradable[sku].map(item => item?.id)); } } - - if (!tradableOnly) { - for (const sku in this.nonTradable) { - if (sku.startsWith(partialSku)) { - matchingSkus.push(...this.nonTradable[sku].map(item => item?.id)); - } - } - } } return matchingSkus.slice(0); } From e9205adf600615b2b324a72f77094be9aa37f9c2 Mon Sep 17 00:00:00 2001 From: IdiNium <47635037+idinium96@users.noreply.github.com> Date: Mon, 30 Oct 2023 03:09:27 +0800 Subject: [PATCH 10/14] =?UTF-8?q?=F0=9F=94=84=EF=B8=8F=20bump=20steam-sess?= =?UTF-8?q?ion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2ad5958dd..164d7f42c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -46,7 +46,7 @@ "retry": "^0.13.1", "semver": "^7.5.4", "socket.io-client": "^4.7.1", - "steam-session": "^1.4.1", + "steam-session": "^1.7.1", "steam-totp": "^2.1.2", "steam-user": "^5.0.1", "steamid": "^2.0.0", @@ -10166,9 +10166,9 @@ } }, "node_modules/steam-session": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/steam-session/-/steam-session-1.6.0.tgz", - "integrity": "sha512-28bTCqxP27hcVRSwMW60tVKQeosFJiNcjJYGJ3yb15IrGFWQAJqHFTRmVZIUYTTMxUiFgv+5ns9dpLXz+eA7DA==", + "version": "1.7.1", + "resolved": "https://registry.npmjs.org/steam-session/-/steam-session-1.7.1.tgz", + "integrity": "sha512-igdcAFlhFVHnpk2+Wy6iI91qDC0FoqmKmShoSVhKH+UvNWDzrHgOza1mq9jPRi/uBfVuVAe1dpUbtEShiprXzg==", "dependencies": { "@doctormckay/stdlib": "^2.9.0", "@doctormckay/user-agents": "^1.0.0", diff --git a/package.json b/package.json index ab3adc385..d0a74ae14 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "retry": "^0.13.1", "semver": "^7.5.4", "socket.io-client": "^4.7.1", - "steam-session": "^1.4.1", + "steam-session": "^1.7.1", "steam-totp": "^2.1.2", "steam-user": "^5.0.1", "steamid": "^2.0.0", From a022bae514cfa26dda9dab0b264f60e2cf9dd76a Mon Sep 17 00:00:00 2001 From: IdiNium <47635037+idinium96@users.noreply.github.com> Date: Mon, 30 Oct 2023 03:09:52 +0800 Subject: [PATCH 11/14] =?UTF-8?q?=F0=9F=94=84=EF=B8=8F=20bump=20steam-user?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 18 +++++++++--------- package.json | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index 164d7f42c..110e2a32d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -48,7 +48,7 @@ "socket.io-client": "^4.7.1", "steam-session": "^1.7.1", "steam-totp": "^2.1.2", - "steam-user": "^5.0.1", + "steam-user": "^5.0.2", "steamid": "^2.0.0", "url": "^0.11.1", "valid-url": "^1.0.9", @@ -10246,12 +10246,12 @@ } }, "node_modules/steam-user": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/steam-user/-/steam-user-5.0.1.tgz", - "integrity": "sha512-kH0u0v4qobbnkxDcWyZNoAvOkbCJH9KBbRGRssSfkmAX4fZZQYlJfJwvojL0DIRJr6/3C4tycqXCHYW0+B1Xlg==", + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/steam-user/-/steam-user-5.0.2.tgz", + "integrity": "sha512-LIzxnD+s+SOWMzJMVUZkD+Wm6RemyMRucSiY+RWPoVb4hI9iVagaZ0buSvUCqpqdoDVtNTQodo8QzUmlDdBkdA==", "dependencies": { "@bbob/parser": "^2.2.0", - "@doctormckay/stdlib": "^2.7.1", + "@doctormckay/stdlib": "^2.9.1", "@doctormckay/steam-crypto": "^1.2.0", "adm-zip": "^0.5.10", "binarykvparser": "^2.2.0", @@ -10262,7 +10262,7 @@ "protobufjs": "^7.2.4", "socks-proxy-agent": "^7.0.0", "steam-appticket": "^1.0.1", - "steam-session": "^1.3.4", + "steam-session": "^1.7.0", "steam-totp": "^2.0.1", "steamid": "^2.0.0", "websocket13": "^4.0.0" @@ -10272,9 +10272,9 @@ } }, "node_modules/steam-user/node_modules/@doctormckay/stdlib": { - "version": "2.8.1", - "resolved": "https://registry.npmjs.org/@doctormckay/stdlib/-/stdlib-2.8.1.tgz", - "integrity": "sha512-QgUfglKSOECKLnWXhqLvcNB0NTozBRcep8I9514mesEexZ/M6zwN5AvBXsXnDknwY/cme4nvAyGfaSO5P/UGXg==", + "version": "2.9.1", + "resolved": "https://registry.npmjs.org/@doctormckay/stdlib/-/stdlib-2.9.1.tgz", + "integrity": "sha512-o/gEe6iTMMLQgJytfpYehAQVTvUsEyPiOOM66ATmzRlHgXdvj9XD5SWjd+DqHZqd5zv6RCC2pO4ktqfMnFU7vA==", "dependencies": { "psl": "^1.9.0" }, diff --git a/package.json b/package.json index d0a74ae14..c76686da1 100644 --- a/package.json +++ b/package.json @@ -65,7 +65,7 @@ "socket.io-client": "^4.7.1", "steam-session": "^1.7.1", "steam-totp": "^2.1.2", - "steam-user": "^5.0.1", + "steam-user": "^5.0.2", "steamid": "^2.0.0", "url": "^0.11.1", "valid-url": "^1.0.9", From 4fee1953d13aa25f267b93bea6e8fe168e49584c Mon Sep 17 00:00:00 2001 From: IdiNium <47635037+idinium96@users.noreply.github.com> Date: Mon, 30 Oct 2023 03:10:14 +0800 Subject: [PATCH 12/14] =?UTF-8?q?=F0=9F=94=84=EF=B8=8F=20bump=20@tf2autobo?= =?UTF-8?q?t/steamcommunity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 10 +++++----- package.json | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 110e2a32d..100fda57d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "@tf2autobot/bptf-login": "^2.3.6", "@tf2autobot/filter-axios-error": "^1.5.2", "@tf2autobot/jsonlint": "^1.0.0", - "@tf2autobot/steamcommunity": "^3.47.1", + "@tf2autobot/steamcommunity": "^3.47.2", "@tf2autobot/tf2": "^1.3.5", "@tf2autobot/tf2-currencies": "^2.0.1", "@tf2autobot/tf2-schema": "^4.2.15", @@ -2364,16 +2364,16 @@ } }, "node_modules/@tf2autobot/steamcommunity": { - "version": "3.47.1", - "resolved": "https://registry.npmjs.org/@tf2autobot/steamcommunity/-/steamcommunity-3.47.1.tgz", - "integrity": "sha512-CBLKj4DzskMJERU+/oh5Eo19jyiPBG3G1CYk6FFZg7QoTdH1nbTFgy7/A15mk7SGML1nLQUnZBqtNOWL25fIlg==", + "version": "3.47.2", + "resolved": "https://registry.npmjs.org/@tf2autobot/steamcommunity/-/steamcommunity-3.47.2.tgz", + "integrity": "sha512-Ta7Jw4XWzFLa4r9Eki3QJxOuuAbCBAvpSiOTNxdP7FrZBWJyS6UFS158U6e8uNe/E29WdAhyuVJRXea6UdVVHw==", "dependencies": { "@doctormckay/user-agents": "^1.0.0", "async": "^3.2.4", "cheerio": "^1.0.0-rc.12", "image-size": "^0.8.2", "request": "^2.88.2", - "steam-session": "^1.6.0", + "steam-session": "^1.7.1", "steam-totp": "^2.1.2", "steamid": "^2.0.0", "xml2js": "^0.6.2" diff --git a/package.json b/package.json index c76686da1..431a137ce 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "@tf2autobot/bptf-login": "^2.3.6", "@tf2autobot/filter-axios-error": "^1.5.2", "@tf2autobot/jsonlint": "^1.0.0", - "@tf2autobot/steamcommunity": "^3.47.1", + "@tf2autobot/steamcommunity": "^3.47.2", "@tf2autobot/tf2": "^1.3.5", "@tf2autobot/tf2-currencies": "^2.0.1", "@tf2autobot/tf2-schema": "^4.2.15", From 20da17e8dd17dda53a40df542030b16342aa569f Mon Sep 17 00:00:00 2001 From: IdiNium <47635037+idinium96@users.noreply.github.com> Date: Mon, 30 Oct 2023 03:10:45 +0800 Subject: [PATCH 13/14] =?UTF-8?q?=F0=9F=94=84=EF=B8=8F=20bump=20@tf2autobo?= =?UTF-8?q?t/tradeoffer-manager?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 10 +++++----- package.json | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 100fda57d..19b34155b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,7 +18,7 @@ "@tf2autobot/tf2-currencies": "^2.0.1", "@tf2autobot/tf2-schema": "^4.2.15", "@tf2autobot/tf2-sku": "^2.0.4", - "@tf2autobot/tradeoffer-manager": "^2.15.1", + "@tf2autobot/tradeoffer-manager": "^2.15.2", "async": "^3.2.4", "axios": "^1.4.0", "bluebird": "^3.7.2", @@ -2432,12 +2432,12 @@ } }, "node_modules/@tf2autobot/tradeoffer-manager": { - "version": "2.15.1", - "resolved": "https://registry.npmjs.org/@tf2autobot/tradeoffer-manager/-/tradeoffer-manager-2.15.1.tgz", - "integrity": "sha512-R6uM5TIShPY4XRJ5YU7HEVMcyLbjyMa/20EzbZIog0SUuRjKuLKdt+Lj1fvIqTkm2uH/lFPIOFAXvrnzy79y8g==", + "version": "2.15.2", + "resolved": "https://registry.npmjs.org/@tf2autobot/tradeoffer-manager/-/tradeoffer-manager-2.15.2.tgz", + "integrity": "sha512-7ysDjQPwLuWNpwPlBeR0SjBCxXeWsxTHYnPdtf6KocOerVPioft7X1P6HLU1F2eHIDAoyac0Z7RuMKGwyVv5Tw==", "dependencies": { "@doctormckay/stdlib": "^1.16.0", - "@tf2autobot/steamcommunity": "^3.47.1", + "@tf2autobot/steamcommunity": "^3.47.2", "async": "^3.2.4", "file-manager": "^2.0.1", "languages": "^0.1.3", diff --git a/package.json b/package.json index 431a137ce..7803ca284 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "@tf2autobot/tf2-currencies": "^2.0.1", "@tf2autobot/tf2-schema": "^4.2.15", "@tf2autobot/tf2-sku": "^2.0.4", - "@tf2autobot/tradeoffer-manager": "^2.15.1", + "@tf2autobot/tradeoffer-manager": "^2.15.2", "async": "^3.2.4", "axios": "^1.4.0", "bluebird": "^3.7.2", From f27183c5e61691ab834be8d681f2b89c454ba507 Mon Sep 17 00:00:00 2001 From: IdiNium <47635037+idinium96@users.noreply.github.com> Date: Fri, 3 Nov 2023 01:11:18 +0800 Subject: [PATCH 14/14] =?UTF-8?q?=F0=9F=94=A8=20update=20getPricelist=20co?= =?UTF-8?q?de=20for=20prices.tf?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/pricer/pricestf/prices-tf-pricer.ts | 64 ++++++++++++++------- 1 file changed, 43 insertions(+), 21 deletions(-) diff --git a/src/lib/pricer/pricestf/prices-tf-pricer.ts b/src/lib/pricer/pricestf/prices-tf-pricer.ts index bd7dd83b5..5eaa62e69 100644 --- a/src/lib/pricer/pricestf/prices-tf-pricer.ts +++ b/src/lib/pricer/pricestf/prices-tf-pricer.ts @@ -1,4 +1,3 @@ -import timersPromises from 'timers/promises'; import Currencies from '@tf2autobot/tf2-currencies'; import PricesTfSocketManager from './prices-tf-socket-manager'; import IPricer, { @@ -8,12 +7,14 @@ import IPricer, { PricerOptions, RequestCheckResponse } from '../../../classes/IPricer'; -import PricesTfApi, { PricesTfItem, PricesTfItemMessageEvent } from './prices-tf-api'; +import PricesTfApi, { PricesTfGetPricesResponse, PricesTfItem, PricesTfItemMessageEvent } from './prices-tf-api'; import log from '../../logger'; export default class PricesTfPricer implements IPricer { private socketManager: PricesTfSocketManager; + private attempts = 0; + public constructor(private api: PricesTfApi) { this.socketManager = new PricesTfSocketManager(api); } @@ -42,19 +43,21 @@ export default class PricesTfPricer implements IPricer { } async getPricelist(): Promise { - try { - const pricelist = await PricesTfApi.apiRequest( - 'GET', - '/json/pricelist-array', - undefined, - undefined, - undefined, - 'https://autobot.tf' - ); - - return pricelist; - } catch (err) { - log.error('Failed to get pricelist from autobot.tf: ', err); + if (JSON.parse(process.env.DEV) === true) { + try { + const pricelist = await PricesTfApi.apiRequest( + 'GET', + '/json/pricelist-array', + undefined, + undefined, + undefined, + 'https://autobot.tf' + ); + + return pricelist; + } catch (err) { + log.error('Failed to get pricelist from autobot.tf: ', err); + } } let prices: PricesTfItem[] = []; @@ -62,15 +65,34 @@ export default class PricesTfPricer implements IPricer { let totalPages = 0; let delay = 0; - const minDelay = 200; + const minDelay = 100; + let response: PricesTfGetPricesResponse; + + log.debug('Requesting pricelist pages...'); do { - await timersPromises.setTimeout(delay); + await new Promise(resolve => setTimeout(resolve, delay)); const start = new Date().getTime(); - log.debug('Requesting pricelist pages...'); - const response = await this.api.getPricelistPage(currentPage); - totalPages = response.meta.totalPages; - currentPage++; + + try { + log.debug(`Getting page ${currentPage}${totalPages === 0 ? '' : ` of ${totalPages}`}...`); + response = await this.api.getPricelistPage(currentPage); + currentPage++; + totalPages = response.meta.totalPages; + } catch (e) { + if (currentPage > 1) { + await new Promise(resolve => setTimeout(resolve, 60 * 1000)); + continue; + } else { + if (this.attempts < 3) { + this.attempts++; + return this.getPricelist(); + } + + this.attempts = 0; + throw e; + } + } prices = prices.concat(response.items); const time = new Date().getTime() - start;