Skip to content

Commit

Permalink
Merge pull request NARKOZ#68 from alexesprit/powershell
Browse files Browse the repository at this point in the history
Improvements of `smack_my_bitch_up.ps1`
  • Loading branch information
NARKOZ committed Nov 29, 2015
2 parents fe4b87d + fedb6fa commit eb7f1d8
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions powershell/smack_my_bitch_up.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,33 @@ if ($DAYOFWEEK -eq 6 -or $DAYOFWEEK -eq 7) {
}

# Exit early if no sessions with my username are found
if ((QWINSTA $env:USERNAME | measure).Count -gt 0){
if (-not (QWINSTA | FINDSTR $env:USERNAME)) {
return
}

# Phone numbers
$MY_NUMBER='+xxx'
$HER_NUMBER='+xxx'

$TWILIO_ACCOUNT_SID = 'xxx'
$TWILIO_AUTH_TOKEN = 'xxx'

$REASONS=
$REASONS =
'Working hard',
'Gotta ship this feature',
'Someone fucked the system again'
$reason = $REASONS | Get-Random
$message = "Late at work. $reason."

$API_URL = "https://api.twilio.com/2010-04-01/Accounts/$env:TWILIO_ACCOUNT_SID/Messages"
$BASE64AUTHINFO = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $env:TWILIO_ACCOUNT_SID,$env:TWILIO_AUTH_TOKEN)))
$body = @{
From = $MY_NUMBER;
To = $HER_NUMBER;
Body = $message;
}

$RAND = Get-Random -Maximum $REASONS.Count

$MSG="Late at work. $REASONS[$RAND]"


$BASE64AUTHINFO = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $TWILIO_ACCOUNT_SID,$TWILIO_AUTH_TOKEN)))

#Send a text messag and Log errors
#Send a text message and Log errors
try{
Invoke-RestMethod -Method Post -Headers @{Authorization=("Basic {0}" -f $BASE64AUTHINFO)} "https://api.twilio.com/2010-04-01/Accounts/$TWILIO_ACCOUNT_SID/Messages" -Body "From=$MY_NUMBER&To=$HER_NUMBER&Body=$MSG" > $null
Invoke-RestMethod -Method Post -Headers @{Authorization=("Basic {0}" -f $BASE64AUTHINFO)} $API_URL -Body $body > $null
}
catch{
Write-Host "Failed to send SMS: $_"
}

0 comments on commit eb7f1d8

Please sign in to comment.