diff --git a/SteamPS/Public/API/Get-SteamPlayerBan.ps1 b/SteamPS/Public/API/Get-SteamPlayerBan.ps1 index 98d54e4..6b5b5fd 100644 --- a/SteamPS/Public/API/Get-SteamPlayerBan.ps1 +++ b/SteamPS/Public/API/Get-SteamPlayerBan.ps1 @@ -1,34 +1,32 @@ function Get-SteamPlayerBan { <# - .SYNOPSIS - Returns Community, VAC, and Economy ban statuses for given players. +.SYNOPSIS + Fetches ban information for Steam players. .DESCRIPTION - Returns Community, VAC, and Economy ban statuses for given players. + This cmdlet fetches ban information for Steam players. The information includes whether the players are banned from the Steam Community, have VAC bans, the number of VAC bans, days since the last ban, number of game bans, and economy ban status. .PARAMETER SteamID64 - Comma-delimited list of 64 bit Steam IDs to return player ban information for. - - .PARAMETER OutputFormat - Format of the output. Options are json (default), xml or vdf. + Specifies one or more 64-bit Steam IDs for which to fetch ban information. Enter the Steam IDs as a comma-separated list. .EXAMPLE - Get-SteamPlayerBan -SteamID64 76561197960435530, 76561197960434622 + Get-SteamPlayerBan -SteamID64 76561197960435530,76561197960434622 + + This example fetches ban information for the players with the specified Steam IDs. .INPUTS - Array of int64. + int64[]: Specifies an array of 64-bit integers representing Steam IDs. .OUTPUTS - Returns a string that is either formatted as json, xml or vdf. + Returns objects with the following properties: - players: List of player ban objects for each 64 bit ID requested - - SteamId (string) The player's 64 bit ID. - - CommunityBanned (bool) Indicates whether or not the player is banned from Steam Community. - - VACBanned (bool) Indicates whether or not the player has VAC bans on record. - - NumberOfVACBans (int) Number of VAC bans on record. - - DaysSinceLastBan (int) Number of days since the last ban. - - NumberOfGameBans (int) Number of bans in games, this includes CS:GO Overwatch bans. - - EconomyBan (string) The player's ban status in the economy. If the player has no bans on record the string will be "none", if the player is on probation it will say "probation", etc. + - SteamID64: The player's 64-bit ID. + - CommunityBanned: A boolean indicating whether the player is banned from the Steam Community. + - VACBanned: A boolean indicating whether the player has VAC bans on record. + - NumberOfVACBans: The number of VAC bans on record. + - DaysSinceLastBan: The number of days since the last ban. + - NumberOfGameBans: The number of bans in games, including CS:GO Overwatch bans. + - EconomyBan: The player's ban status in the economy. If the player has no bans on record, the string will be "none". If the player is on probation, it will say "probation", etc. .NOTES Author: Frederik Hjorslev Nylander @@ -42,12 +40,7 @@ [Parameter(Mandatory = $true, HelpMessage = '64 bit Steam ID to return player bans for.', ValueFromPipelineByPropertyName = $true)] - [int64[]]$SteamID64, - - [Parameter(Mandatory = $false, - HelpMessage = 'Format of the output. Options are json (default), xml or vdf.')] - [ValidateSet('json', 'xml', 'vdf')] - [string]$OutputFormat = 'json' + [int64[]]$SteamID64 ) begin { @@ -55,9 +48,33 @@ } process { - $Request = Invoke-WebRequest -Uri "https://api.steampowered.com/ISteamUser/GetPlayerBans/v1/?format=$OutputFormat&key=$(Get-SteamAPIKey)&steamids=$($SteamID64 -join ',')" -UseBasicParsing + $Request = Invoke-RestMethod -Uri 'https://api.steampowered.com/ISteamUser/GetPlayerBans/v1/' -UseBasicParsing -Body @{ + key = Get-SteamAPIKey + steamids = ($SteamID64 -join ',') + } - Write-Output -InputObject $Request.Content + if (-not [string]::IsNullOrEmpty($Request.players.SteamId)) { + foreach ($Item in $Request.players) { + [PSCustomObject]@{ + SteamID64 = [int64]$Item.SteamId + CommunityBanned = $Item.CommunityBanned + VACBanned = $Item.VACBanned + NumberOfVACBans = $Item.NumberOfVACBans + DaysSinceLastBan = $Item.DaysSinceLastBan + NumberOfGameBans = $Item.NumberOfGameBans + EconomyBan = $Item.EconomyBan + } + } + } elseif ([string]::IsNullOrEmpty($Request.players)) { + $Exception = [Exception]::new("SteamID $SteamID64 couldn't be found.") + $ErrorRecord = [System.Management.Automation.ErrorRecord]::new( + $Exception, + 'PlayerNotFound', + [System.Management.Automation.ErrorCategory]::ObjectNotFound, + $Request + ) + $PSCmdlet.WriteError($ErrorRecord) + } } # Process end { diff --git a/Tests/Unit/Public/Get-SteamPlayerBan.Tests.ps1 b/Tests/Unit/Public/Get-SteamPlayerBan.Tests.ps1 new file mode 100644 index 0000000..6e29717 --- /dev/null +++ b/Tests/Unit/Public/Get-SteamPlayerBan.Tests.ps1 @@ -0,0 +1,51 @@ +Describe 'Get-SteamPlayerBan Tests' { + BeforeAll { + . $SteamPSModulePath\Private\API\Get-SteamAPIKey.ps1 + Mock -CommandName Get-SteamAPIKey -ModuleName SteamPS -MockWith { + return $true + } + } + + Context 'With valid Steam ID' { + BeforeAll { + Mock -CommandName Invoke-RestMethod -ModuleName SteamPS -MockWith { + return '{ + "players": [ + { + "SteamId": "76561197983367235", + "CommunityBanned": false, + "VACBanned": false, + "NumberOfVACBans": 0, + "DaysSinceLastBan": 0, + "NumberOfGameBans": 0, + "EconomyBan": "none" + } + ] + }' | ConvertFrom-Json + } + } + + It 'Should return ban information' { + $result = Get-SteamPlayerBan -SteamID64 76561197983367235 + $result | Should -Not -BeNullOrEmpty + $result.SteamID64 | Should -BeExactly 76561197983367235 + $result.CommunityBanned | Should -Be $false + $result.VACBanned | Should -Be $false + $result.NumberOfVACBans | Should -Be 0 + $result.DaysSinceLastBan | Should -Be 0 + $result.NumberOfGameBans | Should -Be 0 + $result.EconomyBan | Should -Be 'none' + } + } + + Context 'With invalid Steam ID' { + BeforeAll { + Mock -CommandName Invoke-RestMethod -ModuleName SteamPS -MockWith { + return '{"players":[{}]}' | ConvertFrom-Json + } + } + It 'Should throw an error' { + { Get-SteamPlayerBan -SteamID64 12345 -ErrorAction Stop } | Should -Throw + } + } +}