Skip to content

Commit

Permalink
fixed crash when player has placement matches remaining
Browse files Browse the repository at this point in the history
  • Loading branch information
sruusk committed Jun 29, 2022
1 parent e9ea457 commit 091c01a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "esea-scraper",
"version": "1.0.9",
"version": "1.1.0",
"description": "Pull ESEA profile data",
"main": "dist/index.cjs.js",
"typings": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/player.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('The player scrapers', () => {

it('should return handle 10 simultaneous requests (status command)', async () => {
const steamIDs = [
'2742648',
'974465',
'2746569',
'440390',
'2742648',
Expand Down
9 changes: 7 additions & 2 deletions src/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ function getStat(
throw new Error(`No ${statName} stat found`);
}

function nullOrUndefined(value: any): boolean {
return value === null || value === undefined;
}

export async function getPlayer(
this: EseaScraper,
eseaProfileId: string | bigint
Expand Down Expand Up @@ -81,6 +85,7 @@ export async function getPlayer(
const kills = getStat(stats.stats, parseInt, 'all.frags');
const deaths = getStat(stats.stats, parseInt, 'all.deaths');
const kd = kills / deaths;
this.debug(`kills: ${kills}, deaths: ${deaths}, kd: ${kd}`);

return {
summary: {
Expand All @@ -98,8 +103,8 @@ export async function getPlayer(
wins: wins,
kills: kills,
deaths: deaths,
rank: wins > 5 ? profile.rank.current.rank : undefined,
mmr: wins > 5 ? parseInt(profile.rank.current.mmr, 10) : undefined,
rank: nullOrUndefined(profile.rank.placement_matches_remaining) ? profile.rank.current.rank : undefined,
mmr: nullOrUndefined(profile.rank.placement_matches_remaining) ? parseInt(profile.rank.current.mmr, 10) : undefined,
matches: totalGames,
headshotRate: getStat(stats.stats, parseFloat, 'all.hs_percentage'),
averageDamageRound: getStat(stats.stats, parseFloat, 'all.adr'),
Expand Down

0 comments on commit 091c01a

Please sign in to comment.