From d48e8f01af35aa691b1c4c3609930c55c4ca42a6 Mon Sep 17 00:00:00 2001 From: Thijs Stobbelaar Date: Mon, 13 Nov 2023 20:00:20 +0100 Subject: [PATCH 1/2] failsafe --- discord/report_new_matches.ps1 | 60 +++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/discord/report_new_matches.ps1 b/discord/report_new_matches.ps1 index 3f9294a..df62011 100644 --- a/discord/report_new_matches.ps1 +++ b/discord/report_new_matches.ps1 @@ -1,4 +1,4 @@ -Start-Transcript -Path '/var/log/dtch/report_new_matches.log' -Append +Start-Transcript -Path '/var/log/dtch/report_new_matches.log' -Append if ($PSScriptRoot.length -eq 0) { $scriptroot = Get-Location @@ -73,22 +73,24 @@ foreach ($winid in $new_win_matches) { if ($null -eq $winid) { continue } $winmatches = $player_matches.player_matches | Where-Object { $_.id -eq $winid } $telemetry = (invoke-webrequest @($winmatches.telemetry_url)[0]).content | convertfrom-json | where-object { ($_._T -eq 'LOGPLAYERTAKEDAMAGE') -or ($_._T -eq 'LOGPLAYERKILLV2') } - $winners = @(($winmatches | where-object {$_.stats.winPlace -eq 1}).stats.name) + $winners = @(($winmatches | where-object { $_.stats.winPlace -eq 1 }).stats.name) $2D_replay_url = @($winmatches.telemetry_url)[0] -replace 'https://telemetry-cdn.pubg.com/bluehole-pubg', 'https://chickendinner.gg' $2D_replay_url = $2D_replay_url -replace '-telemetry.json', '' $2D_replay_url = $2D_replay_url + "?follow=$($winners[0])" $match_stats = Invoke-RestMethod -Uri "https://api.pubg.com/shards/steam/matches/$winid" -Method GET -Headers $headers - if($winmatches[0].matchType -eq 'custom'){ + if ($winmatches[0].matchType -eq 'custom') { $players_to_report = $match_stats.included.attributes.stats - }else{ + } + else { $players_to_report = ($match_stats.included.attributes.stats | where-object { $_.winplace -eq 1 }) } - - send-discord -content ":chicken: :chicken: **WINNER WINNER CHICKEN DINNER!!** :chicken: :chicken:" - send-discord -content ":partying_face::partying_face::partying_face: Gefeliciteerd $($winners -join ', ') :partying_face::partying_face::partying_face:" - $match_settings = @" + if ($new_win_matches.count -le 10) { + #fail safe + send-discord -content ":chicken: :chicken: **WINNER WINNER CHICKEN DINNER!!** :chicken: :chicken:" + send-discord -content ":partying_face::partying_face::partying_face: Gefeliciteerd $($winners -join ', ') :partying_face::partying_face::partying_face:" + $match_settings = @" `````` match mode $($winmatches[0].gameMode) match type $($winmatches[0].matchType) @@ -96,18 +98,21 @@ map $($map_map[$winmatches[0].mapName]) id $($winmatches[0].id) `````` "@ - send-discord -content $match_settings - + send-discord -content $match_settings + } + else { + write-output "Something went wrong (more then 10 matches to report)" + } foreach ($player in $players_to_report.name) { - if($null -eq $player){continue} + if ($null -eq $player) { continue } write-output "creating table for player $player" $win_stats += [PSCustomObject]@{ - Name = $player - 'Human dmg' = "$([math]::Round(($telemetry | Where-Object { $_._T -eq 'LOGPLAYERTAKEDAMAGE' -and $_.attacker.name -eq $player -and $_.victim.accountId -notlike "ai.*" -and $_.victim.teamId -ne $_.attacker.teamId } | Measure-Object -Property damage -Sum).Sum))" - 'Human Kills' = "$(($telemetry | Where-Object { $_._T -eq 'LOGPLAYERKILLV2' -and $_.killer.name -eq $player -and $_.victim.accountId -notlike "ai.*" }).count)" - 'Dmg' = "$([math]::Round(($players_to_report | Where-Object { $_.name -eq $player }).damageDealt))" - 'Kills' = "$(($players_to_report | Where-Object { $_.name -eq $player }).kills)" - 'alive' = "$([math]::Round((($players_to_report | Where-Object { $_.name -eq $player }).timeSurvived /60 )))" + Name = $player + 'Human dmg' = "$([math]::Round(($telemetry | Where-Object { $_._T -eq 'LOGPLAYERTAKEDAMAGE' -and $_.attacker.name -eq $player -and $_.victim.accountId -notlike "ai.*" -and $_.victim.teamId -ne $_.attacker.teamId } | Measure-Object -Property damage -Sum).Sum))" + 'Human Kills' = "$(($telemetry | Where-Object { $_._T -eq 'LOGPLAYERKILLV2' -and $_.killer.name -eq $player -and $_.victim.accountId -notlike "ai.*" }).count)" + 'Dmg' = "$([math]::Round(($players_to_report | Where-Object { $_.name -eq $player }).damageDealt))" + 'Kills' = "$(($players_to_report | Where-Object { $_.name -eq $player }).kills)" + 'alive' = "$([math]::Round((($players_to_report | Where-Object { $_.name -eq $player }).timeSurvived /60 )))" } $teamdmg = $telemetry | Where-Object { $_._T -eq 'LOGPLAYERTAKEDAMAGE' -and @@ -130,18 +135,21 @@ id $($winmatches[0].id) } + if ($new_win_matches.count -le 10) { + $content_winstats = '```' + ($win_stats | Format-Table | out-string) + '```' + send-discord -content $content_winstats - $content_winstats = '```' + ($win_stats | Format-Table | out-string) + '```' - send-discord -content $content_winstats + if ($victims.count -ge 1) { + send-discord -content ":skull::skull: Helaas hebben we deze keer ook team killers :skull::skull: " + $content_victims = '```' + ($victims | Format-Table | out-string) + '```' + send-discord -content $content_victims + } - if($victims.count -ge 1){ - send-discord -content ":skull::skull: Helaas hebben we deze keer ook team killers :skull::skull: " - $content_victims = '```' + ($victims | Format-Table | out-string) + '```' - send-discord -content $content_victims + send-discord -content "[2D replay](<$2D_replay_url>)" + } + else { + write-output "Something went wrong (more then 10 matches to report)" } - - send-discord -content "[2D replay](<$2D_replay_url>)" - $legenda = ' ``` dmg_h = Schade aangericht aan echte spelers From 2ea734b8d50340b0a8d3b6b6a9ebbe52f3669b53 Mon Sep 17 00:00:00 2001 From: Thijs Stobbelaar Date: Mon, 13 Nov 2023 20:03:34 +0100 Subject: [PATCH 2/2] updates --- discord/report_new_matches.ps1 | 2 +- update/matchparser.ps1 | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/discord/report_new_matches.ps1 b/discord/report_new_matches.ps1 index df62011..8267c41 100644 --- a/discord/report_new_matches.ps1 +++ b/discord/report_new_matches.ps1 @@ -1,4 +1,4 @@ -Start-Transcript -Path '/var/log/dtch/report_new_matches.log' -Append +Start-Transcript -Path '/var/log/dtch/report_new_matches.log' -Append if ($PSScriptRoot.length -eq 0) { $scriptroot = Get-Location diff --git a/update/matchparser.ps1 b/update/matchparser.ps1 index cfbadee..13f6315 100644 --- a/update/matchparser.ps1 +++ b/update/matchparser.ps1 @@ -11,8 +11,9 @@ else { . $scriptroot\..\includes\ps1\lockfile.ps1 new-lock - - +##SETTINGS +$monthsback = -1 # how many months back to look for matches +##END OF SETTINGS function Get-Change { param ( [double]$OldWinRatio, @@ -142,7 +143,7 @@ foreach ($player in $all_player_matches) { $killstats = @() $matchfiles = Get-ChildItem "$scriptroot/../data/killstats/" -File -Filter *.json -$last_month = (get-date).AddMonths(-1) +$last_month = (get-date).AddMonths($monthsback) foreach ($file in $matchfiles) { $json = get-content $file | ConvertFrom-Json if ($json.created -gt $last_month) {