This commit is contained in:
Tnze
2020-11-30 14:29:15 +08:00
parent ff161afd50
commit 67806abcdb
3 changed files with 60 additions and 3 deletions

View File

@ -33,7 +33,7 @@ type jsonChat struct {
Translate string `json:"translate,omitempty"`
With []json.RawMessage `json:"with,omitempty"` // How can go handle an JSON array with Object and String?
Extra []jsonChat `json:"extra,omitempty"`
Extra []Message `json:"extra,omitempty"`
}
//UnmarshalJSON decode json to Message
@ -73,12 +73,12 @@ func (m *Message) Append(extraMsg ...Message) {
finalLen := origLen + len(extraMsg)
if cap(m.Extra) < len(m.Extra)+len(extraMsg) {
// pre expansion
extra := make([]jsonChat, finalLen)
extra := make([]Message, finalLen)
copy(extra, m.Extra)
m.Extra = extra
}
for _, v := range extraMsg {
m.Extra = append(m.Extra, jsonChat(v))
m.Extra = append(m.Extra, v)
}
}

View File

@ -34,6 +34,8 @@ var jsons = []string{
`"Tnze"`,
`"§0Tnze"`,
`"§list"`,
`{"extra":[" "],"text":""}`,
}
var texts = []string{
@ -49,6 +51,8 @@ var texts = []string{
"Tnze",
"\033[30mTnze\033[0m",
"\033[1mist\033[0m",
" ",
}
var ctexts = []string{
@ -64,6 +68,8 @@ var ctexts = []string{
"Tnze",
"Tnze",
"ist",
" ",
}
func TestChatMsgFormatString(t *testing.T) {