protocol

package
v0.0.0-...-d010567 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package protocol (context.go): plugin context interface. Plugins use Context for all sending and protocol operations; the implementation is provided by each protocol (e.g. onebotv11, zerobot).

Package protocol defines protocol-agnostic unified message types (Segment, Message) and the plugin context interface. Protocol-specific implementations live in subpackages (e.g. onebotv11, zerobot).

Index

Constants

View Source
const (
	SegmentTypeText      = "text"
	SegmentTypeFace      = "face"
	SegmentTypeImage     = "image"
	SegmentTypeRecord    = "record"
	SegmentTypeVideo     = "video"
	SegmentTypeAt        = "at"
	SegmentTypeRps       = "rps"
	SegmentTypeDice      = "dice"
	SegmentTypeShake     = "shake"
	SegmentTypePoke      = "poke"
	SegmentTypeAnonymous = "anonymous"
	SegmentTypeShare     = "share"
	SegmentTypeContact   = "contact"
	SegmentTypeLocation  = "location"
	SegmentTypeMusic     = "music"
	SegmentTypeReply     = "reply"
	SegmentTypeForward   = "forward"
	SegmentTypeNode      = "node"
	SegmentTypeXML       = "xml"
	SegmentTypeJSON      = "json"
)

Segment type constants (aligned with OneBot v11; used as canonical segment kinds).

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context interface {
	// Send sends a unified message. The implementation translates it to the protocol format and performs the send.
	Send(msg Message) error
	// Reply sends a reply to the current message (e.g. prepends reply segment or uses reply API).
	Reply(msg Message) error
	// UserID returns the sender user ID of the current event.
	UserID() string
	// GroupID returns the group ID when in a group chat, or empty/"0" for private chat.
	GroupID() string
	// IncomingMessage returns the current event message as unified Message.
	IncomingMessage() Message
	// PlainText returns the plain text of the current message (no CQ/media).
	PlainText() string
	// MessageID returns the current event message_id (for reply/recall).
	MessageID() string
	// RawMessage returns the original raw_message string from the event.
	RawMessage() string
	// SenderNickname returns the sender display name (nickname or card per OneBot sender).
	SenderNickname() string
}

type Message

type Message []Segment

Message is an ordered list of segments; mixed content = multiple segments in one message.

type Segment

type Segment struct {
	Type string         `json:"type"`
	Data map[string]any `json:"data,omitempty"`
}

Segment is a single message segment (type + data), the unified "integrated" unit.

Directories

Path Synopsis
Package onebotv11 provides OneBot v11 protocol compatibility: builders, CQ code, JSON, and Context implementation.
Package onebotv11 provides OneBot v11 protocol compatibility: builders, CQ code, JSON, and Context implementation.
Package zerobot provides protocol.Context implementation by wrapping ZeroBot's *zero.Ctx.
Package zerobot provides protocol.Context implementation by wrapping ZeroBot's *zero.Ctx.

Jump to

Keyboard shortcuts

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