From 5c8421d00f36e1ae9ae29e4d9fa2b938cdd64a1a Mon Sep 17 00:00:00 2001 From: Thijs Stobbelaar Date: Thu, 23 Nov 2023 21:46:35 +0100 Subject: [PATCH] trycatch --- discord/report_new_matches.ps1 | 7 ++++++- update/get_matches.ps1 | 27 +++++++++++++++++++-------- update/matchparser.ps1 | 16 ++++++++++++---- 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/discord/report_new_matches.ps1 b/discord/report_new_matches.ps1 index d90ea59..11cb8a9 100644 --- a/discord/report_new_matches.ps1 +++ b/discord/report_new_matches.ps1 @@ -62,7 +62,12 @@ $map_map = @{ "Tiger_Main" = "Taego" } -$player_matches = get-content "$scriptroot/../data/player_matches.json" | convertfrom-json -Depth 100 +try { + $player_matches = get-content "$scriptroot/../data/player_matches.json" | convertfrom-json -Depth 100 +} +catch { + Write-Output 'Unable to read file exitin' +} $new_win_matches = $player_matches[-1].new_win_matches diff --git a/update/get_matches.ps1 b/update/get_matches.ps1 index 4f0202f..793e36f 100644 --- a/update/get_matches.ps1 +++ b/update/get_matches.ps1 @@ -26,7 +26,13 @@ $headers = @{ 'Authorization' = "$apiKey" } $player_matches = @() -$player_data = get-content "$scriptroot/../data/player_data.json" | convertfrom-json -Depth 100 +try { + $player_data = get-content "$scriptroot/../data/player_data.json" | convertfrom-json -Depth 100 +} +catch { + Write-Output 'Unable to read file exitin' + exit +} foreach ($player in $player_data) { @@ -66,8 +72,13 @@ foreach ($player in $player_data) { } if (test-path "$scriptroot/../data/player_matches.json") { - try{$old_player_data = get-content "$scriptroot/../data/player_matches.json" | convertfrom-json -Depth 100} - catch {exit} + try { + $old_player_data = get-content "$scriptroot/../data/player_matches.json" | convertfrom-json -Depth 100 + } + catch { + Write-Output 'Unable to read file exitin' + exit + } $new_ids = ($player_matches.player_matches | where-object { $_.stats.winplace -eq 1 }).id $old_ids = ($old_player_data.player_matches | where-object { $_.stats.winplace -eq 1 }).id $new_win_matches = ((Compare-Object -ReferenceObject $old_ids -DifferenceObject $new_ids) | Where-Object { $_.SideIndicator -eq '=>' }).InputObject | Select-Object -Unique @@ -111,11 +122,11 @@ foreach ($file in $matchfiles) { if ($null -ne $player_matches_cached) { $player_matches_object += [PSCustomObject]@{ matchType = $filecontent.data.attributes.matchType - gameMode = $filecontent.data.attributes.gameMode - createdAt = $filecontent.data.attributes.createdAt - mapName = $filecontent.data.attributes.mapName - id = $filecontent.data.id - stats = @($player_matches_cached) + gameMode = $filecontent.data.attributes.gameMode + createdAt = $filecontent.data.attributes.createdAt + mapName = $filecontent.data.attributes.mapName + id = $filecontent.data.id + stats = @($player_matches_cached) } } write-output "NEW $matchfiledate" diff --git a/update/matchparser.ps1 b/update/matchparser.ps1 index c1f8eca..7a113e6 100644 --- a/update/matchparser.ps1 +++ b/update/matchparser.ps1 @@ -46,7 +46,7 @@ function get-killstats { $gameMode ) - $kills = $telemetry | where-object { $_.killer.name -eq $player_name -and $_._T -eq 'LOGPLAYERKILLV2'} + $kills = $telemetry | where-object { $_.killer.name -eq $player_name -and $_._T -eq 'LOGPLAYERKILLV2' } $HumanDmg = $([math]::Round(($telemetry | Where-Object { $_._T -eq 'LOGPLAYERTAKEDAMAGE' -and $_.attacker.name -eq $player_name -and $_.victim.accountId -notlike "ai.*" -and $_.victim.teamId -ne $_.attacker.teamId } | Measure-Object -Property damage -Sum).Sum)) return @{ playername = $player_name @@ -93,7 +93,15 @@ else { $oldstats = @() } -$all_player_matches = get-content "$scriptroot/../data/player_matches.json" | convertfrom-json -Depth 100 +try { + $all_player_matches = get-content "$scriptroot/../data/player_matches.json" | convertfrom-json -Depth 100 +} +catch { + Write-Output 'Unable to read file exitin' + exit +} + + foreach ($player in $all_player_matches) { if ($player.psobject.properties.name -eq 'new_win_matches') { @@ -166,10 +174,10 @@ function Get-MatchStatsPlayer { if ($null -eq $player) { continue } - if($GameMode){ + if ($GameMode) { $filterProperty = 'gameMode' } - if($MatchType){ + if ($MatchType) { $filterProperty = 'matchType' } $deaths = (($killstats.stats | where-object { $_.playername -eq $player -and $_.$filterProperty -like $typemodevalue }).deaths | Measure-Object -sum).sum -- 2.49.1