diff options
author | Benny Morrison <benmorrison@ttm.sh> | 2019-03-16 00:38:44 -0400 |
---|---|---|
committer | Benny Morrison <benmorrison@ttm.sh> | 2019-03-16 00:38:44 -0400 |
commit | 39a58b2ad538066ea5ebe77cbce9c79878c398e6 (patch) | |
tree | 3e7314e209438a26c95fab627dc489dcafc8ff90 | |
parent | ff4bdd49040864ac4b6e9e8298bb9d5fc59453e7 (diff) | |
download | goofbot-39a58b2ad538066ea5ebe77cbce9c79878c398e6.tar.gz |
error handling for !users/!uptime
-rw-r--r-- | main.go | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/main.go b/main.go index 1e2b94a..82ca0fe 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "bytes" "log" "os" "os/exec" @@ -51,14 +52,26 @@ func main() { // respond with uptime / load if strings.HasPrefix(e.Last(), "!uptime") { uptime := exec.Command("uptime") - c.Cmd.Reply(e, uptime) + var out bytes.Buffer + uptime.Stdout = &out + err := uptime.Run() + if err != nil { + log.Fatalln("Error while running 'uptime'") + } + c.Cmd.Reply(e, out.String()) return } // respond with currently connected users // TODO: prepend names with _ to avoid pings in irc if strings.HasPrefix(e.Last(), "!users") { users := exec.Command("who", "-q") - c.Cmd.Reply(e, users) + var out bytes.Buffer + users.Stdout = &out + err := users.Run() + if err != nil { + log.Fatalln("Error while running 'who -q'") + } + c.Cmd.Reply(e, out.String()) return } }) |