diff --git a/GoBot/server/hub.go b/GoBot/server/hub.go index 1492b70..7a4aa35 100644 --- a/GoBot/server/hub.go +++ b/GoBot/server/hub.go @@ -2,9 +2,12 @@ package server import ( "fmt" + "strconv" "strings" "github.com/gorilla/websocket" + + "TerraOceanBot/db" ) var clients = make(map[*websocket.Conn]bool) @@ -31,6 +34,27 @@ func handleIncomingMessage(who *websocket.Conn, msg string) { fmt.Println(connectedUsers) who.WriteMessage(websocket.TextMessage, []byte("leave "+message[1])) } + case "active": + if len(message) < 3 { + return + } + arg := strings.Split(msg, " ") + arg[1] = strings.Join(arg[1:], " ") + id, err := db.GetDiscordID(arg[1]) + if err != nil { + fmt.Println(err) + return + } + value, err := strconv.Atoi(arg[len(arg)-1]) + if err != nil { + fmt.Println(err) + return + } + err = db.AddActiveLevel(id, value) + if err != nil { + fmt.Println(err) + return + } default: fmt.Println("Unknown message:" + msg) }