This commit is contained in:
michaelgov-ctrl 2023-07-25 23:29:25 -04:00 committed by GitHub
commit 3d54105ab8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -0,0 +1,45 @@
Function Fucking-Coffee {
[CmdletBinding()]
Param(
[Parameter(Position = 0,Mandatory = $true)]
[ipaddress]$CoffeMachineIp,
[Parameter(Position = 1,Mandatory = $true)]
[int]$Port,
[Parameter(Position = 2,Mandatory = $true)]
[string]$Password
)
if ($env:Username.Count -lt 1) {
break
}
$CommandTimeTable = [ordered]@{
$Password = 17
"sys brew" = 24
"sys pour" = 1
}
$TcpClient = New-Object System.Net.Sockets.TcpClient
$TcpClient.Connect($CoffeMachineIp, $Port)
if ($TcpClient.Connected -eq $true) {
$Stream = $TcpClient.GetStream()
#Start issuing the commands based on $CommandTimeTable values
foreach ( $CommandTimePair in $CommandTimeTable.GetEnumerator() ) {
[byte[]]$CommandBytes = [text.encoding]::ASCII.GetBytes($CommandTimePair.Name)
$Stream.Write($CommandBytes,0,$CommandBytes.Length)
$Stream.Flush()
Start-Sleep -Seconds $CommandTimePair.Value
}
$TcpClient.Dispose()
$Stream.Dispose()
}
}