onebot

package
v0.0.0-...-713866f Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package onebot 实现 OneBot v11 正向 WebSocket 客户端。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RenderMessage

func RenderMessage(message msg.Message, limit int) string

Types

type Action

type Action struct {
	Action string `json:"action"`
	Params any    `json:"params,omitempty"`
	Echo   int64  `json:"echo,omitempty"`
}

type Client

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

Client 会持续重连,直到上下文被取消;写入会串行化。

func NewClient

func NewClient(cfg Config, handler EventHandler) *Client

func (*Client) Call

func (c *Client) Call(ctx context.Context, action string, params any) (json.RawMessage, error)

func (*Client) Connected

func (c *Client) Connected() bool

func (*Client) Run

func (c *Client) Run(ctx context.Context)

func (*Client) SendGroup

func (c *Client) SendGroup(groupID int64, message msg.Message) error

func (*Client) SendPrivate

func (c *Client) SendPrivate(userID int64, message msg.Message) error

type Config

type Config struct {
	URL            string // ws:// 或 wss://...
	AccessToken    string // 可选的 Bearer token
	ReplyLimit     int    // 渲染后文本的最大字符数
	HandlerWorkers int    // 事件 worker 数量,默认 8
	HandlerQueue   int    // 每个 worker 的事件缓冲数,默认 256
}

type Event

type Event struct {
	PostType      string `json:"post_type"`
	MessageType   string `json:"message_type"`
	NoticeType    string `json:"notice_type"`
	RequestType   string `json:"request_type"`
	MetaEventType string `json:"meta_event_type"`
	SubType       string `json:"sub_type"`
	MessageID     int64  `json:"message_id"`
	GroupID       int64  `json:"group_id"`
	UserID        int64  `json:"user_id"`
	OperatorID    int64  `json:"operator_id"`
	RawMessage    string `json:"raw_message"`
	Comment       string `json:"comment"`
	Flag          string `json:"flag"`
	Sender        Sender `json:"sender"`
}

Event 是框架使用的 OneBot 事件子集。这里使用 RawMessage 而非 message, 因为不同适配器对字符串和消息段数组编码的处理不同。

type EventHandler

type EventHandler func(context.Context, Event)

EventHandler 在读取协程中处理已解码的 OneBot 事件。ctx 在客户端关闭时取消。

type Response

type Response struct {
	Status  string          `json:"status"`
	RetCode int             `json:"retcode"`
	Data    json.RawMessage `json:"data"`
	Message string          `json:"message"`
	Wording string          `json:"wording"`
	Echo    int64           `json:"echo"`
}

type Sender

type Sender struct {
	Card     string `json:"card"`
	Nickname string `json:"nickname"`
}

Jump to

Keyboard shortcuts

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