Skip to content

Commit 7e9149e

Browse files
Ported hangover script to golang
1 parent eb7f1d8 commit 7e9149e

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

go/hangover.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
"math/rand"
7+
"os"
8+
9+
"github.com/codeskyblue/go-sh"
10+
"github.com/subosito/twilio"
11+
)
12+
13+
const my_number string = "+xxxxx"
14+
const boss_number string = "+yyyyy"
15+
16+
func main() {
17+
//exit if sessions with my username are found
18+
_, err := sh.Command("who").Command("grep", "my_username").Output()
19+
if err != nil {
20+
os.Exit(1)
21+
}
22+
23+
//Grab Twilio ID and token from environment variables
24+
Account_Sid := os.Getenv("TWILIO_ACCOUNT_SID")
25+
Auth_Token := os.Getenv("TWILIO_AUTH_TOKEN")
26+
27+
//create the reasons slice and append reasons to it
28+
reasons := make([]string, 0)
29+
reasons = append(reasons,
30+
"Locked out",
31+
"Pipes broke",
32+
"Food poisoning",
33+
"Not feeling well")
34+
35+
// Initialize Twilio client and send message
36+
client := twilio.NewClient(Account_Sid, Auth_Token, nil)
37+
message := fmt.Sprint("Gonna work from home...", reasons[rand.Intn(len(reasons))])
38+
39+
params := twilio.MessageParams{
40+
Body: message,
41+
}
42+
s, resp, err := client.Messages.Send(my_number, boss_number, params)
43+
44+
if err == nil {
45+
log.Fatal(s, resp, err)
46+
}
47+
}

0 commit comments

Comments
 (0)