Add user badges
Add badges for admins and mods. Admins get a red badge, and mods get a green one. Normal users do not get a badge.
This commit is contained in:
parent
1b8dd76a45
commit
7dff29b152
|
@ -4,6 +4,7 @@
|
||||||
*.dll
|
*.dll
|
||||||
*.so
|
*.so
|
||||||
*.dylib
|
*.dylib
|
||||||
|
*.aseprite
|
||||||
|
|
||||||
# Test binary, built with `go test -c`
|
# Test binary, built with `go test -c`
|
||||||
*.test
|
*.test
|
||||||
|
|
|
@ -83,7 +83,10 @@ func (cl *Client) NewMsg(data common.ClientData) {
|
||||||
|
|
||||||
response := commands.RunCommand(cmd, args, cl)
|
response := commands.RunCommand(cmd, args, cl)
|
||||||
if response != "" {
|
if response != "" {
|
||||||
err := cl.SendChatData(common.NewChatMessage("", "", ParseEmotes(response), common.MsgCommandResponse))
|
err := cl.SendChatData(common.NewChatMessage("", "",
|
||||||
|
ParseEmotes(response),
|
||||||
|
common.CmdUser,
|
||||||
|
common.MsgCommandResponse))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error command results %v\n", err)
|
fmt.Printf("Error command results %v\n", err)
|
||||||
}
|
}
|
||||||
|
@ -125,7 +128,8 @@ func (cl *Client) Send(data common.ChatData) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cl *Client) SendServerMessage(s string) error {
|
func (cl *Client) SendServerMessage(s string) error {
|
||||||
err := cl.SendChatData(common.NewChatMessage("", ColorServerMessage, s, common.MsgServer))
|
err := cl.SendChatData(common.NewChatMessage("",
|
||||||
|
ColorServerMessage, s, common.CmdUser, common.MsgServer))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could send server message to %s: %s; Message: %s\n", cl.name, err, s)
|
return fmt.Errorf("could send server message to %s: %s; Message: %s\n", cl.name, err, s)
|
||||||
}
|
}
|
||||||
|
|
12
chatroom.go
12
chatroom.go
|
@ -260,7 +260,15 @@ func (cr *ChatRoom) AddMsg(from *Client, isAction, isServer bool, msg string) {
|
||||||
t = common.MsgServer
|
t = common.MsgServer
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := common.NewChatMessage(from.name, from.color, msg, t)()
|
lvl := common.CmdUser
|
||||||
|
if from.IsMod {
|
||||||
|
lvl = common.CmdMod
|
||||||
|
}
|
||||||
|
if from.IsAdmin {
|
||||||
|
lvl = common.CmdAdmin
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := common.NewChatMessage(from.name, from.color, msg, lvl, t)()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error encoding chat message: %s", err)
|
fmt.Printf("Error encoding chat message: %s", err)
|
||||||
return
|
return
|
||||||
|
@ -288,7 +296,7 @@ func (cr *ChatRoom) AddCmdMsg(command common.CommandType, args []string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cr *ChatRoom) AddModNotice(message string) {
|
func (cr *ChatRoom) AddModNotice(message string) {
|
||||||
data, err := common.NewChatMessage("", "", message, common.MsgNotice)()
|
data, err := common.NewChatMessage("", "", message, common.CmdUser, common.MsgNotice)()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error encoding notice: %v", err)
|
fmt.Printf("Error encoding notice: %v", err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -73,6 +73,7 @@ type DataMessage struct {
|
||||||
From string
|
From string
|
||||||
Color string
|
Color string
|
||||||
Message string
|
Message string
|
||||||
|
Level CommandLevel
|
||||||
Type MessageType
|
Type MessageType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,19 +95,28 @@ func (dc DataMessage) HTML() string {
|
||||||
|
|
||||||
case MsgCommandResponse:
|
case MsgCommandResponse:
|
||||||
return `<div class="command">` + dc.Message + `</div>`
|
return `<div class="command">` + dc.Message + `</div>`
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return `<div><span class="name" style="color:` + dc.Color + `">` + dc.From +
|
badge := ""
|
||||||
|
switch dc.Level {
|
||||||
|
case CmdMod:
|
||||||
|
badge = `<img src="/static/img/mod.png" class="badge" />`
|
||||||
|
case CmdAdmin:
|
||||||
|
badge = `<img src="/static/img/admin.png" class="badge" />`
|
||||||
|
}
|
||||||
|
return `<div>` + badge + `<span class="name" style="color:` + dc.Color + `">` + dc.From +
|
||||||
`</span><b>:</b> <span class="msg">` + dc.Message + `</span></div>`
|
`</span><b>:</b> <span class="msg">` + dc.Message + `</span></div>`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewChatMessage(name, color, msg string, msgtype MessageType) NewChatDataFunc {
|
func NewChatMessage(name, color, msg string, lvl CommandLevel, msgtype MessageType) NewChatDataFunc {
|
||||||
return func() (ChatData, error) {
|
return func() (ChatData, error) {
|
||||||
return newChatData(DTChat, DataMessage{
|
return newChatData(DTChat, DataMessage{
|
||||||
From: name,
|
From: name,
|
||||||
Color: color,
|
Color: color,
|
||||||
Message: msg,
|
Message: msg,
|
||||||
Type: msgtype,
|
Type: msgtype,
|
||||||
|
Level: lvl,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,6 +63,12 @@ func wsStaticFiles(w http.ResponseWriter, r *http.Request) {
|
||||||
http.ServeFile(w, r, "./static/"+goodPath)
|
http.ServeFile(w, r, "./static/"+goodPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func wsImages(w http.ResponseWriter, r *http.Request) {
|
||||||
|
base := filepath.Base(r.URL.Path)
|
||||||
|
fmt.Println("[img] ", base)
|
||||||
|
http.ServeFile(w, r, "./static/img/"+base)
|
||||||
|
}
|
||||||
|
|
||||||
func wsEmotes(w http.ResponseWriter, r *http.Request) {
|
func wsEmotes(w http.ResponseWriter, r *http.Request) {
|
||||||
emotefile := filepath.Base(r.URL.Path)
|
emotefile := filepath.Base(r.URL.Path)
|
||||||
http.ServeFile(w, r, "./static/emotes/"+emotefile)
|
http.ServeFile(w, r, "./static/emotes/"+emotefile)
|
||||||
|
|
1
main.go
1
main.go
|
@ -30,6 +30,7 @@ func main() {
|
||||||
http.HandleFunc("/ws", wsHandler)
|
http.HandleFunc("/ws", wsHandler)
|
||||||
http.HandleFunc("/static/js/", wsStaticFiles)
|
http.HandleFunc("/static/js/", wsStaticFiles)
|
||||||
http.HandleFunc("/static/css/", wsStaticFiles)
|
http.HandleFunc("/static/css/", wsStaticFiles)
|
||||||
|
http.HandleFunc("/static/img/", wsImages)
|
||||||
http.HandleFunc("/static/main.wasm", wsStaticFiles)
|
http.HandleFunc("/static/main.wasm", wsStaticFiles)
|
||||||
http.HandleFunc("/emotes/", wsEmotes)
|
http.HandleFunc("/emotes/", wsEmotes)
|
||||||
http.HandleFunc("/favicon.ico", wsStaticFiles)
|
http.HandleFunc("/favicon.ico", wsStaticFiles)
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 159 B |
Binary file not shown.
After Width: | Height: | Size: 166 B |
Loading…
Reference in New Issue