Created
July 1, 2022 00:03
-
-
Save aelxxs/92026f1e9837c598ff434fe819fbac70 to your computer and use it in GitHub Desktop.
[Windows]: Battery status for Lanyard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # REPLACE :id with your Discord ID | |
| # REPLACE :key with your Lanyard API Key | |
| # TASK: run every minute | |
| $endpoint = "https://api.lanyard.rest/v1/users/:id/kv/battery" | |
| function Get-ChargingStatus { | |
| return (Get-WmiObject -Class BatteryStatus -Namespace root\wmi).Charging | |
| } | |
| function Get-Percentage { | |
| return (Get-WmiObject -Class Win32_Battery).EstimatedChargeRemaining | |
| } | |
| $body = @{ | |
| isCharging=Get-ChargingStatus; | |
| percentage=Get-Percentage; | |
| } | ConvertTo-Json | |
| $auth = @{ | |
| "Authorization"=":key" | |
| "Content-Type"="application/json" | |
| } | |
| Invoke-WebRequest -Uri $endpoint -Method PUT -Headers $auth -Body $body |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment