v12

package
v0.0.0-...-7a6c0c8 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ConnectTypeHttp http连接
	ConnectTypeHttp = -1
	// ConnectTypeWebhook webhook 连接
	ConnectTypeWebhook = -2
	// ConnectTypeWebSocket websocket连接
	ConnectTypeWebSocket = -3
	// ConnectTypeWebSocketReverse 反向websocket连接
	ConnectTypeWebSocketReverse = -4
)
View Source
const (
	SendTypeEvent = 1 << 1
)

Variables

View Source
var (
	// ErrorConnectionNotFound 连接不存在
	ErrorConnectionNotFound = errors.New("connection not found")
	// ErrorConnectTypeExist 连接类型已经存在
	ErrorConnectTypeExist = errors.New("connect type exist")
	// ErrorConnectionNotV12 连接了错误的版本
	ErrorConnectionNotV12 = errors.New("the connection is not oneBot v12")
	// ErrorBotExist bot已经存在
	ErrorBotExist = errors.New("bot already exists")
	// ErrorBotNotExist bot不存在
	ErrorBotNotExist = errors.New("bot does not exist")
	// ErrorPortInUsed 端口被占用
	ErrorPortInUsed = errors.New("the port is in used")
)
View Source
var (
	// ErrorResponseIDNotFound 响应ID未找到
	ErrorResponseIDNotFound = errors.New("response id not found")
)
View Source
var (
	// OneBotV12ConnectImplementations 连接实现 OneBotV12ConnectType -> OneBotV12ConnectResisterFunc
	OneBotV12ConnectImplementations sync.Map
)

Functions

func RegisterNewConnectType

func RegisterNewConnectType(typeName OneBotV12ConnectType, registerFunc OneBotV12ConnectResisterFunc) error

Types

type OneBotV12

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

OneBotV12 OneBot V12连接

func NewOneBotV12Connect

func NewOneBotV12Connect(config OneBotV12Config, onebotConfig protocol.OneBotConfig) (*OneBotV12, error)

NewOneBotV12Connect 创建连接

func (*OneBotV12) AddBot

func (o *OneBotV12) AddBot(impl string, version string, oneBotVersion string, self protocol.Self) error

AddBot 添加机器人

func (*OneBotV12) AddBotRequestChan

func (o *OneBotV12) AddBotRequestChan(self protocol.Self, botRequestChan chan protocol.RawRequestType) error

AddBotRequestChan 添加bot请求通道

func (*OneBotV12) GetUUID

func (o *OneBotV12) GetUUID() string

GetUUID 获取连接的uuid

func (*OneBotV12) GetVersion

func (*OneBotV12) GetVersion() string

GetVersion 获取版本号

func (*OneBotV12) SendConnectEvent

func (o *OneBotV12) SendConnectEvent()

func (*OneBotV12) SendEvent

func (o *OneBotV12) SendEvent(e any, eid string, eType string) error

ConnectSendEvent 发送事件

func (*OneBotV12) SendResponse

func (o *OneBotV12) SendResponse(e any) error

ConnectSendResponse 发送响应

func (*OneBotV12) SendStatusUpdate

func (o *OneBotV12) SendStatusUpdate()

type OneBotV12Config

type OneBotV12Config struct {
	// ConnectType 连接类型
	ConnectType OneBotV12ConnectType
	// ConnectConfig 相应连接实现的配置
	ConnectConfig interface{}
}

OneBotV12Config OneBot V12连接配置

type OneBotV12Connect

type OneBotV12Connect interface {
	Send([]byte, int, string) error
	SetCallBackFunc(OneBotV12ConnectCallBackFunc)
}

OneBotV12Connect 连接接口

func NewOneBotV12ConnectHttp

func NewOneBotV12ConnectHttp(_ protocol.OneBotConfig, c any) (OneBotV12Connect, error)

func NewOneBotV12ConnectWebhook

func NewOneBotV12ConnectWebhook(oc protocol.OneBotConfig, c any) (OneBotV12Connect, error)

NewOneBotV12ConnectWebhook 创建一个 OneBot v12 webhook 连接

func NewOneBotV12ConnectWebsocket

func NewOneBotV12ConnectWebsocket(_ protocol.OneBotConfig, c any) (OneBotV12Connect, error)

NewOneBotV12ConnectWebsocket 创建websocket连接实现

func NewOneBotV12ConnectWebsocketReverse

func NewOneBotV12ConnectWebsocketReverse(oc protocol.OneBotConfig, c any) (OneBotV12Connect, error)

NewOneBotV12ConnectWebsocketReverse 创建反向 WebSocket 连接

type OneBotV12ConnectCallBackFunc

type OneBotV12ConnectCallBackFunc func([]byte) (string, error)

type OneBotV12ConnectHttp

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

func (*OneBotV12ConnectHttp) Send

func (c *OneBotV12ConnectHttp) Send(b []byte, t int, e string) error

func (*OneBotV12ConnectHttp) SetCallBackFunc

func (c *OneBotV12ConnectHttp) SetCallBackFunc(f OneBotV12ConnectCallBackFunc)

func (*OneBotV12ConnectHttp) Start

