you can use chat.Message.ClearString()

to output the message without ansi color
This commit is contained in:
Tnze
2019-06-18 17:41:00 +08:00
parent 285f582554
commit f625f06001
2 changed files with 52 additions and 3 deletions

View File

@ -67,7 +67,32 @@ var colors = map[string]int{
"white": 97,
}
// String return the message with escape sequence for ansi color.
// ClearString return the message without escape sequence for ansi color.
func (m Message) ClearString() string {
var msg strings.Builder
msg.WriteString(m.Text)
//handle translate
if m.Translate != "" {
args := make([]interface{}, len(m.With))
for i, v := range m.With {
var arg Message
arg.UnmarshalJSON(v) //ignore error
args[i] = arg.ClearString()
}
fmt.Fprintf(&msg, data.EnUs[m.Translate], args...)
}
if m.Extra != nil {
for i := range m.Extra {
msg.WriteString(Message(m.Extra[i]).ClearString())
}
}
return msg.String()
}
// String return the message string with escape sequence for ansi color.
// On windows, you may want print this string using
// github.com/mattn/go-colorable.
func (m Message) String() string {