message

package
v0.0.0-...-d64b273 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SegmentTypeText      SegmentType = "text"
	SegmentTypeFace      SegmentType = "face"
	SegmentTypeImage     SegmentType = "image"
	SegmentTypeRecord    SegmentType = "record"
	SegmentTypeVideo     SegmentType = "video" // MessageTypeVideo 短视频
	SegmentTypeAt        SegmentType = "at"    // MessageTypeAt @某人
	SegmentTypeRps       SegmentType = "rps"   // MessageTypeRps 猜拳魔法表情
	SegmentTypeDice      SegmentType = "dice"  // MessageTypeDice 掷骰子魔法表情
	SegmentTypeShake     SegmentType = "shake" // MessageTypeShake 窗口抖动
	SegmentTypePoke      SegmentType = "poke"
	SegmentTypeAnonymous SegmentType = "anonymous"
	SegmentTypeShare     SegmentType = "share"
	SegmentTypeContact   SegmentType = "contact"
	SegmentTypeLocation  SegmentType = "location"
	SegmentTypeMusic     SegmentType = "music"
	SegmentTypeReply     SegmentType = "reply"
	SegmentTypeForward   SegmentType = "forward"
	SegmentTypeNode      SegmentType = "node"
	SegmentTypeXml       SegmentType = "xml"
	SegmentTypeJson      SegmentType = "json"

	MusicTypeQQ     MusicType = "qq"
	MusicType163    MusicType = "163"
	MusicTypeXm     MusicType = "xm"
	MusicTypeCustom MusicType = "custom"

	ImageTypeFlash = "flash"
)

Variables

This section is empty.

Functions

func EscapeCQString

func EscapeCQString(s string) string

func GetMsgData

func GetMsgData[T any](msg *Segment) *T

GetMsgData 安全获取类型为 T 的消息数据,返回 nil 表示类型不匹配

func GetMsgDataUnsafe

func GetMsgDataUnsafe[T any](msg *Segment) *T

GetMsgDataUnsafe 获取类型为 T 的消息数据,如果类型不匹配会引发 panic

func UnescapeCQString

func UnescapeCQString(s string) string

Types

type AnonymousData

type AnonymousData struct {
	Ignore bool `json:"ignore,omitempty"`
}

func NewAnonymous

func NewAnonymous(ignore bool) *AnonymousData

func (*AnonymousData) Segment

func (d *AnonymousData) Segment() Segment

type AtData

type AtData struct {
	QQ string `json:"qq"`
}

func NewAt

func NewAt(qq string) *AtData

NewAt 创建 @ 消息,qq 为被 @ 的用户 QQ 号或 all 表示 @ 所有人

func NewAtAll

func NewAtAll() *AtData

NewAtAll 创建 @ 所有人 消息

func NewAtUser

func NewAtUser(id qq.UserId) *AtData

func (*AtData) Segment

func (d *AtData) Segment() Segment

type BasicFileData

type BasicFileData struct {
	File    string `json:"file"`
	URL     string `json:"url,omitempty"`
	Cache   *int   `json:"cache,omitempty"`
	Proxy   *int   `json:"proxy,omitempty"`
	Timeout *int   `json:"timeout,omitempty"`
}

type BasicIdData

type BasicIdData struct {
	Id int64 `json:"id,string"`
}

type BasicMusicData

type BasicMusicData struct {
	Type MusicType `json:"type"`
}

type CQMessage

type CQMessage interface {
	// GetType 获取消息类型
	GetType() SegmentType
	// String CQ 码的消息字符串
	CQStringer
}

CQMessage QQ 消息

type CQStringer

type CQStringer fmt.Stringer

type Chain

type Chain struct {
	Messages []Segment
}

func NewChain

func NewChain(msg ...Segment) *Chain

func ParseCQString

func ParseCQString(s string) (*Chain, error)

func (*Chain) AddAt

func (mc *Chain) AddAt(userId string)

func (*Chain) AddAtAll

func (mc *Chain) AddAtAll()

func (*Chain) AddAtUser

func (mc *Chain) AddAtUser(userId qq.UserId)

func (*Chain) AddSegment

func (mc *Chain) AddSegment(msg Segment)

func (*Chain) AddSegments

func (mc *Chain) AddSegments(msg ...Segment)

func (*Chain) AddText

func (mc *Chain) AddText(text string)

func (*Chain) AppendChain

func (mc *Chain) AppendChain(chain Chain)

func (*Chain) At

func (mc *Chain) At(idx int) Segment

At 返回位置在 idx 的消息的拷贝。

func (*Chain) AtRef

func (mc *Chain) AtRef(idx int) *Segment

AtRef 返回位置在 idx 的消息的引用。

func (*Chain) Clear

func (mc *Chain) Clear()

func (*Chain) FirstImage

func (mc *Chain) FirstImage() *ImageData

func (*Chain) FirstOfType

func (mc *Chain) FirstOfType(msgType SegmentType) Segment

FirstOfType 返回第一个类型为 msgType 的消息的拷贝。如果没有找到,返回空消息。

func (*Chain) FirstOfTypeRef

func (mc *Chain) FirstOfTypeRef(msgType SegmentType) *Segment

FirstOfTypeRef 返回第一个类型为 msgType 的消息的引用。如果没有找到,返回 nil。

func (*Chain) FirstText

func (mc *Chain) FirstText() *TextData

func (*Chain) GetSegmentsWithType

func (mc *Chain) GetSegmentsWithType(msgType SegmentType) []Segment

func (*Chain) Len

func (mc *Chain) Len() int

func (*Chain) MarshalJSON

func (mc *Chain) MarshalJSON() ([]byte, error)

func (*Chain) PrependChain

func (mc *Chain) PrependChain(chain Chain)

func (*Chain) PrependSegment

func (mc *Chain) PrependSegment(msg Segment)

func (*Chain) SetReplyTo

func (mc *Chain) SetReplyTo(msgId qq.MessageId)

SetReplyTo 设置回复的消息 ID。

func (*Chain) SetSendAsAnonymous

func (mc *Chain) SetSendAsAnonymous(ignore bool)

SetSendAsAnonymous 设置是否匿名发送消息。当 ignore 为 true 时,将在无法匿名发送消息时继续发送消息。

func (*Chain) String

func (mc *Chain) String() string

func (*Chain) UnmarshalJSON

func (mc *Chain) UnmarshalJSON(data []byte) error

type ContactData

type ContactData struct {
	Type string `json:"type"`
	BasicIdData
}

func NewContact

func NewContact(t string, id int64) *ContactData

func (*ContactData) Segment

func (d *ContactData) Segment() Segment

type CustomMusicData

type CustomMusicData struct {
	BasicMusicData
	Title string `json:"title"`
	Url   string `json:"url"`
	Audio string `json:"audio"`
}

func NewCustomMusic

func NewCustomMusic(title, url, audio string) *CustomMusicData

func (*CustomMusicData) Segment

func (d *CustomMusicData) Segment() Segment

type CustomNodeData

type CustomNodeData struct {
	UserId   qq.UserId `json:"user_id,string"`
	Nickname string    `json:"nickname"`
	Content  any       `json:"content"`
}

func NewCustomNode

func NewCustomNode[T SendableMessage](userId qq.UserId, nickname string, content T) *CustomNodeData

func (*CustomNodeData) Segment

func (d *CustomNodeData) Segment() Segment

type DiceData

type DiceData utils.Void

func NewDice

func NewDice() *DiceData

func (*DiceData) Segment

func (d *DiceData) Segment() Segment

type FaceData

type FaceData BasicIdData

func NewFace

func NewFace(id int64) *FaceData

func (*FaceData) Segment

func (d *FaceData) Segment() Segment

type FileData

type FileData struct {
	BasicFileData
	// Name 文件名【NapCat 扩展】
	Name string `json:"name,omitempty"`
}

type ForwardData

type ForwardData BasicIdData

func (*ForwardData) Segment

func (d *ForwardData) Segment() Segment

type IdNodeData

type IdNodeData BasicIdData

func NewNode

func NewNode(id int64) *IdNodeData

func (*IdNodeData) Segment

func (d *IdNodeData) Segment() Segment

type ImageData

type ImageData struct {
	BasicFileData
	// Summary 自定义显示的文件名【LLOneBot 扩展】
	Summary string `json:"summary,omitempty"`
	Type    string `json:"type,omitempty"`
}

func NewImage

func NewImage(file string) *ImageData

func (*ImageData) IsFlash

func (d *ImageData) IsFlash() bool

func (*ImageData) Segment

func (d *ImageData) Segment() Segment

func (*ImageData) SetFlash

func (d *ImageData) SetFlash()

type JsonData

type JsonData struct {
	Data string `json:"data"`
}

func NewJson

func NewJson(data string) *JsonData

func (*JsonData) Segment

func (d *JsonData) Segment() Segment

type LocationData

type LocationData struct {
	Lat     float64 `json:"lat,string"`
	Lon     float64 `json:"lon,string"`
	Title   string  `json:"title,omitempty"`
	Content string  `json:"content,omitempty"`
}

func NewLocation

func NewLocation(lat, lon float64) *LocationData

func (*LocationData) Segment

func (d *LocationData) Segment() Segment

type MusicData

type MusicData struct {
	BasicMusicData
	BasicIdData
}

func NewMusic

func NewMusic(t MusicType, id int64) *MusicData

func (*MusicData) Segment

func (d *MusicData) Segment() Segment

type MusicType

type MusicType string

type PokeData

type PokeData struct {
	Type string `json:"type"`
	Id   string `json:"id"`
	Name string `json:"name,omitempty"`
}

func (*PokeData) Segment

func (d *PokeData) Segment() Segment

type RecordData

type RecordData struct {
	BasicFileData
	Magic int `json:"magic,omitempty"`
}

func NewRecord

func NewRecord(file string) *RecordData

func (*RecordData) Segment

func (d *RecordData) Segment() Segment

type ReplyData

type ReplyData BasicIdData

func NewReply

func NewReply(id qq.MessageId) *ReplyData

func (*ReplyData) Segment

func (d *ReplyData) Segment() Segment

type RpsData

type RpsData utils.Void

func NewRps

func NewRps() *RpsData

func (*RpsData) Segment

func (d *RpsData) Segment() Segment

type Segment

type Segment struct {
	Type SegmentType `json:"type"`
	Data any         `json:"data"`
}

Segment 消息片段

func NewAtMessage

func NewAtMessage(qq string) Segment

func NewDiceMessage

func NewDiceMessage() Segment

func NewFaceSegment

func NewFaceSegment(id int64) Segment

func NewImageSegment

func NewImageSegment(file string) Segment

func NewRecordSegment

func NewRecordSegment(file string) Segment

func NewRpsMessage

func NewRpsMessage() Segment

func NewShakeMessage

func NewShakeMessage() Segment

func NewTextSegment

func NewTextSegment(text string) Segment

func NewVideoSegment

func NewVideoSegment(file string) Segment

func (Segment) AsChain

func (m Segment) AsChain() *Chain

func (Segment) GetAtData

func (m Segment) GetAtData() *AtData

GetAtData 获取 @ 消息数据,如果类型不匹配返回 nil

func (Segment) GetContactData

func (m Segment) GetContactData() *ContactData

GetContactData 获取联系人消息数据,如果类型不匹配返回 nil

func (Segment) GetCustomNodeData

func (m Segment) GetCustomNodeData() any

GetCustomNodeData 获取自定义节点消息数据,如果类型不匹配返回 nil

func (Segment) GetDataPtr

func (m Segment) GetDataPtr() any

func (Segment) GetDiceData

func (m Segment) GetDiceData() *DiceData

GetDiceData 获取掷骰子消息数据,如果类型不匹配返回 nil

