message

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2024 License: Apache-2.0 Imports: 3 Imported by: 4

Documentation

Index

Constants

View Source
const ACTION_CHAN_CAPACITY = 64
View Source
const LOG_MESSAGE_LEN_THRESHOLD = 256
View Source
const MESSAGE_CHAN_CAPACITY = 64

Variables

This section is empty.

Functions

func AddReceivedCount

func AddReceivedCount()

AddReceivedCount increases the received count by one

func AddSentCount

func AddSentCount()

AddSentCount increases the sent count by one

func GetReceivedCount

func GetReceivedCount() (result int)

GetReceivedCount returns the current received count

func GetSentCount

func GetSentCount() (result int)

GetSentCount returns the current sent count

Types

type ActionCall

type ActionCall struct {
	// Which action
	Action any
	// Which channel to push the result, will initialize automatically
	ResultChannel *chan any
}

If you want to call adapter action, you should use this struct

type ActionChannel

type ActionChannel struct {
	// contains filtered or unexported fields
}

func NewActionChannel

func NewActionChannel() *ActionChannel

Create a new ActionChannel

func (*ActionChannel) Pull

func (ac *ActionChannel) Pull() *ActionCall

Pull a message from the channel

func (*ActionChannel) Push

func (ac *ActionChannel) Push(action *ActionCall)

Push a message to the channel

If the channel is full, the oldest message will be dropped

type FileType

type FileType struct {
	File string `json:"file"`
}

func (FileType) AdapterName added in v1.0.1

func (serializer FileType) AdapterName() string

func (FileType) ToRawText

func (serializer FileType) ToRawText(msg MessageSegment) string

func (FileType) TypeName added in v1.0.1

func (serializer FileType) TypeName() string

type ImageType

type ImageType struct {
	File string `json:"file"`
}

func (ImageType) AdapterName added in v1.0.1

func (serializer ImageType) AdapterName() string

func (ImageType) ToRawText

func (serializer ImageType) ToRawText(msg MessageSegment) string

func (ImageType) TypeName added in v1.0.1

func (serializer ImageType) TypeName() string

type Message

type Message struct {
	// Is the message to me?
	IsToMe bool
	// Which group is it in?(Only useful with group message and notice)
	Group string
	// Who is sending this message?
	Sender string
	// Who is receiving this message?
	Receiver string
	// Who am i?
	Self string
	// contains filtered or unexported fields
}

This describes the whole message

func NewMessage added in v1.1.0

func NewMessage() *Message

func NewReply added in v1.0.1

func NewReply(m Message) *Message

func (*Message) Any added in v1.1.0

func (m *Message) Any(data MessageType) *Message

AnySegment attachs any message segment to message

func (*Message) AttachSegment added in v1.0.1

func (m *Message) AttachSegment(seg MessageSegment)

Attach a segment for a message

func (*Message) File added in v1.0.1

func (m *Message) File(file string) *Message

File attachs a file message segment to message

func (Message) GetRawText

func (m Message) GetRawText() string

func (Message) GetSegments

func (m Message) GetSegments() []MessageSegment

func (*Message) Image added in v1.0.1

func (m *Message) Image(file string) *Message

Image attachs an image message segment to message

func (*Message) Join added in v1.0.2

func (m *Message) Join(msg Message) *Message

Attach the message contents together

func (*Message) MarshalJSON

func (m *Message) MarshalJSON() ([]byte, error)

func (*Message) Text added in v1.0.1

func (m *Message) Text(text string) *Message

Text attachs a plain text message segment to message

func (*Message) UnmarshalJSON

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

func (*Message) Video added in v1.0.1

func (m *Message) Video(file string) *Message

Video attachs a video message segment to message

func (*Message) Voice added in v1.0.1

func (m *Message) Voice(file string) *Message

Voice attachs a voice message segment to message

type MessageChannel

type MessageChannel struct {
	// contains filtered or unexported fields
}

func NewMessageChannel

func NewMessageChannel() *MessageChannel

Create a new MessageChannel

func (*MessageChannel) Pull

func (mc *MessageChannel) Pull() Message

Pull a message from the channel

func (*MessageChannel) Push

func (mc *MessageChannel) Push(msg Message, isReceive bool)

Push a message to the channel

If the channel is full, the oldest message will be dropped

If isReceive is true, the message will be counted as received, otherwise it will be counted as result

type MessageSegment

type MessageSegment struct {
	// Message type
	Type string `json:"type"`
	// Make sure it implements MessageType interface
	Data MessageType `json:"data"`
}

This describes a simple part of a message

type MessageType

type MessageType interface {
	// Which adapter is this message for
	AdapterName() string
	// Which message type is this message for
	TypeName() string
	// Convert this message segment to raw text
	ToRawText(msg MessageSegment) string
}

Implement this to create a message type

func ToBuiltIn added in v1.1.0

func ToBuiltIn(typeName string, msg any) MessageType

Convert raw MessageSegment.Data to built-in MessageType

type TextType

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

func (TextType) AdapterName added in v1.0.1

func (serializer TextType) AdapterName() string

func (TextType) ToRawText

func (serializer TextType) ToRawText(msg MessageSegment) string

func (TextType) TypeName added in v1.0.1

func (serializer TextType) TypeName() string

type VideoType

type VideoType struct {
	File string `json:"file"`
}

func (VideoType) AdapterName added in v1.0.1

func (serializer VideoType) AdapterName() string

func (VideoType) ToRawText

func (serializer VideoType) ToRawText(msg MessageSegment) string

func (VideoType) TypeName added in v1.0.1

func (serializer VideoType) TypeName() string

type VoiceType

type VoiceType struct {
	File string `json:"file"`
}

func (VoiceType) AdapterName added in v1.0.1

func (serializer VoiceType) AdapterName() string

func (VoiceType) ToRawText

func (serializer VoiceType) ToRawText(msg MessageSegment) string

func (VoiceType) TypeName added in v1.0.1

func (serializer VoiceType) TypeName() string

Jump to

Keyboard shortcuts

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