From 74f73b16f589120ea3acb66b4f3108c6aeac6a35 Mon Sep 17 00:00:00 2001 From: idinium96 Date: Fri, 31 Jul 2020 14:50:54 +0800 Subject: [PATCH] include max slots in inventory command/webhook --- src/classes/Commands.ts | 7 +++++- src/classes/DiscordWebhook.ts | 5 +++- src/classes/MyHandler.ts | 43 +++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/classes/Commands.ts b/src/classes/Commands.ts index 3b73d6a99..1d2ea1c3a 100644 --- a/src/classes/Commands.ts +++ b/src/classes/Commands.ts @@ -422,7 +422,12 @@ export = class Commands { private inventoryCommand(steamID: SteamID): void { const currentItems = this.bot.inventoryManager.getInventory().getTotalItems(); - this.bot.sendMessage(steamID, `šŸŽ’ My crrent items in my inventory: ${currentItems}`); + const backpackSlots = (this.bot.handler as MyHandler).getBackpackSlots(); + + this.bot.sendMessage( + steamID, + `šŸŽ’ My crrent items in my inventory: ${currentItems + (backpackSlots !== 0 ? '/' + backpackSlots : '')}` + ); } private autoKeysCommand(steamID: SteamID): void { diff --git a/src/classes/DiscordWebhook.ts b/src/classes/DiscordWebhook.ts index 719854ca5..bdbdf51cb 100644 --- a/src/classes/DiscordWebhook.ts +++ b/src/classes/DiscordWebhook.ts @@ -321,6 +321,7 @@ export = class DiscordWebhook { tradeSummary: string, pureStock: string[], currentItems: number, + backpackSlots: number, invalidItemsCombine: string[], keyPrice: { buy: Currencies; sell: Currencies }, value: { diff: number; diffRef: number; diffKey: string }, @@ -483,7 +484,9 @@ export = class DiscordWebhook { }` : '') + (isShowPureStock ? `\nšŸ’° Pure stock: ${pureStock.join(', ').toString()}` : '') + - (isShowInventory ? `\nšŸŽ’ Total items: ${currentItems}` : '') + + (isShowInventory + ? `\nšŸŽ’ Total items: ${currentItems + (backpackSlots !== 0 ? '/' + backpackSlots : '')}` + : '') + (AdditionalNotes ? '\n' + AdditionalNotes : ''), color: botEmbedColor } diff --git a/src/classes/MyHandler.ts b/src/classes/MyHandler.ts index ee453cdea..a4be6e1ed 100644 --- a/src/classes/MyHandler.ts +++ b/src/classes/MyHandler.ts @@ -7,6 +7,7 @@ import Inventory from './Inventory'; import { UnknownDictionary } from '../types/common'; import { Currency } from '../types/TeamFortress2'; import SKU from 'tf2-sku'; +import request from '@nicklason/request-retry'; import SteamUser from 'steam-user'; import TradeOfferManager, { TradeOffer, PollData } from 'steam-tradeoffer-manager'; @@ -99,6 +100,8 @@ export = class MyHandler extends Handler { private scrapAdjustmentValue = 0; + private backpackSlots = 0; + private isAcceptedWithInvalidItemsOrOverstocked = false; recentlySentMessage: UnknownDictionary = {}; @@ -239,6 +242,10 @@ export = class MyHandler extends Handler { return this.customGameName; } + getBackpackSlots(): number { + return this.backpackSlots; + } + getUserAutokeys(): { enabled: boolean; status: boolean; @@ -304,6 +311,9 @@ export = class MyHandler extends Handler { this.bot.client.gamesPlayed([this.customGameName, 440]); this.bot.client.setPersona(SteamUser.EPersonaState.Online); + // GetBackpackSlots + this.requestBackpackSlots(); + // Smelt / combine metal if needed this.keepMetalSupply(); @@ -1242,6 +1252,7 @@ export = class MyHandler extends Handler { offer.summarizeWithLink(this.bot.schema), pureStock, currentItems, + this.backpackSlots, invalidItemsCombine, keyPrice, value, @@ -2389,6 +2400,38 @@ Autokeys status:- } } + requestBackpackSlots(): Promise { + return new Promise((resolve, reject) => { + request( + { + url: 'https://api.steampowered.com/IEconItems_440/GetPlayerItems/v0001/', + method: 'GET', + qs: { + key: this.bot.manager.apiKey, + steamid: this.bot.client.steamID.getSteamID64() + }, + json: true, + gzip: true + }, + (err, response, body) => { + if (err) { + return reject(err); + } + + if (body.result.status != 1) { + err = new Error(body.result.statusDetail); + err.status = body.result.status; + return reject(err); + } + + this.backpackSlots = body.result.num_backpack_slots; + + return resolve(); + } + ); + }); + } + private itemList(offer: TradeOffer): { their: string[]; our: string[] } { const items: { our: {}; their: {} } = offer.data('dict'); const their: string[] = [];