cqcode

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 25, 2020 License: MIT Imports: 7 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cqcode provides basic structs of cqcode media, and utilities of parsing and formatting cqcode

Index

Constants

View Source
const (
	Rock     = 1
	Paper    = 2
	Scissors = 3
)

Common value of Rps

Variables

View Source
var CommandPrefix = "/"

CommandPrefix is the prefix to identify a message as a command. See function #Command

View Source
var StrictCommand = false

StrictCommand indicates that whether a command must start with a specified command prefix, default to "/". See function #Command

Functions

func Command

func Command(str string) (cmd string, args []string)

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

func DecodeCQCodeText(str string) string

DecodeCQCodeText unescapes special characters in a cqcode value.

func DecodeCQText

func DecodeCQText(str string) string

DecodeCQText unescapes special characters in a non-media plain message.

func EncodeCQCodeText

func EncodeCQCodeText(str string) string

EncodeCQCodeText escapes special characters in a cqcode value.

func EncodeCQText

func EncodeCQText(str string) string

EncodeCQText escapes special characters in a non-media plain message.

func FormatCQCode

func FormatCQCode(media Media) string

FormatCQCode returns the CQCode of a Media.

func IsCommand

func IsCommand(str string) bool

IsCommand indicates whether a string is a command. If #StrictCommand is true, only strings start with #CommandPrefix will be regard as command.

func ParseCQCode

func ParseCQCode(str string, media Media) error

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

func (a *At) FunctionName() string

type Bface

type Bface struct {
	BfaceID int `cq:"id"`
}

原创表情

func (*Bface) FunctionName

func (b *Bface) FunctionName() string

type Dice

type Dice struct {
	Type int `cq:"type"` // 1-6
}

掷骰子魔法表情

func (*Dice) FunctionName

func (d *Dice) FunctionName() string

type Emoji

type Emoji struct {
	EmojiID int `cq:"id"` // Unicode Dec
}

Emoji

func (*Emoji) FunctionName

func (e *Emoji) FunctionName() string

type Face

type Face struct {
	FaceID int `cq:"id"` // 1-170 (旧版), >170 (新表情)
}

QQ表情

func NewFaceFromName

func NewFaceFromName(str string) (*Face, error)

NewFaceFromName returns a face that corresponds to a given face name.

func (*Face) FunctionName

func (f *Face) FunctionName() string

func (*Face) Name

func (f *Face) Name() (string, error)

Name returns the name of a face

type Image

type Image struct {
	FileID string `cq:"file"`
	URL    string `cq:"url"`
}

Image

func (*Image) FunctionName

func (i *Image) FunctionName() string

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

func (l *Location) FunctionName() string

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 NewMessage

func NewMessage() Message

NewMessage returns an empty Message.

func ParseMessage

func ParseMessage(msg interface{}) (Message, error)

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

func ParseMessageFromArray(msg interface{}) (Message, error)

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

func ParseMessageFromString(str string) (Message, error)

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) Append

func (m *Message) Append(media Media) error

Append is just an alias to append, which appends media to m.

func (*Message) CQString

func (m *Message) CQString() string

CQString returns the CQEncoded string. All media in the message will be converted to its CQCode.

func (*Message) Command

func (m *Message) Command() (cmd string, args []string)

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

func (m *Message) IsCommand() bool

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

type MessageSegment struct {
	Type string                 `json:"type"`
	Data map[string]interface{} `json:"data"`
}

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
	ShareURL string `cq:"url"`     // Link open on click
	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 (m *Music) FunctionName() string

func (*Music) IsCustomMusic

func (m *Music) IsCustomMusic() bool

IsCustomMusic shows whether a music is a custom music.

type Record

type Record struct {
	FileID string `cq:"file"`
	Magic  bool   `cq:"magic"`
	URL    string `cq:"url"`
}

Record

func (*Record) FunctionName

func (r *Record) FunctionName() string

type RedPack

type RedPack struct {
	Title string `cq:"title"`
}

红包

func (*RedPack) FunctionName

func (rp *RedPack) FunctionName() string

type Rich

type Rich struct {
}

其他富媒体

func (*Rich) FunctionName

func (r *Rich) FunctionName() string

type Rps

type Rps struct {
	Type int `cq:"type"`
}

猜拳魔法表情

func (*Rps) FunctionName

func (rps *Rps) FunctionName() string

type Sface

type Sface struct {
	SfaceID int `cq:"id"`
}

小表情

func (*Sface) FunctionName

func (s *Sface) FunctionName() string

type Shake

type Shake struct {
}

戳一戳

func (*Shake) FunctionName

func (s *Shake) FunctionName() string

type Share

type Share struct {
	URL     string `cq:"url"`
	Title   string `cq:"title"`   // In 12 words
	Content string `cq:"content"` // In 30 words
	Image   string `cq:"image"`   // Link of cover image
}

分享链接

func (*Share) FunctionName

func (s *Share) FunctionName() string

type Show

type Show struct {
	ID int `cq:"id"`
}

厘米秀

func (*Show) FunctionName

func (s *Show) FunctionName() string

type Sign

type Sign struct {
	Image    string `cq:"image"` // URL of cover image
	Location string `cq:"location"`
	Title    string `cq:"title"`
}

签到

func (*Sign) FunctionName

func (s *Sign) FunctionName() string

type Text

type Text struct {
	Text string `cq:"text"`
}

Plain text

func (*Text) FunctionName

func (t *Text) FunctionName() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL