diff --git a/packages/dota/src/twitch/commands/test.ts b/packages/dota/src/twitch/commands/test.ts index 018435bf..4e7066e3 100644 --- a/packages/dota/src/twitch/commands/test.ts +++ b/packages/dota/src/twitch/commands/test.ts @@ -1,8 +1,11 @@ +import DOTA_ITEM_IDS from 'dotaconstants/build/item_ids.json' assert { type: 'json' } +import DOTA_ITEMS from 'dotaconstants/build/items.json' assert { type: 'json' } import { t } from 'i18next' import { gsiHandlers } from '../../dota/lib/consts.js' import { getAccountsFromMatch } from '../../dota/lib/getAccountsFromMatch.js' import { steamSocket } from '../../steam/ws.js' +import { DelayedGames } from '../../types.js' import { logger } from '../../utils/logger.js' import { chatClient } from '../chatClient.js' import commandHandler, { MessageType } from '../lib/CommandHandler.js' @@ -23,6 +26,67 @@ commandHandler.registerCommand('test', { return } + if (args[0] === 'items') { + const [, matchId, steam32Id] = args + let itemList: string[] | false | undefined = false + + steamSocket.emit('getUserSteamServer', steam32Id, async (err: any, steamServerId: string) => { + console.log({ steamServerId }) + if (!steamServerId) { + chatClient.say(channel, t('gameNotFound', { lng: message.channel.client.locale })) + return + } + + logger.info('test command', { + command: 'TEST', + steam32Id: steam32Id || client.steam32Id, + steamServerId, + }) + + // Wrap the steamSocket.emit in a Promise + const getDelayedDataPromise = new Promise((resolve, reject) => { + steamSocket.emit( + 'getRealTimeStats', + { + match_id: matchId, + forceRefetchAll: true, + steam_server_id: steamServerId, + token: client.token, + }, + (err: any, cards: any) => { + if (err) { + reject(err) + } else { + resolve(cards) + } + }, + ) + }) + + const playerIdx = 1 + const delayedData = await getDelayedDataPromise + const teamIndex = (playerIdx ?? 0) > 4 ? 1 : 0 + const teamPlayerIdx = (playerIdx ?? 0) % 5 + const itemIds = delayedData.teams[teamIndex]?.players[teamPlayerIdx]?.items + + itemList = + Array.isArray(itemIds) && + itemIds.length > 0 && + itemIds + .map((itemId) => { + const id = itemId as unknown as keyof typeof DOTA_ITEM_IDS + const itemShortname = DOTA_ITEM_IDS[id] as keyof typeof DOTA_ITEMS + const item = DOTA_ITEMS[itemShortname] + const itemName: string | boolean = item && 'dname' in item && item.dname + + return itemName || itemShortname + }) + .filter(Boolean) + + console.log(itemList) + }) + } + if (args[0] === 'cards') { const { accountIds } = await getAccountsFromMatch({ gsi: client.gsi, @@ -51,9 +115,9 @@ commandHandler.registerCommand('test', { steamSocket.emit( 'getUserSteamServer', steam32Id || client.steam32Id, - (err: any, steamserverid: string) => { - console.log({ steamserverid }) - if (!steamserverid) { + (err: any, steamServerId: string) => { + console.log({ steamServerId }) + if (!steamServerId) { chatClient.say(channel, t('gameNotFound', { lng: message.channel.client.locale })) return } @@ -61,12 +125,12 @@ commandHandler.registerCommand('test', { logger.info('test command', { command: 'TEST', steam32Id: steam32Id || client.steam32Id, - steamserverid, + steamServerId, }) logger.info( `https://api.steampowered.com/IDOTA2MatchStats_570/GetRealtimeStats/v1/?key=${process.env - .STEAM_WEB_API!}&server_steam_id=${steamserverid}`, + .STEAM_WEB_API!}&server_steam_id=${steamServerId}`, ) }, )