Skip to content

Commit eb7f1d8

Browse files
committed
Merge pull request NARKOZ#68 from alexesprit/powershell
Improvements of `smack_my_bitch_up.ps1`
2 parents fe4b87d + fedb6fa commit eb7f1d8

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

powershell/smack_my_bitch_up.ps1

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,33 @@ if ($DAYOFWEEK -eq 6 -or $DAYOFWEEK -eq 7) {
66
}
77

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

1313
# Phone numbers
1414
$MY_NUMBER='+xxx'
1515
$HER_NUMBER='+xxx'
1616

17-
$TWILIO_ACCOUNT_SID = 'xxx'
18-
$TWILIO_AUTH_TOKEN = 'xxx'
19-
20-
$REASONS=
17+
$REASONS =
2118
'Working hard',
2219
'Gotta ship this feature',
2320
'Someone fucked the system again'
21+
$reason = $REASONS | Get-Random
22+
$message = "Late at work. $reason."
23+
24+
$API_URL = "https://api.twilio.com/2010-04-01/Accounts/$env:TWILIO_ACCOUNT_SID/Messages"
25+
$BASE64AUTHINFO = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $env:TWILIO_ACCOUNT_SID,$env:TWILIO_AUTH_TOKEN)))
26+
$body = @{
27+
From = $MY_NUMBER;
28+
To = $HER_NUMBER;
29+
Body = $message;
30+
}
2431

25-
$RAND = Get-Random -Maximum $REASONS.Count
26-
27-
$MSG="Late at work. $REASONS[$RAND]"
28-
29-
30-
$BASE64AUTHINFO = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $TWILIO_ACCOUNT_SID,$TWILIO_AUTH_TOKEN)))
31-
32-
#Send a text messag and Log errors
32+
#Send a text message and Log errors
3333
try{
34-
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
34+
Invoke-RestMethod -Method Post -Headers @{Authorization=("Basic {0}" -f $BASE64AUTHINFO)} $API_URL -Body $body > $null
3535
}
3636
catch{
3737
Write-Host "Failed to send SMS: $_"
3838
}
39-

0 commit comments

Comments
 (0)