Skip to content

Commit

Permalink
fix steam service callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
Geczy committed Sep 17, 2023
1 parent c9be6c8 commit 0be485c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
14 changes: 13 additions & 1 deletion packages/dota/src/twitch/commands/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,31 @@ commandHandler.registerCommand('test', {
gsi: client.gsi,
})
steamSocket.emit('getCards', accountIds, (err: any, response: any) => {
console.log(response) // one response per client
console.log(response, err) // one response per client
})

chatClient.say(channel, `cards! ${client.gsi?.map?.matchid}`)
return
}

if (args[0] === 'card') {
const [, accountId] = args

steamSocket.emit('getCard', Number(accountId), (err: any, response: any) => {
console.log({ response, err }) // one response per client
})

chatClient.say(channel, `card!`)
return
}

const [steam32Id] = args

steamSocket.emit(
'getUserSteamServer',
steam32Id || client.steam32Id,
(err: any, steamserverid: string) => {
console.log({ steamserverid })
if (!steamserverid) {
chatClient.say(channel, t('gameNotFound', { lng: message.channel.client.locale }))
return
Expand Down
37 changes: 29 additions & 8 deletions packages/steam/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ dota.dota2.on('ready', () => {
isConnectedToSteam = true
})

interface callback {
(err: any, response: any): void
}

io.on('connection', (socket) => {
// dota node app just connected
// make it join our room
Expand All @@ -28,28 +32,45 @@ io.on('connection', (socket) => {
hasDotabodSocket = true

socket.on('disconnect', () => {
console.log('disconnect')
console.log('We lost the server! Respond to all messages with "server offline"')
hasDotabodSocket = false
})

socket.on('getCards', async function (accountIds: number[]) {
socket.on('getCards', async function (accountIds: number[], callback: callback) {
if (!isConnectedToSteam) return
return await dota.getCards(accountIds)
try {
callback(null, await dota.getCards(accountIds))
} catch (e: any) {
callback(e.message, null)
}
})

socket.on('getCard', async function (accountId: number) {
socket.on('getCard', async function (accountId: number, callback: callback) {
if (!isConnectedToSteam) return
return await dota.getCard(accountId)
try {
callback(null, await dota.getCard(accountId))
} catch (e: any) {
callback(e.message, null)
}
})

socket.on('getUserSteamServer', async function (steam32Id: number) {
socket.on('getUserSteamServer', async function (steam32Id: number, callback: callback) {
if (!isConnectedToSteam) return
return await dota.getUserSteamServer(steam32Id)
try {
callback(null, await dota.getUserSteamServer(steam32Id))
} catch (e: any) {
callback(e.message, null)
}
})

socket.on('getRealTimeStats', async function (data: any) {
socket.on('getRealTimeStats', async function (data: any, callback: callback) {
if (!isConnectedToSteam) return
return await dota.GetRealTimeStats(data)
try {
callback(null, await dota.GetRealTimeStats(data))
} catch (e: any) {
callback(e.message, null)
}
})
})

Expand Down
2 changes: 2 additions & 0 deletions packages/steam/src/steam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import crypto from 'crypto'
import fs from 'fs'

import axios from 'axios'
// @ts-expect-error no types exist
import Dota2 from 'dota2'
import { Long } from 'mongodb'
import retry from 'retry'
import Steam from 'steam'
// @ts-expect-error no types exist
import steamErrors from 'steam-errors'

import MongoDBSingleton from './MongoDBSingleton.js'
Expand Down

0 comments on commit 0be485c

Please sign in to comment.