func (Segment) GetFaceData

func (m Segment) GetFaceData() *FaceData

GetFaceData 获取表情消息数据,如果类型不匹配返回 nil

func (Segment) GetForwardData

func (m Segment) GetForwardData() *ForwardData

GetForwardData 获取转发消息数据,如果类型不匹配返回 nil

func (Segment) GetImageData

func (m Segment) GetImageData() *ImageData

GetImageData 获取图片消息数据,如果类型不匹配返回 nil

func (Segment) GetJsonData

func (m Segment) GetJsonData() *JsonData

GetJsonData 获取 JSON 消息数据,如果类型不匹配返回 nil

func (Segment) GetLocationData

func (m Segment) GetLocationData() *LocationData

GetLocationData 获取位置消息数据,如果类型不匹配返回 nil

func (Segment) GetMusicData

func (m Segment) GetMusicData() *MusicData

GetMusicData 获取音乐消息数据,如果类型不匹配返回 nil

func (Segment) GetPokeData

func (m Segment) GetPokeData() *PokeData

GetPokeData 获取戳一戳消息数据,如果类型不匹配返回 nil

func (Segment) GetRecordData

func (m Segment) GetRecordData() *RecordData

GetRecordData 获取语音消息数据,如果类型不匹配返回 nil

func (Segment) GetReplyData

func (m Segment) GetReplyData() *ReplyData

GetReplyData 获取回复消息数据,如果类型不匹配返回 nil

func (Segment) GetRpsData

func (m Segment) GetRpsData() *RpsData

GetRpsData 获取猜拳消息数据,如果类型不匹配返回 nil

func (Segment) GetShakeData

func (m Segment) GetShakeData() *ShakeData

GetShakeData 获取窗口抖动消息数据,如果类型不匹配返回 nil

func (Segment) GetShareData

func (m Segment) GetShareData() *ShareData

GetShareData 获取分享消息数据,如果类型不匹配返回 nil

func (Segment) GetTextData

func (m Segment) GetTextData() *TextData

GetTextData 获取文本消息数据,如果类型不匹配返回 nil

func (Segment) GetType

func (m Segment) GetType() SegmentType

func (Segment) GetVideoData

func (m Segment) GetVideoData() *VideoData

GetVideoData 获取视频消息数据,如果类型不匹配返回 nil

func (Segment) GetXmlData

func (m Segment) GetXmlData() *XmlData

GetXmlData 获取 XML 消息数据,如果类型不匹配返回 nil

func (Segment) IsInvalid

func (m Segment) IsInvalid() bool

func (Segment) String

func (m Segment) String() string

func (*Segment) UnmarshalJSON

func (m *Segment) UnmarshalJSON(data []byte) error

type SegmentType

type SegmentType string

SegmentType 消息片段类型

type SendableMessage

type SendableMessage interface {
	string | *Chain
}

type ShakeData

type ShakeData utils.Void

func NewShake

func NewShake() *ShakeData

func (*ShakeData) Segment

func (d *ShakeData) Segment() Segment

type ShareData

type ShareData struct {
	Title   string `json:"title"`
	Url     string `json:"url"`
	Content string `json:"content,omitempty"`
	Image   string `json:"image,omitempty"`
}

func NewShare

func NewShare(title, url string) *ShareData

func (*ShareData) Segment

func (d *ShareData) Segment() Segment

type TextData

type TextData struct {
	Text string `json:"text"`
}

func NewText

func NewText(text string) *TextData

func (*TextData) Segment

func (d *TextData) Segment() Segment

type UnknownData

type UnknownData map[string]any

type VideoData

type VideoData BasicFileData

func NewVideo

func NewVideo(file string) *VideoData

func (*VideoData) Segment

func (d *VideoData) Segment() Segment

type XmlData

type XmlData struct {
	Data string `json:"data"`
}

func NewXml

func NewXml(data string) *XmlData

func (*XmlData) Segment

func (d *XmlData) Segment() Segment

Jump to

Keyboard shortcuts

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