qq_bot/message/text.go

39 lines
689 B
Go

package message
import (
"encoding/json"
)
// TextMessage 纯文本消息
type TextMessage struct {
Type string `json:"type"`
Data TextMessageData `json:"data"`
}
type TextMessageData struct {
Text string `json:"text"`
}
func init() {
RegisterMessageType(TypeText, func() CQMessage {
return NewTextMessage()
})
}
func NewTextMessage() *TextMessage {
return &TextMessage{Type: TypeText}
}
func (msg *TextMessage) SetData(data json.RawMessage) error {
return json.Unmarshal(data, &msg.Data)
}
func (msg *TextMessage) ToCQString() string {
return msg.Data.Text
}
func (msg *TextMessage) ParseMessage(data string) *TextMessage {
msg.Data.Text = data
return msg
}