From c43060b1439336eaa0f3ac15cd229af5c789bef4 Mon Sep 17 00:00:00 2001 From: Lanta Date: Tue, 14 Nov 2023 15:55:15 +0100 Subject: [PATCH] multiple users possible + wacky --- config/clanmembers.json | 4 +- discord/report_new_matches.ps1 | 2 +- update/update_clan_members.ps1 | 125 ++++++++++++++++++++++----------- 3 files changed, 89 insertions(+), 42 deletions(-) diff --git a/config/clanmembers.json b/config/clanmembers.json index 1c44a5d..129cecf 100644 --- a/config/clanmembers.json +++ b/config/clanmembers.json @@ -8,6 +8,8 @@ "RalphNorris", "Jimbo_The_One", "SquadKiller101", - "Pettie1972" + "Pettie1972", + "HeteKip", + "WackyJacky101" ] } diff --git a/discord/report_new_matches.ps1 b/discord/report_new_matches.ps1 index e2a5276..2ce213d 100644 --- a/discord/report_new_matches.ps1 +++ b/discord/report_new_matches.ps1 @@ -63,7 +63,7 @@ $map_map = @{ } $player_matches = get-content "$scriptroot/../data/player_matches.json" | convertfrom-json -Depth 100 -$new_win_matches = $player_matches.new_win_matches +$new_win_matches = $player_matches[-1].new_win_matches foreach ($winid in $new_win_matches) { diff --git a/update/update_clan_members.ps1 b/update/update_clan_members.ps1 index 1b32f5a..03bf144 100644 --- a/update/update_clan_members.ps1 +++ b/update/update_clan_members.ps1 @@ -24,24 +24,48 @@ else { } -$clanMembersArray = (get-content "$scriptroot/../config/clanmembers.json" | convertfrom-json).clanMembers +$clanMembersArray = (Get-Content "$scriptroot/../config/clanmembers.json" | ConvertFrom-Json).clanMembers + +$clanmemberchunks = @() +$chunk = @() +$chunksize = 10 +$i = 0 + +foreach ($member in $clanMembersArray) { + $chunk += $member + if ($chunk.Count -eq $chunksize) { + $clanmemberchunks += @{ "Chunk$i" = $chunk } + $chunk = @() + $i++ + } +} + +# Add any remaining members to the last chunk +if ($chunk.Count -gt 0) { + $clanmemberchunks += @{ "Chunk$i" = $chunk } +} $clanMembers = $clanMembersArray -join ',' -if ($clanMembersArray.count -gt 10 ) { - write-output "Currently not able to process more then 10 players" - exit -} + $headers = @{ 'accept' = 'application/vnd.api+json' 'Authorization' = "$apiKey" } -try { - $playerinfo = Invoke-RestMethod -Uri "https://api.pubg.com/shards/steam/players?filter[playerNames]=$clanMembers" -Method GET -Headers $headers -} catch { - write-output 'Sleeping for 61 seconds' - start-sleep -Seconds 61 - $playerinfo = Invoke-RestMethod -Uri "https://api.pubg.com/shards/steam/players?filter[playerNames]=$clanMembers" -Method GET -Headers $headers +$playerinfo = @() +foreach ($key in $clanmemberchunks.keys) { + + $clanMembers = $clanmemberchunks.$key -join ',' + $clanMembers + try { + $playerinfo += Invoke-RestMethod -Uri "https://api.pubg.com/shards/steam/players?filter[playerNames]=$clanMembers" -Method GET -Headers $headers + } + catch { + write-output 'Sleeping for 61 seconds' + start-sleep -Seconds 61 + $playerinfo += Invoke-RestMethod -Uri "https://api.pubg.com/shards/steam/players?filter[playerNames]=$clanMembers" -Method GET -Headers $headers + } + } $playerinfo.data | convertto-json -depth 100 | Out-File "$scriptroot/../data/player_data.json" $playerList = @() @@ -57,12 +81,32 @@ $playerinfo.data | ForEach-Object { $playerList -$playeridstring = "" -foreach ($playerid in $playerinfo.data.id) { - $playeridstring += "$playerid," -} -$playeridstring = $playeridstring.Substring(0, $playeridstring.Length - 1) +$playerChunks = @{} +$chunk = @() +$chunksize = 10 +$i = 0 + +foreach ($player in $playerList) { + $chunkName = "Chunk$i" + $chunk += $player + if ($chunk.Count -eq $chunksize) { + $playerChunks[$chunkName] = $chunk + $chunk = @() + $i++ + } +} + +# Add any remaining players to the last chunk +if ($chunk.Count -gt 0) { + $playerChunks["Chunk$i"] = $chunk +} + +$playeridstringarray = @() +foreach ($key in $playerChunks.keys) { + + $playeridstringarray += $playerChunks.$key.PlayerID -join ',' +} $playermodes = @( "solo", @@ -74,44 +118,45 @@ $playermodes = @( ) # Initialize the master hashtable $lifetimestats = @{} - -foreach ($playmode in $playermodes) { - # Fetch stats for the current playmode +foreach ($playeridstring in $playeridstringarray) { + foreach ($playmode in $playermodes) { + # Fetch stats for the current playmode write-output "Getting data for players $playeridstring gameode $playmode" - try{ + try { $stats = Invoke-RestMethod -Uri "https://api.pubg.com/shards/steam/seasons/lifetime/gameMode/$playmode/players?filter[playerIds]=$playeridstring" -Method GET -Headers $headers - } catch { + } + catch { write-output 'sleeping for 61 seconds' start-sleep -Seconds 61 $stats = Invoke-RestMethod -Uri "https://api.pubg.com/shards/steam/seasons/lifetime/gameMode/$playmode/players?filter[playerIds]=$playeridstring" -Method GET -Headers $headers } - # Check if the playmode doesn't exist in the hashtable, then add it - if (-not $lifetimestats.ContainsKey($playmode)) { - $lifetimestats[$playmode] = @{} - } - - foreach ($stat in $stats.data.relationships.player.data.id) { - - # Fetch the player name for the current stat (account ID) from the dictionary - $playerName = $playerList | Where-Object { $_.PlayerID -eq $stat } | Select-Object -ExpandProperty PlayerName - write-output "Getting data for $playerName with gamemode $playmode" - # Fetch the specific stat data for the current stat - $specificStat = ($stats.data | where-object { $_.relationships.player.data.id -eq $stat }).attributes.gamemodestats.$playmode - - # Create a new hashtable entry for the player and insert the specific stat data - if (-not $lifetimestats[$playmode].ContainsKey($playerName)) { - $lifetimestats[$playmode][$playerName] = @{} + # Check if the playmode doesn't exist in the hashtable, then add it + if (-not $lifetimestats.ContainsKey($playmode)) { + $lifetimestats[$playmode] = @{} + } + + foreach ($stat in $stats.data.relationships.player.data.id) { + + # Fetch the player name for the current stat (account ID) from the dictionary + $playerName = $playerList | Where-Object { $_.PlayerID -eq $stat } | Select-Object -ExpandProperty PlayerName + write-output "Getting data for $playerName with gamemode $playmode" + # Fetch the specific stat data for the current stat + $specificStat = ($stats.data | where-object { $_.relationships.player.data.id -eq $stat }).attributes.gamemodestats.$playmode + + # Create a new hashtable entry for the player and insert the specific stat data + if (-not $lifetimestats[$playmode].ContainsKey($playerName)) { + $lifetimestats[$playmode][$playerName] = @{} + } + $lifetimestats[$playmode][$playerName][$stat] = $specificStat } - $lifetimestats[$playmode][$playerName][$stat] = $specificStat } + } - - # Get current date and time $currentDateTime = Get-Date