From 4de3c2b2844129aa84999fd990980545fe3448c4 Mon Sep 17 00:00:00 2001 From: idinium96 <47635037+idinium96@users.noreply.github.com> Date: Thu, 2 May 2024 10:42:24 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20use=20AccessToken=20if=20API=20k?= =?UTF-8?q?ey=20is=20not=20set=20(temp)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/classes/Bot.ts | 7 +++--- src/classes/Friends.ts | 24 +++++++++++++------ src/classes/TF2Inventory.ts | 17 +++++++++---- .../@tf2autobot/tradeoffer-manager/index.d.ts | 2 ++ 4 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/classes/Bot.ts b/src/classes/Bot.ts index d4f2f00c6..c1f6c1a2f 100644 --- a/src/classes/Bot.ts +++ b/src/classes/Bot.ts @@ -179,7 +179,7 @@ export default class Bot { this.manager = new TradeOfferManager({ steam: this.client, community: this.community, - // useAccessToken: false, // https://github.com/DoctorMcKay/node-steam-tradeoffer-manager/wiki/Access-Tokens + useAccessToken: !this.options.steamApiKey, // https://github.com/DoctorMcKay/node-steam-tradeoffer-manager/wiki/Access-Tokens language: 'en', pollInterval: -1, cancelTime: 15 * 60 * 1000, @@ -960,7 +960,7 @@ export default class Bot { }); }, (callback): void => { - log.info('Getting Steam API key...'); + log.info('Setting cookies...'); void this.setCookies(cookies).asCallback(callback); }, (callback): void => { @@ -984,8 +984,7 @@ export default class Bot { }, (callback): void => { this.schemaManager = new SchemaManager({ - apiKey: this.manager.apiKey, - updateTime: 24 * 60 * 60 * 1000, + updateTime: 1 * 60 * 60 * 1000, lite: true }); diff --git a/src/classes/Friends.ts b/src/classes/Friends.ts index 3c2cf81a0..b0e968345 100644 --- a/src/classes/Friends.ts +++ b/src/classes/Friends.ts @@ -43,16 +43,26 @@ export default class Friends { get getMaxFriends(): Promise { return new Promise((resolve, reject) => { + const params: { + steamid: string; + key?: string; + access_token?: string; + } = { + steamid: (this.bot.client.steamID === null + ? this.bot.handler.getBotInfo.steamID + : this.bot.client.steamID + ).getSteamID64() + }; + + if (this.bot.manager.apiKey) { + params.key = this.bot.manager.apiKey; + } else { + params.access_token = this.bot.manager.accessToken; + } void axios({ url: 'https://api.steampowered.com/IPlayerService/GetBadges/v1/', method: 'GET', - params: { - key: this.bot.manager.apiKey, - steamid: (this.bot.client.steamID === null - ? this.bot.handler.getBotInfo.steamID - : this.bot.client.steamID - ).getSteamID64() - } + params }) .then(response => { // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access diff --git a/src/classes/TF2Inventory.ts b/src/classes/TF2Inventory.ts index 94c6941bd..7c1fcf9f7 100644 --- a/src/classes/TF2Inventory.ts +++ b/src/classes/TF2Inventory.ts @@ -99,13 +99,22 @@ export default class TF2Inventory { private fetch(): Promise { return new Promise((resolve, reject) => { + const params: { + steamid: string; + key?: string; + access_token?: string; + } = { steamid: this.getSteamID.toString() }; + + if (this.manager.apiKey) { + params.key = this.manager.apiKey; + } else { + params.access_token = this.manager.accessToken; + } + void axios({ url: 'https://api.steampowered.com/IEconItems_440/GetPlayerItems/v0001/', method: 'GET', - params: { - key: this.manager.apiKey, - steamid: this.getSteamID.toString() - } + params }) .then(response => { const body = response.data as GetPlayerItems; diff --git a/src/types/modules/@tf2autobot/tradeoffer-manager/index.d.ts b/src/types/modules/@tf2autobot/tradeoffer-manager/index.d.ts index af5f4e139..1bebac24c 100644 --- a/src/types/modules/@tf2autobot/tradeoffer-manager/index.d.ts +++ b/src/types/modules/@tf2autobot/tradeoffer-manager/index.d.ts @@ -27,6 +27,8 @@ declare module '@tf2autobot/tradeoffer-manager' { apiKey: string | null; + accessToken: string | null; + pollInterval: number; getUserInventoryContents(