about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBenny Morrison <benmorrison@ttm.sh>2019-03-17 04:41:46 -0400
committerBenny Morrison <benmorrison@ttm.sh>2019-03-17 04:41:46 -0400
commit62cf41435a59d157244badc555bee90b7de77f11 (patch)
tree9beef1289d980e32fd5d61bf9ed78e8f2ab12628
parentb40e65f379a629297a48bc49c43ef28c41794aa4 (diff)
downloadgoofbot-62cf41435a59d157244badc555bee90b7de77f11.tar.gz
finished handler: reports total human users with accounts
-rw-r--r--main.go18
1 files 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")
 		}
 	})