Skip to content

Commit

Permalink
include max slots in inventory command/webhook
Browse files Browse the repository at this point in the history
  • Loading branch information
idinium96 committed Jul 31, 2020
1 parent e987fce commit 74f73b1
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/classes/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion src/classes/DiscordWebhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -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
}
Expand Down
43 changes: 43 additions & 0 deletions src/classes/MyHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -99,6 +100,8 @@ export = class MyHandler extends Handler {

private scrapAdjustmentValue = 0;

private backpackSlots = 0;

private isAcceptedWithInvalidItemsOrOverstocked = false;

recentlySentMessage: UnknownDictionary<number> = {};
Expand Down Expand Up @@ -239,6 +242,10 @@ export = class MyHandler extends Handler {
return this.customGameName;
}

getBackpackSlots(): number {
return this.backpackSlots;
}

getUserAutokeys(): {
enabled: boolean;
status: boolean;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -1242,6 +1252,7 @@ export = class MyHandler extends Handler {
offer.summarizeWithLink(this.bot.schema),
pureStock,
currentItems,
this.backpackSlots,
invalidItemsCombine,
keyPrice,
value,
Expand Down Expand Up @@ -2389,6 +2400,38 @@ Autokeys status:-
}
}

requestBackpackSlots(): Promise<void> {
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[] = [];
Expand Down

0 comments on commit 74f73b1

Please sign in to comment.