go: server: Implement active endpoint

master
Luther Wen Xu 2019-10-17 17:08:57 +07:00
parent 1963c773d6
commit 27158b2afb
Signed by: chanbakjsd
GPG Key ID: B7D77E3E9D102B70
1 changed files with 24 additions and 0 deletions

@ -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)
}