This repository has been archived by the owner on Jun 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
chatMsg.go
101 lines (87 loc) · 2.05 KB
/
chatMsg.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package gomcbot
import (
"encoding/json"
"fmt"
)
//ChatMsg is a message sent by other
type ChatMsg jsonChat
type jsonChat struct {
Text string `json:"text"`
Bold bool `json:"bold"` //粗体
Italic bool `json:"Italic"` //斜体
UnderLined bool `json:"underlined"` //下划线
StrikeThrough bool `json:"strikethrough"` //删除线
Obfuscated bool `json:"obfuscated"` //随机
Color string `json:"color"`
Translate string `json:"translate"`
With []json.RawMessage `json:"with"` // How can go handle an JSON array with Object and String?
Extra []jsonChat `json:"extra"`
}
func newChatMsg(jsonMsg []byte) (jc ChatMsg, err error) {
if jsonMsg[0] == '"' {
err = json.Unmarshal(jsonMsg, &jc.Text)
} else {
err = json.Unmarshal(jsonMsg, &jc)
}
return
}
var colors = map[string]int{
"black": 30,
"dark_blue": 34,
"dark_green": 32,
"dark_aqua": 36,
"dark_red": 31,
"dark_purple": 35,
"gold": 33,
"gray": 37,
"dark_gray": 90,
"blue": 94,
"green": 92,
"aqua": 96,
"red": 91,
"light_purple": 95,
"yellow": 93,
"white": 97,
}
// String return the message with escape sequence for ansi color.
// On windows, you may want print this string using
// github.com/mattn/go-colorable.
func (c ChatMsg) String() (s string) {
var format string
if c.Bold {
format += "1;"
}
if c.Italic {
format += "3;"
}
if c.UnderLined {
format += "4;"
}