Documentation
¶
Index ¶
- Constants
- Variables
- func AddReceivedCount()
- func AddSentCount()
- func GetReceivedCount() (result int)
- func GetSentCount() (result int)
- func Init()
- func RegisterSerializer(serializer MessageSerializer)
- type ActionCall
- type ActionChannel
- type FileType
- type ImageType
- type Message
- func (m *Message) AnySegment(data MessageSerializer) *Message
- func (m *Message) AttachSegment(seg MessageSegment, serializer MessageSerializer)
- func (m *Message) File(file string) *Message
- func (m Message) GetRawText() string
- func (m Message) GetSegments() []MessageSegment
- func (m *Message) Image(file string) *Message
- func (m *Message) Join(msg Message) *Message
- func (m *Message) MarshalJSON() ([]byte, error)
- func (m *Message) Text(text string) *Message
- func (m *Message) UnmarshalJSON(data []byte) error
- func (m *Message) Video(file string) *Message
- func (m *Message) Voice(file string) *Message
- type MessageChannel
- type MessageSegment
- type MessageSerializer
- type MessageType
- type TextType
- type VideoType
- type VoiceType
Constants ¶
View Source
const ACTION_CHAN_CAPACITY = 64
View Source
const LOG_MESSAGE_LEN_THRESHOLD = 256
View Source
const MESSAGE_CHAN_CAPACITY = 64
Variables ¶
View Source
var SerializerRegistry = make(map[string]MessageSerializer)
Functions ¶
func AddReceivedCount ¶
func AddReceivedCount()
AddReceivedCount increases the received count by one
func GetReceivedCount ¶
func GetReceivedCount() (result int)
GetReceivedCount returns the current received count
func RegisterSerializer ¶
func RegisterSerializer(serializer MessageSerializer)
Types ¶
type ActionCall ¶
type ActionCall struct {
// Which adapter to call
AdapterName string
// 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 (*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 {
MessageType
File string `json:"file"`
}
func (FileType) AdapterName ¶ added in v1.0.1
func (FileType) ToRawText ¶
func (serializer FileType) ToRawText(msg MessageSegment) string
type ImageType ¶
type ImageType struct {
MessageType
File string `json:"file"`
}
func (ImageType) AdapterName ¶ added in v1.0.1
func (ImageType) ToRawText ¶
func (serializer ImageType) ToRawText(msg MessageSegment) 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
// Whi is receiving this message?
Receiver string
// Who am i?
Self string
// contains filtered or unexported fields
}
This describes the whole message
func (*Message) AnySegment ¶ added in v1.0.1
func (m *Message) AnySegment(data MessageSerializer) *Message
AnySegment attachs any message segment to message
func (*Message) AttachSegment ¶ added in v1.0.1
func (m *Message) AttachSegment(seg MessageSegment, serializer MessageSerializer)
Attach a segment for a message
func (Message) GetRawText ¶
func (Message) GetSegments ¶
func (m Message) GetSegments() []MessageSegment
func (*Message) MarshalJSON ¶
func (*Message) UnmarshalJSON ¶
type MessageChannel ¶
type MessageChannel struct {
// contains filtered or unexported fields
}
func (*MessageChannel) Pull ¶
func (mc *MessageChannel) Pull() Message
Pull a message from the channel
type MessageSegment ¶
type MessageSegment struct {
// Message type
Type string `json:"type"`
// Which adapter is this message type for?
// Leave it empty if you are using universal message type
// If you have multiple adapters that have the same name, what can i say?
Adapter string `json:"adapter"`
// Use a message serializer to decode this
Data string `json:"data"`
}
This describes a simple part of a message
type MessageSerializer ¶
type MessageSerializer interface {
// Which adapter is this serializer for
AdapterName() string
// Which message type is this serializer for
TypeName() string
// Serialize a data to string
Serialize(data any, messageType reflect.Type) string
// Deserialize a message from string, will change to serializer type
Deserialize(str string, messageType reflect.Type) any
// Convert this message segment to raw text
ToRawText(msg MessageSegment) string
}
Implement this to create a message serializer
func GetSerializer ¶
func GetSerializer(typeName, adapterName string) MessageSerializer
type MessageType ¶
type MessageType struct{}
func (MessageType) Deserialize ¶
func (serializer MessageType) Deserialize(data string, messageType reflect.Type) any
Deserialize a message from string, will change to serializer type
type TextType ¶
type TextType struct {
MessageType
Text string `json:"text"`
}
func (TextType) AdapterName ¶ added in v1.0.1
func (TextType) ToRawText ¶
func (serializer TextType) ToRawText(msg MessageSegment) string
type VideoType ¶
type VideoType struct {
MessageType
File string `json:"file"`
}
func (VideoType) AdapterName ¶ added in v1.0.1
func (VideoType) ToRawText ¶
func (serializer VideoType) ToRawText(msg MessageSegment) string
type VoiceType ¶
type VoiceType struct {
MessageType
File string `json:"file"`
}
func (VoiceType) AdapterName ¶ added in v1.0.1
func (VoiceType) ToRawText ¶
func (serializer VoiceType) ToRawText(msg MessageSegment) string
Click to show internal directories.
Click to hide internal directories.