-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ps1
49 lines (41 loc) · 1.76 KB
/
main.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# check if admin because we require elevated permissions
#Requires -RunAsAdministrator
$discordPath = "$env:localappdata\Discord"
$directories = Get-ChildItem -Path $discordPath -Directory
$currentDate = (Get-Date).ToString("yyyy/MM/dd")
$displayName = "Block Discord from contacting Spotify"
$description = "Blocks discord from contacting spotify so it can't pause your music. Created automatically by Discord Anti-Pauser on $currentDate."
$spotifyServerAddress = "35.186.224.24" # pause API is usually https://api.spotify.com/v1/me/player/pause
foreach ($dir in $directories)
{
# checks if the child count of a directory is equal to 0
$empty = (Get-ChildItem -Path $dir.FullName -Recurse -Directory | Measure-Object | Select-Object -ExpandProperty Count) -eq 0
# if the directory isn't empty, it is the path in which Discord is stored in
if (!($empty))
{
$fullDiscordPath = $discordPath + "\" + $dir + "\Discord.exe"
Write-Host "Found Discord path at $fullDiscordPath"
break
}
}
if (-not $fullDiscordPath)
{
Write-Warning "Could not find Discord.exe!"
exit
}
# 2> $null redirects any errors to be sent to hell (null) so no stinky error pops up
$firewallRuleExists = Get-NetFirewallRule -DisplayName $displayName 2> $null
if ($firewallRuleExists)
{
Remove-NetFirewallRule -DisplayName $displayName
Write-Host "Removed old firewall rule"
}
New-NetFirewallRule -DisplayName $displayName `
-Description $description `
-Direction Outbound `
-Action Block `
-RemoteAddress $spotifyServerAddress `
-RemotePort 443 `
-Protocol TCP `
-Program $fullDiscordPath
Write-Host "Created firewall rule"