func (c *OneBotV12ConnectHttp) Start() error

type OneBotV12ConnectResisterFunc

type OneBotV12ConnectResisterFunc func(protocol.OneBotConfig, any) (OneBotV12Connect, error)

type OneBotV12ConnectType

type OneBotV12ConnectType int

type OneBotV12ConnectWebhook

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

OneBotV12ConnectWebhook OneBot v12 webhook 连接 这个!我没测试! TODO: 测试

func (*OneBotV12ConnectWebhook) Send

func (c *OneBotV12ConnectWebhook) Send(b []byte, t int, e string) error

Send 发送事件

func (*OneBotV12ConnectWebhook) SetCallBackFunc

SetCallBackFunc 绑定接收函数

type OneBotV12ConnectWebsocket

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

OneBotV12ConnectWebsocket websocket链接

func (*OneBotV12ConnectWebsocket) Send

func (c *OneBotV12ConnectWebsocket) Send(b []byte, t int, e string) error

Send 发送消息

func (*OneBotV12ConnectWebsocket) SetCallBackFunc

SetCallBackFunc 绑定接收函数

func (*OneBotV12ConnectWebsocket) Start

func (c *OneBotV12ConnectWebsocket) Start() error

Start 启动websocket服务

type OneBotV12ConnectWebsocketReverse

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

OneBotV12ConnectWebsocketReverse 反向 WebSocket 连接

func (*OneBotV12ConnectWebsocketReverse) Send

Send 直接发送数据

func (*OneBotV12ConnectWebsocketReverse) SetCallBackFunc

SetCallBackFunc 绑定接收函数

func (*OneBotV12ConnectWebsocketReverse) Start

Start 启动反向 WebSocket 连接

type OneBotV12HttpConfig

type OneBotV12HttpConfig struct {
	// Host HTTP 服务器监听 IP
	Host string `yaml:"host" json:"host" default:""`
	// Port HTTP 服务器监听端口
	Port int `yaml:"port" json:"port" default:""`
	// AccessToken 访问令牌
	AccessToken string `yaml:"access_token" json:"access_token" default:""`
	// TimeOut 超时时间
	// 如果开发者在该时间内没有给出相应, 自动503
	TimeOut int `yaml:"time_out" json:"time_out" default:"5000"`
	// EventEnable 是否启用 get_latest_events 元动作
	EventEnable bool `yaml:"event_enable" json:"event_enable" default:"true"`
	// EventBufferSize 事件缓冲区大小,超过该大小将会丢弃最旧的事件,0 表示不限大小
	EventBufferSize int `yaml:"event_buffer_size" json:"event_buffer_size" default:"500"`
}

OneBotV12HttpConfig HTTP 连接配置

type OneBotV12Response

type OneBotV12Response struct {
	*protocol.Response
	Data any `json:"data"`
}

OneBotV12Response V12响应

type OneBotV12WebHookConfig

type OneBotV12WebHookConfig struct {
	// Url Webhook 上报地址
	Url string `yaml:"url" json:"url" default:""`
	//AccessToken 访问令牌
	AccessToken string `yaml:"access_token" json:"access_token" default:""`
	// TimeOut 上报请求超时时间,单位:毫秒,0 表示不超时
	TimeOut int `yaml:"time_out" json:"time_out" default:"5000"`
	// UserAgent
	UserAgent string `yaml:"user_agent" json:"user_agent" default:"go-libonebot"`
	// contains filtered or unexported fields
}

OneBotV12WebHookConfig HTTP 连接配置

type OneBotV12WebsocketConfig

type OneBotV12WebsocketConfig struct {
	// Host WebSocket 服务器监听 IP
	Host string `yaml:"host" json:"host" default:""`
	// Port WebSocket 服务器监听端口
	Port int `yaml:"port" json:"port" default:""`
	// AccessToken WebSocket 服务器监听端口
	AccessToken string `yaml:"access_token" json:"access_token" default:""`
	// TimeOut 超时时间
	TimeOut int `yaml:"time_out" json:"time_out" default:"5000"`
}

OneBotV12WebsocketConfig HTTP 连接配置

type OneBotV12WebsocketReverseConfig

type OneBotV12WebsocketReverseConfig struct {
	// Url 反向 WebSocket 连接地址
	Url string `yaml:"url" json:"url" default:""`
	// AccessToken 访问令牌
	AccessToken string `yaml:"access_token" json:"access_token" default:""`
	// ReconnectInterval 反向 WebSocket 重连间隔,单位:毫秒,必须大于 0
	ReconnectInterval int `yaml:"reconnect_interval" json:"reconnect_interval" default:"5000"`
	// UserAgent HTTP 请求头中的 User-Agent 字段
	UserAgent string `yaml:"user_agent" json:"user_agent" default:"go-libonebot"`
	// TimeOut
	TimeOut int `yaml:"time_out" json:"time_out" default:"5000"`
	// BufferSize 缓存事件和响应
	BufferSize int `yaml:"buffer_size" json:"buffer_size" default:"500"`
	// contains filtered or unexported fields
}

OneBotV12WebsocketReverseConfig HTTP 连接配置

Jump to

Keyboard shortcuts

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