diff --git a/src/classes/Bot.ts b/src/classes/Bot.ts index 716ffdadf..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 }); @@ -1247,6 +1246,10 @@ export default class Bot { this.listingManager.setUserID(this.userID); } + if (this.options.steamApiKey) { + this.manager.apiKey = this.options.steamApiKey; + } + return new Promise((resolve, reject) => { this.manager.setCookies(cookies, err => { if (err) { 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/Options.ts b/src/classes/Options.ts index 112832d2e..6fb7dd4d2 100644 --- a/src/classes/Options.ts +++ b/src/classes/Options.ts @@ -2178,6 +2178,7 @@ export default interface Options extends JsonOptions { steamPassword?: string; steamSharedSecret?: string; steamIdentitySecret?: string; + steamApiKey?: string; bptfAccessToken?: string; bptfApiKey?: string; @@ -2494,6 +2495,7 @@ export function loadOptions(options?: Options): Options { steamPassword: getOption('steamPassword', '', String, incomingOptions), steamSharedSecret: getOption('steamSharedSecret', '', String, incomingOptions), steamIdentitySecret: getOption('steamIdentitySecret', '', String, incomingOptions), + steamApiKey: getOption('steamApiKey', '', String, incomingOptions), bptfAccessToken: getOption('bptfAccessToken', '', String, incomingOptions), bptfApiKey: getOption('bptfApiKey', '', String, incomingOptions), 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( diff --git a/template.ecosystem.json b/template.ecosystem.json index 2427a7f21..c187f15b7 100644 --- a/template.ecosystem.json +++ b/template.ecosystem.json @@ -17,6 +17,7 @@ "STEAM_PASSWORD": "", "STEAM_SHARED_SECRET": "", "STEAM_IDENTITY_SECRET": "", + "STEAM_API_KEY": "", "BPTF_ACCESS_TOKEN": "", "BPTF_API_KEY": "", @@ -28,9 +29,7 @@ "STEAMSUPPLY_API_KEY": "", "STEAMAPIS_API_KEY": "", - "ADMINS": [ - { "steam": "", "discord": null } - ], + "ADMINS": [{ "steam": "", "discord": null }], "KEEP": [""], "ITEM_STATS_WHITELIST": [], "GROUPS": ["103582791469033930"], diff --git a/template.env b/template.env index 3d85a25d8..c56ff2b94 100644 --- a/template.env +++ b/template.env @@ -4,6 +4,7 @@ STEAM_ACCOUNT_NAME="" STEAM_PASSWORD="" STEAM_SHARED_SECRET="" STEAM_IDENTITY_SECRET="" +STEAM_API_KEY="" BPTF_ACCESS_TOKEN="" BPTF_API_KEY=""