Documentation
¶
Index ¶
- Constants
- func ListPlugins(pluginPath string) ([]string, error)
- type ClearTimerRequest
- type ClearTimerResponse
- type CommandArgument
- type CommandDefinition
- type CommandEvent
- type CommandOption
- type GetFeaturesRequest
- type GetFeaturesResponse
- type GroupInfo
- type HttpIncomingRequest
- type HttpListenRequest
- type HttpListenResponse
- type HttpOutgoingResponse
- type HttpRequestPayload
- type HttpResponsePayload
- type InlineKeyboardButtonPayload
- type InlineKeyboardPayload
- type MessageElementPayload
- type MessageEventPayload
- type PluginInstance
- func (inst *PluginInstance) AddTimer(id string, cancel context.CancelFunc)
- func (inst *PluginInstance) Call(name string, input []byte) ([]byte, error)
- func (inst *PluginInstance) FunctionExists(name string) bool
- func (inst *PluginInstance) Release()
- func (inst *PluginInstance) RemoveTimer(id string) bool
- type ReplyMessageRequest
- type SendMessageRequest
- type SendMessageResponse
- type SenderInfo
- type Service
- func (s *Service) DisablePlugin(name string) error
- func (s *Service) EnablePlugin(name string) error
- func (s *Service) GetPluginStat() map[string]bool
- func (s *Service) HasPlugin(name string) (bool, bool)
- func (s *Service) Init(grb *GoroBot.Instant) error
- func (s *Service) InitPlugin(name string) (err error)
- func (s *Service) InitPlugins()
- func (s *Service) LookupPlugins() (int, error)
- func (s *Service) Name() string
- func (s *Service) Release(grb *GoroBot.Instant) error
- func (s *Service) ReleasePlugin(name string) (err error)
- type SetTimerRequest
- type SetTimerResponse
- type SubscribeEventRequest
- type TimeNowResponse
Constants ¶
const ( DefaultPluginPath = "plugin/" PluginsListTemplateString = `` /* 162-byte string literal not displayed */ )
Variables ¶
This section is empty.
Functions ¶
func ListPlugins ¶
ListPlugins 检查指定目录,返回所有以 .wasm 结尾的插件标识数组
Types ¶
type ClearTimerRequest ¶ added in v0.4.0
type ClearTimerRequest struct {
TimerID string `json:"timer_id"`
}
ClearTimerRequest 是取消定时任务的请求参数
type ClearTimerResponse ¶ added in v0.4.0
type ClearTimerResponse struct {
Success bool `json:"success"`
Error string `json:"error,omitempty"`
}
ClearTimerResponse 是取消定时任务后的响应
type CommandArgument ¶
type CommandArgument struct {
Name string `json:"name"`
Type string `json:"type"` // "string", "number", "bool"
Required bool `json:"required"`
Help string `json:"help"`
}
CommandArgument 描述指令参数
type CommandDefinition ¶
type CommandDefinition struct {
Name string `json:"name"`
Description string `json:"description"`
Arguments []CommandArgument `json:"arguments,omitempty"`
Options []CommandOption `json:"options,omitempty"`
Handler string `json:"handler,omitempty"` // Wasm 导出函数名,默认 "on_command"
}
CommandDefinition 描述 Wasm 插件向宿主注册的指令结构
type CommandEvent ¶
type CommandEvent struct {
Command string `json:"command"`
Commands []string `json:"commands"`
MessageType string `json:"message_type"` // "group" 或 "direct"
GroupID string `json:"group_id,omitempty"` // 群聊 ID(私聊为空)
Group *GroupInfo `json:"group,omitempty"` // 群聊详情(若有)
SenderID string `json:"sender_id"`
Sender *SenderInfo `json:"sender,omitempty"` // 发送者详情
Protocol string `json:"protocol"`
BotContextID string `json:"context_id"`
Features []string `json:"features,omitempty"`
MessageID string `json:"message_id,omitempty"`
Elements []MessageElementPayload `json:"elements,omitempty"`
Timestamp int64 `json:"timestamp,omitempty"` // 秒级时间戳
Arguments []string `json:"arguments"`
KvArgs map[string]string `json:"kv_args"`
Options map[string]string `json:"options"`
Raw string `json:"raw"`
ContextToken string `json:"context_token"`
}
CommandEvent 是指令被触发时传给 Wasm 插件的上下文 JSON 结构
type CommandOption ¶
type CommandOption struct {
Name string `json:"name"`
ShortName string `json:"short,omitempty"`
Type string `json:"type"` // "string", "number", "bool"
Required bool `json:"required"`
Default string `json:"default,omitempty"`
Help string `json:"help"`
}
CommandOption 描述指令选项(如 -t / --times)
type GetFeaturesRequest ¶
type GetFeaturesRequest struct {
ContextToken string `json:"context_token,omitempty"` // 可选,通过事件或指令上下文 Token 查
BotContextID string `json:"context_id,omitempty"` // 可选,直接通过机器人上下文 ID 查
}
GetFeaturesRequest 查询适配器支持特性的请求
type GetFeaturesResponse ¶
type GetFeaturesResponse struct {
Success bool `json:"success"`
Features []string `json:"features"`
Error string `json:"error,omitempty"`
}
GetFeaturesResponse 查询适配器特性的响应
type GroupInfo ¶
type GroupInfo struct {
ID string `json:"id"`
Name string `json:"name,omitempty"`
Avatar string `json:"avatar,omitempty"`
}
GroupInfo 描述消息所属群聊详情
type HttpIncomingRequest ¶
type HttpIncomingRequest struct {
Method string `json:"method"`
Path string `json:"path"`
Query string `json:"query"`
Headers map[string]string `json:"headers"`
Body string `json:"body"`
}
HttpIncomingRequest 是宿主收到外部 HTTP 请求后传给 Wasm 插件的数据
type HttpListenRequest ¶
type HttpListenRequest struct {
Addr string `json:"addr"` // 监听端口或地址,如 ":8080"
Path string `json:"path,omitempty"` // 路由路径,默认为 "/"
Handler string `json:"handler,omitempty"` // 收到 HTTP 请求时回调的 Wasm 导出函数名,默认 "on_http_request"
}
HttpListenRequest 是插件向宿主申请监听 HTTP 网络服务的请求结构
type HttpListenResponse ¶
type HttpListenResponse struct {
Success bool `json:"success"`
Addr string `json:"addr"`
Path string `json:"path"`
Error string `json:"error,omitempty"`
}
HttpListenResponse 是监听 HTTP 网络服务后的返回结构
type HttpOutgoingResponse ¶
type HttpOutgoingResponse struct {
StatusCode int `json:"status_code"`
Headers map[string]string `json:"headers,omitempty"`
Body string `json:"body"`
}
HttpOutgoingResponse 是 Wasm 插件处理完 HTTP 请求后返回给外部客户端的响应
type HttpRequestPayload ¶
type HttpRequestPayload struct {
URL string `json:"url"`
Method string `json:"method,omitempty"` // 默认 "GET"
Headers map[string]string `json:"headers,omitempty"`
RawHeaders map[string][]string `json:"raw_headers,omitempty"` // 支持传递多值头部
Body string `json:"body,omitempty"` // 文本请求体
BodyBase64 string `json:"body_base64,omitempty"` // 可选 Base64 编码请求体(用于发送二进制数据)
TimeoutMs int64 `json:"timeout_ms,omitempty"`
FollowRedirects *bool `json:"follow_redirects,omitempty"` // 是否自动跟随重定向,默认 true
}
HttpRequestPayload 是插件调用网络请求时的入参
type HttpResponsePayload ¶
type HttpResponsePayload struct {
StatusCode int `json:"status_code"`
Status string `json:"status,omitempty"` // 状态说明,如 "200 OK"
Proto string `json:"proto,omitempty"` // 协议版本,如 "HTTP/1.1"
Headers map[string]string `json:"headers"` // 扁平化 Header(支持规范名称及全小写名称查询)
RawHeaders map[string][]string `json:"raw_headers"` // 完整多值 Header 映射(如 Set-Cookie: [...])
Body string `json:"body"` // 响应体文本内容
BodyBase64 string `json:"body_base64"` // 响应体完整 Base64 编码(确保图片、压缩包、二进制与特殊字符不损坏)
ContentLength int64 `json:"content_length"` // 响应体字节长度
Error string `json:"error,omitempty"`
}
HttpResponsePayload 是网络请求的响应数据,包含完整的状态、响应头与响应体
type InlineKeyboardButtonPayload ¶
type InlineKeyboardButtonPayload struct {
Text string `json:"text"`
Action int `json:"action"` // 0: URL, 1: Callback, 2: Command
Data string `json:"data"`
DirectSend bool `json:"direct_send,omitempty"`
ID string `json:"id,omitempty"`
}
InlineKeyboardButtonPayload 是 Wasm 插件构造内嵌按钮的数据结构
type InlineKeyboardPayload ¶
type InlineKeyboardPayload struct {
Rows [][]InlineKeyboardButtonPayload `json:"rows"`
}
InlineKeyboardPayload 是 Wasm 插件构造内嵌键盘的数据结构
type MessageElementPayload ¶
type MessageElementPayload struct {
Type int `json:"type"` // 0=Text, 1=Quote, 2=Mention, 3=Image, 4=Video, 5=File, 6=Voice, 7=Sticker, 8=Link, 9=InlineKeyboard, 10=Other
Content string `json:"content,omitempty"`
Source string `json:"source,omitempty"`
}
MessageElementPayload 描述结构化消息元素
type MessageEventPayload ¶
type MessageEventPayload struct {
MessageType string `json:"message_type"` // "group" 或 "direct"
GroupID string `json:"group_id,omitempty"` // 群聊 ID(私聊为空)
Group *GroupInfo `json:"group,omitempty"` // 群聊详情(若有)
Protocol string `json:"protocol"`
BotContextID string `json:"context_id"`
Features []string `json:"features,omitempty"`
MessageID string `json:"message_id,omitempty"`
SenderID string `json:"sender_id"`
Sender *SenderInfo `json:"sender,omitempty"` // 发送者详情
Text string `json:"text"`
Elements []MessageElementPayload `json:"elements,omitempty"`
Timestamp int64 `json:"timestamp,omitempty"` // 秒级时间戳
ContextToken string `json:"context_token"`
}
MessageEventPayload 是接收到聊天消息时传给 Wasm 插件的结构
type PluginInstance ¶
type PluginInstance struct {
// contains filtered or unexported fields
}
PluginInstance 表示一个已加载并运行的 Wasm 插件实例
func (*PluginInstance) AddTimer ¶ added in v0.4.0
func (inst *PluginInstance) AddTimer(id string, cancel context.CancelFunc)
AddTimer 记录并启动一个受控的定时任务
func (*PluginInstance) Call ¶
func (inst *PluginInstance) Call(name string, input []byte) ([]byte, error)
Call 线程安全地调用 Wasm 插件导出的函数
func (*PluginInstance) FunctionExists ¶
func (inst *PluginInstance) FunctionExists(name string) bool
FunctionExists 检查插件是否导出了指定函数
func (*PluginInstance) Release ¶
func (inst *PluginInstance) Release()
Release 释放插件所占用的所有系统资源(指令注销、事件解绑、HTTP服务清理、Wasm关闭)
func (*PluginInstance) RemoveTimer ¶ added in v0.4.0
func (inst *PluginInstance) RemoveTimer(id string) bool
RemoveTimer 移除并取消一个定时任务
type ReplyMessageRequest ¶
type ReplyMessageRequest struct {
ContextToken string `json:"context_token"`
Text string `json:"text,omitempty"` // 回复的普通文本内容
Markdown string `json:"markdown,omitempty"` // 可选 Markdown 文本内容
Keyboard *InlineKeyboardPayload `json:"keyboard,omitempty"`
}
ReplyMessageRequest 是针对当前上下文的回复请求参数(支持带内嵌键盘与 Markdown)
type SendMessageRequest ¶
type SendMessageRequest struct {
BotContextID string `json:"context_id,omitempty"` // 可选,指定机器人上下文ID
TargetID string `json:"target_id"` // 接收者 ID (User/Group 或统一 Entity ID)
Text string `json:"text,omitempty"` // 发送的普通文本内容
Markdown string `json:"markdown,omitempty"` // 可选 Markdown 文本内容
Keyboard *InlineKeyboardPayload `json:"keyboard,omitempty"` // 可选内嵌键盘
}
SendMessageRequest 是 Wasm 插件主动发送消息的请求参数
type SendMessageResponse ¶
type SendMessageResponse struct {
Success bool `json:"success"`
Error string `json:"error,omitempty"`
}
SendMessageResponse 是主动发送消息后的返回结果
type SenderInfo ¶
type SenderInfo struct {
ID string `json:"id"`
Name string `json:"name,omitempty"`
Nickname string `json:"nickname,omitempty"`
Avatar string `json:"avatar,omitempty"`
Authority int `json:"authority,omitempty"` // 0=Banned, 1=Member, 2=GroupAdmin, 3=GroupOwner, 4=Admin, 5=Owner
}
SenderInfo 描述消息发送者的身份详情
type Service ¶
type Service struct {
PluginPath string
// contains filtered or unexported fields
}
func (*Service) DisablePlugin ¶
func (*Service) EnablePlugin ¶
func (*Service) GetPluginStat ¶
func (*Service) InitPlugin ¶
func (*Service) InitPlugins ¶
func (s *Service) InitPlugins()
func (*Service) LookupPlugins ¶
func (*Service) ReleasePlugin ¶
type SetTimerRequest ¶ added in v0.4.0
type SetTimerRequest struct {
IntervalMs int64 `json:"interval_ms,omitempty"` // 周期触发间隔(毫秒),用于 set_interval
DelayMs int64 `json:"delay_ms,omitempty"` // 延时触发时间(毫秒),用于 set_timeout
Handler string `json:"handler,omitempty"` // 触发时回调的 Wasm 导出函数名
Payload string `json:"payload,omitempty"` // 可选传递给处理函数的参数字符串
}
SetTimerRequest 是设置定时或轮询任务的请求参数
type SetTimerResponse ¶ added in v0.4.0
type SetTimerResponse struct {
Success bool `json:"success"`
TimerID string `json:"timer_id,omitempty"`
Error string `json:"error,omitempty"`
}
SetTimerResponse 是设置定时任务后的响应
type SubscribeEventRequest ¶
type SubscribeEventRequest struct {
Event string `json:"event"` // 事件名,例如 "message"
Handler string `json:"handler,omitempty"` // 触发时回调的 Wasm 导出函数名
}
SubscribeEventRequest 是事件订阅请求
type TimeNowResponse ¶ added in v0.4.0
type TimeNowResponse struct {
Unix int64 `json:"unix"` // 秒级时间戳
UnixMilli int64 `json:"unix_milli"` // 毫秒级时间戳
ISO8601 string `json:"iso8601"` // ISO8601 格式时间
}
TimeNowResponse 是获取当前系统时间的响应