diff --git a/packages/dota/src/dota/events/minimap/parser.ts b/packages/dota/src/dota/events/minimap/parser.ts index 8300fedd..f50c52b2 100644 --- a/packages/dota/src/dota/events/minimap/parser.ts +++ b/packages/dota/src/dota/events/minimap/parser.ts @@ -200,13 +200,21 @@ class MinimapParser { } } + if (!data.hero || !data.player || !data.map || !data.minimap) { + return { + status: { + active: false, + }, + } + } + // Parse Status const status: any = { active: true, - paused: this.isGamePaused(data.map!), - playing: this.isPlaying(data.player!), - hero: this.isPlaying(data.player!) ? data.hero?.name : data.hero?.team2?.player0.name, - team: this.isPlaying(data.player!) ? data.player?.team_name : 'radiant', + paused: this.isGamePaused(data.map), + playing: this.isPlaying(data.player), + hero: this.isPlaying(data.player) ? data.hero?.name : data.hero?.team2?.player0.name, + team: this.isPlaying(data.player) ? data.player?.team_name : 'radiant', } // Parse Minimap @@ -219,10 +227,11 @@ class MinimapParser { tp: [], scan: [], } - const entities = Object.keys(data.minimap!) + const entities = Object.keys(data.minimap) entities.forEach((key) => { const entity = data.minimap?.[key] + if (!entity) return // Heroes if ( @@ -285,5 +294,4 @@ class MinimapParser { } } -const minimapParser = new MinimapParser() -export default minimapParser +export default MinimapParser diff --git a/packages/steam/src/steam.ts b/packages/steam/src/steam.ts index 00fd56eb..2152888b 100644 --- a/packages/steam/src/steam.ts +++ b/packages/steam/src/steam.ts @@ -47,7 +47,7 @@ Dota2.Dota2Client.prototype.spectateFriendGame = function ( friend: { steam_id: number; live: boolean }, callback: any, ) { - callback = callback || null + const localCallback = callback || null if (!this._gcReady) { logger.info("[STEAM] GC not ready, please listen for the 'ready' event.") return null @@ -58,7 +58,7 @@ Dota2.Dota2Client.prototype.spectateFriendGame = function ( Dota2.schema.EDOTAGCMsg.k_EMsgGCSpectateFriendGame, payload, onGCSpectateFriendGameResponse, - callback, + localCallback, ) } @@ -428,7 +428,7 @@ class Dota { (oldest, [key, entry]) => { if (!oldest) return key // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - return entry.timestamp < this.cache.get(oldest)?.timestamp ? key : oldest + return entry.timestamp < (this.cache.get(oldest)?.timestamp || 0) ? key : oldest }, null as number | null, )