-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmessage.go
49 lines (41 loc) · 901 Bytes
/
message.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"fmt"
"regexp"
"strings"
)
type Message struct {
MCUser *MCUser
Text string
Output func() string
}
func NewMessage(t string) *Message {
var err error
m := new(Message)
msg_user := regexp.MustCompile("<[^>]+>")
tmpMCUser := msg_user.FindString(t)
tmpMCUser = strings.Replace(tmpMCUser, "<", "", -1)
tmpMCUser = strings.Replace(tmpMCUser, ">", "", -1)
if tmpMCUser != "" {
if m.MCUser, err = c.model.getMCUser(tmpMCUser); err != nil {
m.MCUser = new(MCUser)
m.MCUser.Name = tmpMCUser
fmt.Println(">>> Updating/Creating User: " + m.MCUser.Name)
c.model.updateMCUser(m.MCUser)
}
}
m.Text = t
if m.MCUser != nil {
res := strings.Split(t, "<"+m.MCUser.Name+"> ")
if len(res) > 0 {
m.Text = res[1]
}
}
m.Output = func() string {
if m.MCUser != nil {
return "<" + m.MCUser.Name + "> " + m.Text
}
return m.Text
}
return m
}