From 9f2f0f88e4cafc81ee6a57995cdbf805545e9fcb Mon Sep 17 00:00:00 2001 From: michaelgov-ctrl <81777732+michaelgov-ctrl@users.noreply.github.com> Date: Tue, 25 Jul 2023 23:28:38 -0400 Subject: [PATCH] Create Fucking-Coffee.psm1 Alternate version, most of the currently published branch doesn't work. OrderedHashTable is not necessary just seemed like a cleaner solution and the helper function seemed unnecessary --- powershell/Fucking-Coffee.psm1 | 45 ++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 powershell/Fucking-Coffee.psm1 diff --git a/powershell/Fucking-Coffee.psm1 b/powershell/Fucking-Coffee.psm1 new file mode 100644 index 00000000..3b8a80f5 --- /dev/null +++ b/powershell/Fucking-Coffee.psm1 @@ -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() + + } + +}