diff options
| author | Christine Dodrill <me@christine.website> | 2017-01-04 15:19:25 -0800 |
|---|---|---|
| committer | Christine Dodrill <me@christine.website> | 2017-01-04 15:19:25 -0800 |
| commit | f91dfeb71d8dd638238d3f30be82f3e2b9c290f6 (patch) | |
| tree | e6d885abba34bdd23d5dba271b73331fbdbe3480 | |
| parent | 869a19f6243be43f973b097a089ec358f4cc2946 (diff) | |
| download | x-f91dfeb71d8dd638238d3f30be82f3e2b9c290f6.tar.xz x-f91dfeb71d8dd638238d3f30be82f3e2b9c290f6.zip | |
add discordaway
| -rw-r--r-- | discordaway/main.go | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/discordaway/main.go b/discordaway/main.go new file mode 100644 index 0000000..ff6754c --- /dev/null +++ b/discordaway/main.go @@ -0,0 +1,61 @@ +package main + +import ( + "bytes" + "log" + "os/exec" + "time" + + "github.com/bwmarrin/discordgo" + "github.com/namsral/flag" +) + +var ( + cfg = flag.String("config", "/home/xena/.local/share/within/discordaway.cfg", "configuration file") + username = flag.String("username", "", "Discord username to use") + password = flag.String("password", "", "Discord password to use") +) + +func main() { + flag.Parse() + + dg, err := discordgo.New(*username, *password) + if err != nil { + log.Fatal(err) + } + + log.Println("monitoring tmux status...") + t := time.NewTicker(300 * time.Second) + + ok, err := isTmuxAttached() + log.Println(ok, err) + + for { + select { + case <-t.C: + at, err := isTmuxAttached() + if err != nil { + log.Println(err) + return + } + + if at { + log.Println("Cadey is away, marking as away on Discord") + dg.UpdateStatus(600, "around with reality for some reason") + } else { + log.Println("Cadey is back!!!") + dg.UpdateStatus(0, "") + } + } + } +} + +func isTmuxAttached() (bool, error) { + cmd := exec.Command("/usr/bin/tmux", "ls", "-F", "#{?session_attached,attached,not attached}") + output, err := cmd.Output() + if err != nil { + return false, err + } + + return bytes.HasPrefix(output, []byte("attached")), nil +} |
