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
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,6 +4,7 @@
|
||||
*.dll
|
||||
*.so
|
||||
*.dylib
|
||||
*.aseprite
|
||||
|
||||
# Test binary, built with `go test -c`
|
||||
*.test
|
||||
|
@ -83,7 +83,10 @@ func (cl *Client) NewMsg(data common.ClientData) {
|
||||
|
||||
response := commands.RunCommand(cmd, args, cl)
|
||||
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 {
|
||||
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 {
|
||||
err := cl.SendChatData(common.NewChatMessage("", ColorServerMessage, s, common.MsgServer))
|
||||
err := cl.SendChatData(common.NewChatMessage("",
|
||||
ColorServerMessage, s, common.CmdUser, common.MsgServer))
|
||||
if err != nil {
|
||||
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
|
||||
}
|
||||
|
||||
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 {
|
||||
fmt.Printf("Error encoding chat message: %s", err)
|
||||
return
|
||||
@ -288,7 +296,7 @@ func (cr *ChatRoom) AddCmdMsg(command common.CommandType, args []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 {
|
||||
fmt.Printf("Error encoding notice: %v", err)
|
||||
return
|
||||
|
@ -73,6 +73,7 @@ type DataMessage struct {
|
||||
From string
|
||||
Color string
|
||||
Message string
|
||||
Level CommandLevel
|
||||
Type MessageType
|
||||
}
|
||||
|
||||
@ -94,19 +95,28 @@ func (dc DataMessage) HTML() string {
|
||||
|
||||
case MsgCommandResponse:
|
||||
return `<div class="command">` + dc.Message + `</div>`
|
||||
|
||||
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>`
|
||||
}
|
||||
}
|
||||
|
||||
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 newChatData(DTChat, DataMessage{
|
||||
From: name,
|
||||
Color: color,
|
||||
Message: msg,
|
||||
Type: msgtype,
|
||||
Level: lvl,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -63,6 +63,12 @@ func wsStaticFiles(w http.ResponseWriter, r *http.Request) {
|
||||
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) {
|
||||
emotefile := filepath.Base(r.URL.Path)
|
||||
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("/static/js/", wsStaticFiles)
|
||||
http.HandleFunc("/static/css/", wsStaticFiles)
|
||||
http.HandleFunc("/static/img/", wsImages)
|
||||
http.HandleFunc("/static/main.wasm", wsStaticFiles)
|
||||
http.HandleFunc("/emotes/", wsEmotes)
|
||||
http.HandleFunc("/favicon.ico", wsStaticFiles)
|
||||
|
BIN
static/img/admin.png
Normal file
BIN
static/img/admin.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 159 B |
BIN
static/img/mod.png
Normal file
BIN
static/img/mod.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 166 B |
Loading…
Reference in New Issue
Block a user