Documentation ¶
Overview ¶
Package cqcode provides basic structs of cqcode media, and utilities of parsing and formatting cqcode
Index ¶
- Constants
- Variables
- func Command(str string) (cmd string, args []string)
- func DecodeCQCodeText(str string) string
- func DecodeCQText(str string) string
- func EncodeCQCodeText(str string) string
- func EncodeCQText(str string) string
- func FormatCQCode(media Media) string
- func IsCommand(str string) bool
- func ParseCQCode(str string, media Media) error
- type At
- type Bface
- type Dice
- type Emoji
- type Face
- type Image
- type Location
- type Media
- type Message
- type MessageSegment
- func NewMessageSegment(media Media) (MessageSegment, error)
- func NewMessageSegmentFromCQCode(str string) (MessageSegment, error)
- func ParseMessageSegments(msg interface{}) ([]MessageSegment, error)
- func ParseMessageSegmentsFromArray(msg interface{}) ([]MessageSegment, error)
- func ParseMessageSegmentsFromString(str string) ([]MessageSegment, error)
- type Music
- type Record
- type RedPack
- type Rich
- type Rps
- type Sface
- type Shake
- type Share
- type Show
- type Sign
- type Text
Constants ¶
const ( Rock = 1 Paper = 2 Scissors = 3 )
Common value of Rps
Variables ¶
var CommandPrefix = "/"
CommandPrefix is the prefix to identify a message as a command. See function #Command
var StrictCommand = false
StrictCommand indicates that whether a command must start with a specified command prefix, default to "/". See function #Command
Functions ¶
func Command ¶
Command parses a command string and returns the command with command arguments. In a StrictCommand mode, the initial #CommandPrefix in a command will be stripped off.
func DecodeCQCodeText ¶
DecodeCQCodeText unescapes special characters in a cqcode value.
func DecodeCQText ¶
DecodeCQText unescapes special characters in a non-media plain message.
func EncodeCQCodeText ¶
EncodeCQCodeText escapes special characters in a cqcode value.
func EncodeCQText ¶
EncodeCQText escapes special characters in a non-media plain message.
func FormatCQCode ¶
FormatCQCode returns the CQCode of a Media.
func IsCommand ¶
IsCommand indicates whether a string is a command. If #StrictCommand is true, only strings start with #CommandPrefix will be regard as command.
func ParseCQCode ¶
ParseMedia parses a CQEncoded string to a specified type of Media.
Types ¶
type At ¶
type At struct {
QQ string `cq:"qq"` // Someone's QQ号, could be "all"
}
Mention @
func (*At) FunctionName ¶
type Emoji ¶
type Emoji struct {
EmojiID int `cq:"id"` // Unicode Dec
}
Emoji
func (*Emoji) FunctionName ¶
type Face ¶
type Face struct {
FaceID int `cq:"id"` // 1-170 (旧版), >170 (新表情)
}
QQ表情
func NewFaceFromName ¶
NewFaceFromName returns a face that corresponds to a given face name.
func (*Face) FunctionName ¶
type Location ¶
type Location struct { Content string `cq:"content"` // 详细地址 Latitude float64 `cq:"lat"` Longitude float64 `cq:"lon"` Style int `cq:"style"` // 不知道是什么 Title string `cq:"title"` }
位置
func (*Location) FunctionName ¶
type Media ¶
type Media interface { // FunctionName returns the "function name" defined by Coolq, see documentation at // https://d.cqp.me/Pro/CQ%E7%A0%81 FunctionName() string }
Media is any kind of media that could be contained in a message.
type Message ¶
type Message []Media
A Message is a sort of Media.
func ParseMessage ¶
ParseMessage parses msg, which might have 2 types, string or array, depending on the configuration of cqhttp, to a Message. msg is the value of key "message" of the data umarshalled from the API response JSON.
func ParseMessageFromArray ¶
ParseMessageFromArray parses msg as type array to a Message. msg is the value of key "message" of the data umarshalled from the API response JSON.
func ParseMessageFromMessageSegments ¶
func ParseMessageFromMessageSegments(segs []MessageSegment) Message
ParseMessageFromMessageSegments parses a sort of MessageSegment to a Message.
func ParseMessageFromString ¶
ParseMessageFromString parses msg as type string to a Message. msg is the value of key "message" of the data umarshalled from the API response JSON.
func (*Message) CQString ¶
CQString returns the CQEncoded string. All media in the message will be converted to its CQCode.
func (*Message) Command ¶
Command parses a command message and returns the command with command arguments. In a StrictCommand mode, the initial #CommandPrefix in a command will be stripped off.
func (*Message) IsCommand ¶
IsCommand indicates whether a Message is a command. If #StrictCommand is true, only messages start with #CommandPrefix will be regard as command.
func (*Message) MessageSegments ¶
func (m *Message) MessageSegments() []MessageSegment
MessageSegments returns an array of MessageSegment, you will find this useful if you configured your cqhttp to receive messages in type of array.
type MessageSegment ¶
A MessageSegment is a struct which has "type" and "data", see documentation at https://cqhttp.cc/docs/3.4/#/Message?id=%E6%B6%88%E6%81%AF%E6%AE%B5%EF%BC%88%E5%B9%BF%E4%B9%89-cq-%E7%A0%81%EF%BC%89
func NewMessageSegment ¶
func NewMessageSegment(media Media) (MessageSegment, error)
NewMessageSegment formats MessageSegment from any type of Media.
func NewMessageSegmentFromCQCode ¶
func NewMessageSegmentFromCQCode(str string) (MessageSegment, error)
NewMessageSegmentFromCQCode parses a CQCode to a NewMessageSegment.
func ParseMessageSegments ¶
func ParseMessageSegments(msg interface{}) ([]MessageSegment, error)
ParseMessageSegments parses msg, which might have 2 types, string or array, depending on the configuration of cqhttp, to a sort of MessageSegment. msg is the value of key "message" of the data umarshalled from the API response JSON.
func ParseMessageSegmentsFromArray ¶
func ParseMessageSegmentsFromArray(msg interface{}) ([]MessageSegment, error)
ParseMessageSegmentsFromArray parses msg as type array to a sort of MessageSegment. msg is the value of key "message" of the data umarshalled from the API response JSON.
func ParseMessageSegmentsFromString ¶
func ParseMessageSegmentsFromString(str string) ([]MessageSegment, error)
ParseMessageSegmentsFromString parses msg as type string to a sort of MessageSegment. msg is the value of key "message" of the data umarshalled from the API response JSON.
func (*MessageSegment) CQString ¶
func (seg *MessageSegment) CQString() string
CQString returns the CQCode of a MessageSegment.
func (*MessageSegment) FunctionName ¶
func (seg *MessageSegment) FunctionName() string
func (*MessageSegment) ParseMedia ¶
func (seg *MessageSegment) ParseMedia(media Media) error
ParseMedia parses a MessageSegment to a specified type of Media.
type Music ¶
type Music struct { Type string `cq:"type"` // qq, 163, xiami // non-custom music MusicID string `cq:"id"` // id // custom music AudioURL string `cq:"audio"` // Link of audio Title string `cq:"title"` // Title Content string `cq:"content"` // Description Image string `cq:"image"` // Link of cover image }
音乐
func (*Music) FunctionName ¶
func (*Music) IsCustomMusic ¶
IsCustomMusic shows whether a music is a custom music.