From 62cf41435a59d157244badc555bee90b7de77f11 Mon Sep 17 00:00:00 2001 From: Benny Morrison Date: Sun, 17 Mar 2019 04:41:46 -0400 Subject: finished handler: reports total human users with accounts --- main.go | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/main.go b/main.go index 12a954b..a61c764 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,7 @@ import ( "log" "os" "os/exec" + "strconv" "strings" "time" @@ -106,7 +107,7 @@ func main() { } //another basic command/response. required information for the tildeverse if strings.HasPrefix(e.Last(), "!botlist") { - c.Cmd.Reply(e, "Creator: ~a h r i m a n~ :: I'm the assistance bot for tilde.institute. Commands: !hello !join !uptime !users") + c.Cmd.Reply(e, "Creator: ~a h r i m a n~ :: I'm the assistance bot for tilde.institute. Commands: !hello !join !uptime !users !totalusers") return } // when requested by owner, join channel specified @@ -141,18 +142,11 @@ func main() { c.Cmd.Reply(e, out.String()) return } - // number of total users - // bot dies when i run this - // TODO: defuckulate this command + // number of total human users on the server if strings.HasPrefix(e.Last(), "!totalusers") { - users := exec.Command("ls /home | wc -w") - var out bytes.Buffer - users.Stdout = &out - err := users.Run() - if err != nil { - log.Fatalln("Error while running 'ls /home | wc -w'") - } - c.Cmd.Reply(e, out.String()) + userdirs, err := ioutil.ReadDir("/home") + checkerr(err) + c.Cmd.Reply(e, strconv.Itoa(len(userdirs))+" user accounts on ~institute") } }) -- cgit 1.4.1-2-gfad0