nova

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2026 License: GPL-3.0 Imports: 26 Imported by: 0

README

Attribution

This project is derived from wdvxdr1123/ZeroBot. Thanks to the original authors and contributors.

Major changes in this fork:

  • Refactored API return model to APIResult[T] + error
  • Extended NapCat-related APIs
  • Internal error propagation improvements

License: This project follows the original license terms (see LICENSE).

Documentation

Index

Constants

View Source
const (
	StateKeyPrefixKeep = "__zerobot_keep_"
	StateKeyEventIndex = StateKeyPrefixKeep + "_zerobot_ev_idx__"
)
View Source
const (
	KeyPattern = "pattern_matched"
)

Variables

View Source
var APICallers callerMap

APICallers 所有的APICaller列表, 通过self-ID映射

Functions

func AdminPermission

func AdminPermission(ctx *Ctx) bool

AdminPermission only triggered by the group admins or higher permission

func ExposeCaller

func ExposeCaller[T any](ctx *Ctx) *T

ExposeCaller as *T, maybe panic if misused

func GetTriggeredMessages

func GetTriggeredMessages(id message.ID) []message.ID

GetTriggeredMessages 获取被 id 消息触发的回复消息 id

func HasPicture

func HasPicture(ctx *Ctx) bool

HasPicture 消息含有图片返回 true

func MustProvidePicture

func MustProvidePicture(ctx *Ctx) bool

MustProvidePicture 消息不存在图片阻塞120秒至有图片,超时返回 false

func OnlyGroup

func OnlyGroup(ctx *Ctx) bool

OnlyGroup requires that the ctx.Event is public/group message

func OnlyGuild

func OnlyGuild(ctx *Ctx) bool

OnlyGuild requires that the ctx.Event is public/guild message

func OnlyPrivate

func OnlyPrivate(ctx *Ctx) bool

OnlyPrivate requires that the ctx.Event is private message

func OnlyPublic

func OnlyPublic(ctx *Ctx) bool

OnlyPublic requires that the ctx.Event is public/group or public/guild message

func OnlyToMe

func OnlyToMe(ctx *Ctx) bool

OnlyToMe only triggered in conditions of @bot or begin with the nicknames

func OwnerPermission

func OwnerPermission(ctx *Ctx) bool

OwnerPermission only triggered by the group owner or higher permission

func ParseShell

func ParseShell(s string) []string

ParseShell 将指令转换为指令参数. modified from https://github.com/mattn/go-shellwords

func RangeBot

func RangeBot(iter func(id int64, ctx *Ctx) bool)

RangeBot 遍历所有bot (Ctx)实例

单次操作返回 true 则继续遍历,否则退出

func Run

func Run(op *Config)

Run 主函数初始化

func RunAndBlock

func RunAndBlock(op *Config, preblock func())

RunAndBlock 主函数初始化并阻塞

preblock 在所有 Driver 连接后,调用最后一个 Driver 的 Listen 阻塞前执行本函数

func SuperUserPermission

func SuperUserPermission(ctx *Ctx) bool

SuperUserPermission only triggered by the bot's owner

func UserOrGrpAdmin

func UserOrGrpAdmin(ctx *Ctx) bool

UserOrGrpAdmin 允许用户单独使用或群管使用

Types

type APICaller

type APICaller interface {
	CallAPI(c context.Context, request APIRequest) (APIResponse, error)
}

APICaller is the interface of CallAPI

type APIRequest

type APIRequest struct {
	Action string `json:"action"`
	Params Params `json:"params"`
	Echo   uint64 `json:"echo,omitempty"` // 该项不用填写,由Driver生成
}

APIRequest is the request sending to the cqhttp https://github.com/botuniverse/onebot-11/blob/master/communication/ws.md

func (*APIRequest) String

func (ar *APIRequest) String() string

type APIResponse

type APIResponse struct {
	Status  string       `json:"status"`
	Data    gjson.Result `json:"data"`
	Message string       `json:"message"`
	Wording string       `json:"wording"`
	RetCode int64        `json:"retcode"`
	Echo    uint64       `json:"echo"`
}

APIResponse is the response of calling API https://github.com/botuniverse/onebot-11/blob/master/communication/ws.md

type APIResult

type APIResult[T any] struct {
	Value T
	Resp  APIResponse
}

APIResult wraps typed business value with raw API response.

type Config

type Config struct {
	NickName        []string      `json:"nickname"`           // 机器人名称
	CommandPrefix   string        `json:"command_prefix"`     // 触发命令
	SuperUsers      []int64       `json:"super_users"`        // 超级用户
	RingLen         uint          `json:"ring_len"`           // 事件环长度 (默认关闭)
	Latency         time.Duration `json:"latency"`            // 事件处理延迟 (延迟 latency 再处理事件,在 ring 模式下不可低于 1ms)
	MaxProcessTime  time.Duration `json:"max_process_time"`   // 事件最大处理时间 (默认4min)
	MarkMessage     bool          `json:"mark_message"`       // 自动标记消息为已读
	KeepAtMeMessage bool          `json:"keep_at_me_message"` // 是否保留at me的原始消息
	AddSpaceAfterAt bool          `json:"at_space"`           // 是否在At消息后没有空格时自动添加空格
	Driver          []Driver      `json:"-"`                  // 通信驱动
}

Config is config of zero bot

var BotConfig Config

BotConfig 运行中bot的配置,是Run函数的参数的拷贝

func (*Config) GetFirstSuperUser

func (op *Config) GetFirstSuperUser(qqs ...int64) int64

GetFirstSuperUser 在 qqs 中获得 SuperUsers 列表的首个 qq

找不到返回 -1

type Ctx

type Ctx struct {
	Event *Event
	State State
	// contains filtered or unexported fields
}

Ctx represents the Context which hold the event. 代表上下文

func GetBot

func GetBot(id int64) *Ctx

GetBot 获取指定的bot (Ctx)实例

func (*Ctx) ArkSharePeer

func (ctx *Ctx) ArkSharePeer(userID, groupID string) (APIResult[string], error)

ArkSharePeer 获取推荐好友/群聊卡片

c

func (*Ctx) Block

func (ctx *Ctx) Block()

Block 匹配成功后阻止后续触发

func (*Ctx) Break

func (ctx *Ctx) Break()

Block 在 pre, rules, mid 阶段阻止后续触发

func (*Ctx) CallAction

func (ctx *Ctx) CallAction(action string, params Params) (APIResponse, error)

CallAction 调用 cqhttp API

func (*Ctx) CallActionWithContext

func (ctx *Ctx) CallActionWithContext(c context.Context, action string, params Params) (APIResponse, error)

CallActionWithContext 使用 context 调用 cqhttp API

func (*Ctx) CanSendImage

func (ctx *Ctx) CanSendImage() (APIResult[bool], error)

CanSendImage 检查是否可以发送图片

https://napcat.apifox.cn/226657071e0.md

func (*Ctx) CanSendRecord

func (ctx *Ctx) CanSendRecord() (APIResult[bool], error)

CanSendRecord 检查是否可以发送语音

https://napcat.apifox.cn/226657080e0.md

func (*Ctx) CardOrNickName

func (ctx *Ctx) CardOrNickName(uid int64) (name string)

CardOrNickName 从 uid 获取群名片,如果没有则获取昵称

func (*Ctx) CheckSession

func (ctx *Ctx) CheckSession() Rule

CheckSession 判断会话连续性

func (*Ctx) CheckURLSafely

func (ctx *Ctx) CheckURLSafely(url string) (APIResult[int64], error)

CheckURLSafely 检查URL安全性

https://napcat.apifox.cn/228534361e0.md

返回安全等级: 1=安全, 2=未知, 3=危险

func (*Ctx) CleanCache

func (ctx *Ctx) CleanCache() (APIResult[struct{}], error)

CleanCache 清理缓存

https://napcat.apifox.cn/298305106e0.md

func (*Ctx) ClickInlineKeyboardButton

func (ctx *Ctx) ClickInlineKeyboardButton(groupID int64, botAppid string, buttonID, callbackData string) (APIResult[struct{}], error)

ClickInlineKeyboardButton 点击内联键盘按钮

https://napcat.apifox.cn/266151864e0.md

func (*Ctx) CreateGroupFileFolder

func (ctx *Ctx) CreateGroupFileFolder(groupID int64, folderName string) (APIResult[gjson.Result], error)

CreateGroupFileFolder 创建群文件目录

https://napcat.apifox.cn/226658773e0.md

func (*Ctx) CreateThisGroupFileFolder

func (ctx *Ctx) CreateThisGroupFileFolder(folderName string) (APIResult[gjson.Result], error)

CreateThisGroupFileFolder 创建本群文件目录

func (*Ctx) DeleteFriend

func (ctx *Ctx) DeleteFriend(userID int64, tempBlock, tempBothDel bool) (APIResult[struct{}], error)

DeleteFriend 删除好友

https://napcat.apifox.cn/227237873e0.md

func (*Ctx) DeleteGroupAlbumMedia

func (ctx *Ctx) DeleteGroupAlbumMedia(groupID int64, albumID, mediaID string) (APIResult[struct{}], error)

DeleteGroupAlbumMedia 删除群相册媒体

https://napcat.apifox.cn/395455119e0.md

func (*Ctx) DeleteGroupEssenceMessage

func (ctx *Ctx) DeleteGroupEssenceMessage(messageID int64) (APIResponse, error)

DeleteGroupEssenceMessage 移出群精华消息 https://github.com/Mrs4s/go-cqhttp/blob/master/docs/cqhttp.md#%E7%A7%BB%E5%87%BA%E7%B2%BE%E5%8D%8E%E6%B6%88%E6%81%AF

func (*Ctx) DeleteGroupFile

func (ctx *Ctx) DeleteGroupFile(groupID int64, fileID string) (APIResult[struct{}], error)

DeleteGroupFile 删除群文件

https://napcat.apifox.cn/226658755e0.md

func (*Ctx) DeleteGroupFileFolder

func (ctx *Ctx) DeleteGroupFileFolder(groupID int64, folderID string) (APIResult[struct{}], error)

DeleteGroupFileFolder 删除群文件目录

https://napcat.apifox.cn/226658779e0.md

func (*Ctx) DeleteGroupNotice

func (ctx *Ctx) DeleteGroupNotice(groupID int64, noticeID string) (APIResult[struct{}], error)

DeleteGroupNotice 删除群公告

https://napcat.apifox.cn/226659240e0.md

func (*Ctx) DeleteMessage

func (ctx *Ctx) DeleteMessage(messageID interface{}) (APIResult[struct{}], error)

DeleteMessage 撤回消息 https://github.com/botuniverse/onebot-11/blob/master/api/public.md#delete_msg-%E6%92%A4%E5%9B%9E%E6%B6%88%E6%81%AF

func (*Ctx) DeleteThisGroupFile

func (ctx *Ctx) DeleteThisGroupFile(fileID string) (APIResult[struct{}], error)

DeleteThisGroupFile 删除本群文件

func (*Ctx) DeleteThisGroupFileFolder

func (ctx *Ctx) DeleteThisGroupFileFolder(folderID string) (APIResult[struct{}], error)

DeleteThisGroupFileFolder 删除本群文件目录

func (*Ctx) DeleteThisGroupNotice

func (ctx *Ctx) DeleteThisGroupNotice(noticeID string) (APIResult[struct{}], error)

DeleteThisGroupNotice 删除本群公告

func (*Ctx) DownloadFile

func (ctx *Ctx) DownloadFile(url, name, headers string) (APIResult[string], error)

DownloadFile 下载文件到本地临时目录

https://napcat.apifox.cn/226658887e0.md

func (*Ctx) Echo

func (ctx *Ctx) Echo(response []byte)

Echo 向自身分发虚拟事件

func (*Ctx) ExtractPlainText

func (ctx *Ctx) ExtractPlainText() string

ExtractPlainText 提取消息中的纯文本

func (*Ctx) ForwardFriendSingleMessage

func (ctx *Ctx) ForwardFriendSingleMessage(userID int64, messageID interface{}) (APIResponse, error)

ForwardFriendSingleMessage 转发单条消息到好友

https://llonebot.github.io/zh-CN/develop/extends_api

func (*Ctx) ForwardGroupSingleMessage

func (ctx *Ctx) ForwardGroupSingleMessage(groupID int64, messageID interface{}) (APIResponse, error)

ForwardGroupSingleMessage 转发单条消息到群

https://llonebot.github.io/zh-CN/develop/extends_api

func (*Ctx) FriendPoke

func (ctx *Ctx) FriendPoke(userID int64) (APIResult[struct{}], error)

FriendPoke 私聊戳一戳

https://napneko.github.io/develop/api/doc#friend-poke-%E7%A7%81%E8%81%8A%E6%88%B3%E4%B8%80%E6%88%B3

func (*Ctx) FutureEvent

func (ctx *Ctx) FutureEvent(typ string, rule ...Rule) *FutureEvent

FutureEvent ...

func (*Ctx) Get

func (ctx *Ctx) Get(prompt string) string

Get ..

func (*Ctx) GetAIRecord

func (ctx *Ctx) GetAIRecord(character string, groupID int64, text string) (APIResult[string], error)

GetAIRecord AI文字转语音

https://napneko.github.io/develop/api/doc#get-ai-record-ai%E6%96%87%E5%AD%97%E8%BD%AC%E8%AF%AD%E9%9F%B3

func (*Ctx) GetCSRFToken

func (ctx *Ctx) GetCSRFToken() (APIResult[int64], error)

GetCSRFToken 获取 CSRF Token

https://napcat.apifox.cn/226657044e0.md

func (*Ctx) GetClientKey

func (ctx *Ctx) GetClientKey() (APIResult[string], error)

GetClientKey 获取当前登录帐号的 ClientKey

https://napcat.apifox.cn/250286915e0.md

func (*Ctx) GetCookies

func (ctx *Ctx) GetCookies(domain string) (APIResult[string], error)

GetCookies 获取指定域名的 Cookies

https://napcat.apifox.cn/226657041e0.md

func (*Ctx) GetCredentials

func (ctx *Ctx) GetCredentials(domain string) (APIResult[gjson.Result], error)

GetCredentials 获取登录凭证(Cookies + CSRF Token)

https://napcat.apifox.cn/226657054e0.md

func (*Ctx) GetDoubtFriendsAddRequest

func (ctx *Ctx) GetDoubtFriendsAddRequest() (APIResult[gjson.Result], error)

GetDoubtFriendsAddRequest 获取可疑好友申请列表

https://napcat.apifox.cn/289565516e0.md

func (*Ctx) GetEmojiLikeList

func (ctx *Ctx) GetEmojiLikeList(messageID interface{}, emojiID string, count int) (APIResult[gjson.Result], error)

GetEmojiLikeList 获取消息表情点赞列表

https://napcat.apifox.cn/410334663e0.md

func (*Ctx) GetFile

func (ctx *Ctx) GetFile(fileID string) (APIResult[gjson.Result], error)

GetFile 下载收到的群文件或私聊文件

https://llonebot.github.io/zh-CN/develop/extends_api

func (*Ctx) GetFriendMessageHistory

func (ctx *Ctx) GetFriendMessageHistory(userID, messageSeq string, count int, reverseOrder bool) (APIResult[gjson.Result], error)

GetFriendMessageHistory 获取私聊历史记录

https://napneko.github.io/develop/api/doc#get-friend-msg-history-%E8%8E%B7%E5%8F%96%E7%A7%81%E8%81%8A%E5%8E%86%E5%8F%B2%E8%AE%B0%E5%BD%95

func (*Ctx) GetGroupAlbumList

func (ctx *Ctx) GetGroupAlbumList(groupID int64) (APIResult[gjson.Result], error)

GetGroupAlbumList 获取群相册列表

https://napcat.apifox.cn/395460287e0.md

func (*Ctx) GetGroupAlbumMediaList

func (ctx *Ctx) GetGroupAlbumMediaList(groupID int64, albumID string) (APIResult[gjson.Result], error)

GetGroupAlbumMediaList 获取群相册媒体列表

https://napcat.apifox.cn/395459066e0.md

func (*Ctx) GetGroupIgnoredNotifies

func (ctx *Ctx) GetGroupIgnoredNotifies(groupID int64) (APIResult[gjson.Result], error)

GetGroupIgnoredNotifies 获取群忽略通知(被忽略的入群申请和邀请)

https://napcat.apifox.cn/226659323e0.md

func (*Ctx) GetGroupInfoEx

func (ctx *Ctx) GetGroupInfoEx(groupID int64) (APIResult[gjson.Result], error)

GetGroupInfoEx 获取群详细信息(扩展)

https://napcat.apifox.cn/226659229e0.md

func (*Ctx) GetGroupMessageHistory

func (ctx *Ctx) GetGroupMessageHistory(groupID, messageID, count int64, reverseOrder bool) (APIResult[gjson.Result], error)

GetGroupMessageHistory 获取群消息历史记录 https://github.com/Mrs4s/go-cqhttp/blob/master/docs/cqhttp.md#%E8%8E%B7%E5%8F%96%E7%BE%A4%E6%B6%88%E6%81%AF%E5%8E%86%E5%8F%B2%E8%AE%B0%E5%BD%95 https://napcat.apifox.cn/226657401e0

messageID: 起始消息序号, 可通过 get_msg 获得, 添加count和reverseOrder参数

func (*Ctx) GetGroupNotice

func (ctx *Ctx) GetGroupNotice(groupID int64) (APIResult[gjson.Result], error)

GetGroupNotice 获取群公告列表

https://napcat.apifox.cn/226658742e0.md

func (*Ctx) GetGroupShutList

func (ctx *Ctx) GetGroupShutList(groupID int64) (APIResult[gjson.Result], error)

GetGroupShutList 获取群禁言列表

https://napcat.apifox.cn/226659300e0.md

func (*Ctx) GetGuildList

func (ctx *Ctx) GetGuildList() (APIResult[gjson.Result], error)

GetGuildList 获取频道列表

https://napcat.apifox.cn/226659311e0.md

func (*Ctx) GetGuildServiceProfile

func (ctx *Ctx) GetGuildServiceProfile() (APIResult[gjson.Result], error)

GetGuildServiceProfile 获取频道个人信息

https://napcat.apifox.cn/226659317e0.md

func (*Ctx) GetLatestGroupMessageHistory

func (ctx *Ctx) GetLatestGroupMessageHistory(groupID, count int64, reverseOrder bool) (APIResult[gjson.Result], error)

GettLatestGroupMessageHistory 获取最新群消息历史记录

func (*Ctx) GetLatestThisGroupMessageHistory

func (ctx *Ctx) GetLatestThisGroupMessageHistory(count int64, reverseOrder bool) (APIResult[gjson.Result], error)

GettLatestThisGroupMessageHistory 获取最新本群消息历史记录

func (*Ctx) GetMatcher

func (ctx *Ctx) GetMatcher() *Matcher

GetMatcher ...

func (*Ctx) GetMessage

func (ctx *Ctx) GetMessage(messageID interface{}, nologreply ...bool) (APIResult[Message], error)

GetMessage 获取消息 https://github.com/botuniverse/onebot-11/blob/master/api/public.md#get_msg-%E8%8E%B7%E5%8F%96%E6%B6%88%E6%81%AF

func (*Ctx) GetMiniAppArk

func (ctx *Ctx) GetMiniAppArk(appID, title, desc, iconURL, webURL string) (APIResult[gjson.Result], error)

GetMiniAppArk 获取小程序 Ark

https://napcat.apifox.cn/227738594e0.md

func (*Ctx) GetPacketStatus

func (ctx *Ctx) GetPacketStatus() (APIResult[gjson.Result], error)

GetPacketStatus 获取Packet状态

https://napcat.apifox.cn/226659280e0.md

func (*Ctx) GetPrivateFileURL

func (ctx *Ctx) GetPrivateFileURL(fileID string) (APIResult[string], error)

GetPrivateFileURL 获取私聊文件下载链接

https://napcat.apifox.cn/266151849e0.md

func (*Ctx) GetRKey

func (ctx *Ctx) GetRKey() (APIResult[gjson.Result], error)

GetRKey 获取 RKey

https://napcat.apifox.cn/226659297e0.md

func (*Ctx) GetRKeyServer

func (ctx *Ctx) GetRKeyServer() (APIResult[gjson.Result], error)

GetRKeyServer 获取RKey服务器

https://napcat.apifox.cn/283136236e0.md

func (*Ctx) GetStatus

func (ctx *Ctx) GetStatus() (APIResult[gjson.Result], error)

GetStatus 获取运行状态

https://napcat.apifox.cn/226657083e0.md

func (*Ctx) GetThisGroupEssenceMessageList

func (ctx *Ctx) GetThisGroupEssenceMessageList() (APIResult[gjson.Result], error)

GetThisGroupEssenceMessageList 获取本群精华消息列表

func (*Ctx) GetThisGroupIgnoredNotifies

func (ctx *Ctx) GetThisGroupIgnoredNotifies() (APIResult[gjson.Result], error)

GetThisGroupIgnoredNotifies 获取本群忽略通知

func (*Ctx) GetThisGroupInfoEx

func (ctx *Ctx) GetThisGroupInfoEx() (APIResult[gjson.Result], error)

GetThisGroupInfoEx 获取本群详细信息(扩展)

func (*Ctx) GetThisGroupMemberList

func (ctx *Ctx) GetThisGroupMemberList() (APIResult[gjson.Result], error)

GetThisGroupMemberList 获取本群成员列表

func (*Ctx) GetThisGroupMemberListNoCache

func (ctx *Ctx) GetThisGroupMemberListNoCache() (APIResult[gjson.Result], error)

GetThisGroupMemberListNoCache 无缓存获取本群员列表

func (*Ctx) GetThisGroupMessageHistory

func (ctx *Ctx) GetThisGroupMessageHistory(messageID, count int64, reverseOrder bool) (APIResult[gjson.Result], error)

GetThisGroupMessageHistory 获取本群消息历史记录

messageID: 起始消息序号, 可通过 get_msg 获得

func (*Ctx) GetThisGroupNotice

func (ctx *Ctx) GetThisGroupNotice() (APIResult[gjson.Result], error)

GetThisGroupNotice 获取本群公告列表

func (*Ctx) GetThisGroupShutList

func (ctx *Ctx) GetThisGroupShutList() (APIResult[gjson.Result], error)

GetThisGroupShutList 获取本群禁言列表

func (*Ctx) GetUnidirectionalFriendList

func (ctx *Ctx) GetUnidirectionalFriendList() (APIResult[gjson.Result], error)

GetUnidirectionalFriendList 获取单向好友列表

https://napcat.apifox.cn/266151878e0.md

func (*Ctx) GetUserStatus

func (ctx *Ctx) GetUserStatus(userID int64) (APIResult[gjson.Result], error)

GetUserStatus 获取用户在线状态

https://napcat.apifox.cn/226659292e0.md

返回 data: status(在线状态), ext_status(扩展状态)

func (*Ctx) GroupKickBatch

func (ctx *Ctx) GroupKickBatch(groupID int64, userIDs []int64, rejectAddRequest bool) (APIResult[struct{}], error)

GroupKickBatch 批量踢出群成员

https://napcat.apifox.cn/301542209e0.md

func (*Ctx) GroupPoke

func (ctx *Ctx) GroupPoke(groupID, userID int64) (APIResult[struct{}], error)

GroupPoke 群聊戳一戳

https://napneko.github.io/develop/api/doc#group-poke-%E7%BE%A4%E8%81%8A%E6%88%B3%E4%B8%80%E6%88%B3

func (*Ctx) LikeGroupAlbumMedia

func (ctx *Ctx) LikeGroupAlbumMedia(groupID int64, albumID, mediaID string) (APIResult[struct{}], error)

LikeGroupAlbumMedia 点赞群相册媒体

https://napcat.apifox.cn/395457331e0.md

func (*Ctx) Logout

func (ctx *Ctx) Logout() (APIResult[struct{}], error)

Logout 退出登录

https://napcat.apifox.cn/283136399e0.md

func (*Ctx) MarkGroupMessageAsRead

func (ctx *Ctx) MarkGroupMessageAsRead(groupID int64) (APIResult[struct{}], error)

MarkGroupMessageAsRead 设置群聊已读

https://napneko.github.io/develop/api/doc#mark-group-msg-as-read-%E8%AE%BE%E7%BD%AE%E7%BE%A4%E8%81%8A%E5%B7%B2%E8%AF%BB

func (*Ctx) MarkPrivateMessageAsRead

func (ctx *Ctx) MarkPrivateMessageAsRead(userID int64) (APIResult[struct{}], error)

MarkPrivateMessageAsRead 设置私聊已读

https://napneko.github.io/develop/api/doc#mark-private-msg-as-read-%E8%AE%BE%E7%BD%AE%E7%A7%81%E8%81%8A%E5%B7%B2%E8%AF%BB

func (*Ctx) MessageString

func (ctx *Ctx) MessageString() string

MessageString 字符串消息便于Regex

func (*Ctx) MoveGroupFile

func (ctx *Ctx) MoveGroupFile(groupID int64, fileID, parentFolderID, targetFolderID string) (APIResult[struct{}], error)

MoveGroupFile 移动群文件

https://napcat.apifox.cn/283136359e0.md

func (*Ctx) NcGetRKey

func (ctx *Ctx) NcGetRKey() (APIResult[gjson.Result], error)

NcGetRKey 获取扩展RKey

https://napcat.apifox.cn/283136230e0.md

func (*Ctx) NickName

func (ctx *Ctx) NickName() (name string)

NickName 从 args/at 获取昵称,如果都没有则获取发送者的昵称

func (*Ctx) NoTimeout

func (ctx *Ctx) NoTimeout()

NoTimeout 处理时不设超时

func (*Ctx) Parse

func (ctx *Ctx) Parse(model interface{}) (err error)

Parse 将 Ctx.State 映射到结构体

func (*Ctx) RenameGroupFile

func (ctx *Ctx) RenameGroupFile(groupID int64, fileID, newName string) (APIResult[struct{}], error)

RenameGroupFile 重命名群文件

https://napcat.apifox.cn/283136375e0.md

func (*Ctx) Restart

func (ctx *Ctx) Restart() (APIResult[struct{}], error)

Restart 重启服务

https://napcat.apifox.cn/410334662e0.md

func (*Ctx) Send

func (ctx *Ctx) Send(msg interface{}) message.ID

Send 快捷发送消息/合并转发

func (*Ctx) SendChain

func (ctx *Ctx) SendChain(msg ...message.Segment) message.ID

SendChain 快捷发送消息/合并转发-消息链

func (*Ctx) SendForwardMessage

func (ctx *Ctx) SendForwardMessage(messageType string, userID, groupID int64, messages message.Message) (messageID int64, resID string, err error)

SendForwardMessage 发送合并转发

https://napneko.github.io/develop/api/doc#send-forward-msg-%E5%8F%91%E9%80%81%E5%90%88%E5%B9%B6%E8%BD%AC%E5%8F%91

func (*Ctx) SendGroupAIRecord

func (ctx *Ctx) SendGroupAIRecord(character string, groupID int64, text string) (APIResult[string], error)

SendGroupAIRecord 群聊发送AI语音

https://napneko.github.io/develop/api/doc#send-group-ai-record-%E7%BE%A4%E8%81%8A%E5%8F%91%E9%80%81ai%E8%AF%AD%E9%9F%B3

func (*Ctx) SendGroupCustomMusic

func (ctx *Ctx) SendGroupCustomMusic(groupID int64, url, audio, title string) (APIResult[int64], error)

SendGroupCustomMusic 发送群聊自定义音乐卡片

func (*Ctx) SendGroupForwardMessage

func (ctx *Ctx) SendGroupForwardMessage(groupID int64, message message.Message) (APIResult[gjson.Result], error)

SendGroupForwardMessage 发送合并转发(群) https://github.com/Mrs4s/go-cqhttp/blob/master/docs/cqhttp.md#%E5%9B%BE%E7%89%87ocr

func (*Ctx) SendGroupMessage

func (ctx *Ctx) SendGroupMessage(groupID int64, message interface{}) (APIResult[int64], error)

SendGroupMessage 发送群消息 https://github.com/botuniverse/onebot-11/blob/master/api/public.md#send_group_msg-%E5%8F%91%E9%80%81%E7%BE%A4%E6%B6%88%E6%81%AF

func (*Ctx) SendGroupMusic

func (ctx *Ctx) SendGroupMusic(groupID int64, musicType string, id int64) (APIResult[int64], error)

SendGroupMusic 发送群聊音乐卡片

https://napcat.apifox.cn

musicType: "qq", "163", "custom"

func (*Ctx) SendGroupNotice

func (ctx *Ctx) SendGroupNotice(groupID int64, content, image string, pinned int) (APIResult[struct{}], error)

SendGroupNotice 发送群公告

https://napcat.apifox.cn/226658740e0.md

func (*Ctx) SendGuildChannelMessage

func (ctx *Ctx) SendGuildChannelMessage(guildID, channelID string, message interface{}) (APIResult[string], error)

SendGuildChannelMessage 发送频道消息

func (*Ctx) SendPoke

func (ctx *Ctx) SendPoke(groupID, userID int64) (APIResult[struct{}], error)

SendPoke 群聊/私聊戳一戳

https://napneko.github.io/develop/api/doc#send-poke-%E7%BE%A4%E8%81%8A-%E7%A7%81%E8%81%8A%E6%88%B3%E4%B8%80%E6%88%B3

func (*Ctx) SendPrivateForwardMessage

func (ctx *Ctx) SendPrivateForwardMessage(userID int64, message message.Message) (APIResult[gjson.Result], error)

SendPrivateForwardMessage 发送合并转发(私聊) https://github.com/Mrs4s/go-cqhttp/blob/master/docs/cqhttp.md#%E5%9B%BE%E7%89%87ocr

func (*Ctx) SendThisGroupNotice

func (ctx *Ctx) SendThisGroupNotice(content, image string, pinned int) (APIResult[struct{}], error)

SendThisGroupNotice 发送本群公告

func (*Ctx) SetCustomOnlineStatus

func (ctx *Ctx) SetCustomOnlineStatus(faceID int, faceType int, wording string) (APIResult[struct{}], error)

SetCustomOnlineStatus 设置自定义在线状态

https://napcat.apifox.cn/266151905e0.md

func (*Ctx) SetDoubtFriendsAddRequest

func (ctx *Ctx) SetDoubtFriendsAddRequest(flag string, approve bool, remark string) (APIResult[struct{}], error)

SetDoubtFriendsAddRequest 处理可疑好友申请

https://napcat.apifox.cn/289565525e0.md

func (*Ctx) SetFriendRemark

func (ctx *Ctx) SetFriendRemark(userID int64, remark string) (APIResult[struct{}], error)

SetFriendRemark 设置好友备注

https://napcat.apifox.cn/298305173e0.md

func (*Ctx) SetGroupAddOption

func (ctx *Ctx) SetGroupAddOption(groupID int64, addOption int) (APIResult[struct{}], error)

SetGroupAddOption 设置群加群选项

https://napcat.apifox.cn/301542178e0.md

func (*Ctx) SetGroupAnonymous

func (ctx *Ctx) SetGroupAnonymous(groupID int64, enable bool) (APIResult[struct{}], error)

SetGroupAnonymous 群组匿名 https://github.com/botuniverse/onebot-11/blob/master/api/public.md#set_group_anonymous-%E7%BE%A4%E7%BB%84%E5%8C%BF%E5%90%8D

func (*Ctx) SetGroupBan

func (ctx *Ctx) SetGroupBan(groupID, userID, duration int64) (APIResult[struct{}], error)

SetGroupBan 群组单人禁言 https://github.com/botuniverse/onebot-11/blob/master/api/public.md#set_group_ban-%E7%BE%A4%E7%BB%84%E5%8D%95%E4%BA%BA%E7%A6%81%E8%A8%80

func (*Ctx) SetGroupEssenceMessage

func (ctx *Ctx) SetGroupEssenceMessage(messageID int64) (APIResponse, error)

SetGroupEssenceMessage 设置群精华消息 https://github.com/Mrs4s/go-cqhttp/blob/master/docs/cqhttp.md#%E8%AE%BE%E7%BD%AE%E7%B2%BE%E5%8D%8E%E6%B6%88%E6%81%AF

func (*Ctx) SetGroupKick

func (ctx *Ctx) SetGroupKick(groupID, userID int64, rejectAddRequest bool) (APIResult[struct{}], error)

SetGroupKick 群组踢人 https://github.com/botuniverse/onebot-11/blob/master/api/public.md#set_group_kick-%E7%BE%A4%E7%BB%84%E8%B8%A2%E4%BA%BA

func (*Ctx) SetGroupLeave

func (ctx *Ctx) SetGroupLeave(groupID int64, isDismiss bool) (APIResult[struct{}], error)

SetGroupLeave 退出群组 https://github.com/botuniverse/onebot-11/blob/master/api/public.md#set_group_leave-%E9%80%80%E5%87%BA%E7%BE%A4%E7%BB%84

func (*Ctx) SetGroupPortrait

func (ctx *Ctx) SetGroupPortrait(groupID int64, file string) (APIResult[struct{}], error)

SetGroupPortrait 设置群头像 https://github.com/Mrs4s/go-cqhttp/blob/master/docs/cqhttp.md#%E8%AE%BE%E7%BD%AE%E7%BE%A4%E5%A4%B4%E5%83%8F

func (*Ctx) SetGroupRemark

func (ctx *Ctx) SetGroupRemark(groupID int64, remark string) (APIResult[struct{}], error)

SetGroupRemark 设置群备注

https://napcat.apifox.cn/283136268e0.md

func (*Ctx) SetGroupSearchOption

func (ctx *Ctx) SetGroupSearchOption(groupID int64, enabled bool) (APIResult[struct{}], error)

SetGroupSearchOption 设置群搜索选项

https://napcat.apifox.cn/301542170e0.md

func (*Ctx) SetGroupSign

func (ctx *Ctx) SetGroupSign(groupID int64) (APIResult[struct{}], error)

SetGroupSign 群签到

https://napneko.github.io/develop/api/doc#set-group-sign-%E7%BE%A4%E7%AD%BE%E5%88%B0

func (*Ctx) SetGroupSpecialTitle

func (ctx *Ctx) SetGroupSpecialTitle(groupID, userID int64, specialTitle string) (APIResult[struct{}], error)

SetGroupSpecialTitle 设置群组专属头衔 https://github.com/botuniverse/onebot-11/blob/master/api/public.md#set_group_special_title-%E8%AE%BE%E7%BD%AE%E7%BE%A4%E7%BB%84%E4%B8%93%E5%B1%9E%E5%A4%B4%E8%A1%94

func (*Ctx) SetGroupTodo

func (ctx *Ctx) SetGroupTodo(groupID, messageID int64) (APIResult[struct{}], error)

SetGroupTodo 设置群待办

https://napcat.apifox.cn/395460568e0.md

func (*Ctx) SetInputStatus

func (ctx *Ctx) SetInputStatus(userID int64, eventType int) (APIResult[struct{}], error)

SetInputStatus 设置输入状态

https://napcat.apifox.cn/226659225e0.md

eventType: 事件类型

func (*Ctx) SetMessageEmojiLike

func (ctx *Ctx) SetMessageEmojiLike(messageID interface{}, emojiID rune) error

SetMessageEmojiLike 发送表情回应

https://llonebot.github.io/zh-CN/develop/extends_api

emoji_id 参考 https://bot.q.qq.com/wiki/develop/api-v2/openapi/emoji/model.html#EmojiType

func (*Ctx) SetMyAvatar

func (ctx *Ctx) SetMyAvatar(file string) (APIResponse, error)

SetMyAvatar 设置我的头像

https://llonebot.github.io/zh-CN/develop/extends_api

func (*Ctx) SetOnlineStatus

func (ctx *Ctx) SetOnlineStatus(status, extStatus, batteryStatus int) (APIResult[struct{}], error)

SetOnlineStatus 设置在线状态

https://napneko.github.io/develop/api/doc#set-online-status-%E8%AE%BE%E7%BD%AE%E5%9C%A8%E7%BA%BF%E7%8A%B6%E6%80%81

func (*Ctx) SetQQProfile

func (ctx *Ctx) SetQQProfile(nickname, personalNote string, sex int) (APIResult[struct{}], error)

SetQQProfile 设置QQ资料(昵称、个性签名、性别)

https://napcat.apifox.cn/226657374e0.md

sex: 0=未知, 1=男, 2=女

func (*Ctx) SetThisGroupBan

func (ctx *Ctx) SetThisGroupBan(userID, duration int64) (APIResult[struct{}], error)

SetThisGroupBan 本群组单人禁言 https://github.com/botuniverse/onebot-11/blob/master/api/public.md#set_group_ban-%E7%BE%A4%E7%BB%84%E5%8D%95%E4%BA%BA%E7%A6%81%E8%A8%80

func (*Ctx) SetThisGroupKick

func (ctx *Ctx) SetThisGroupKick(userID int64, rejectAddRequest bool) (APIResult[struct{}], error)

SetThisGroupKick 本群组踢人 https://github.com/botuniverse/onebot-11/blob/master/api/public.md#set_group_kick-%E7%BE%A4%E7%BB%84%E8%B8%A2%E4%BA%BA

func (*Ctx) SetThisGroupLeave

func (ctx *Ctx) SetThisGroupLeave(isDismiss bool) (APIResult[struct{}], error)

SetThisGroupLeave 退出本群组 https://github.com/botuniverse/onebot-11/blob/master/api/public.md#set_group_leave-%E9%80%80%E5%87%BA%E7%BE%A4%E7%BB%84

func (*Ctx) SetThisGroupName

func (ctx *Ctx) SetThisGroupName(groupName string) (APIResult[struct{}], error)

SetThisGroupName 设置本群名 https://github.com/botuniverse/onebot-11/blob/master/api/public.md#set_group_name-%E8%AE%BE%E7%BD%AE%E7%BE%A4%E5%90%8D

func (*Ctx) SetThisGroupPortrait

func (ctx *Ctx) SetThisGroupPortrait(file string) (APIResult[struct{}], error)

SetThisGroupPortrait 设置本群头像 https://github.com/Mrs4s/go-cqhttp/blob/master/docs/cqhttp.md#%E8%AE%BE%E7%BD%AE%E7%BE%A4%E5%A4%B4%E5%83%8F

func (*Ctx) SetThisGroupRemark

func (ctx *Ctx) SetThisGroupRemark(remark string) (APIResult[struct{}], error)

SetThisGroupRemark 设置本群备注

func (*Ctx) SetThisGroupSpecialTitle

func (ctx *Ctx) SetThisGroupSpecialTitle(userID int64, specialTitle string) (APIResult[struct{}], error)

SetThisGroupSpecialTitle 设置本群组专属头衔 https://github.com/botuniverse/onebot-11/blob/master/api/public.md#set_group_special_title-%E8%AE%BE%E7%BD%AE%E7%BE%A4%E7%BB%84%E4%B8%93%E5%B1%9E%E5%A4%B4%E8%A1%94

func (*Ctx) SetThisGroupTodo

func (ctx *Ctx) SetThisGroupTodo(messageID int64) (APIResult[struct{}], error)

SetThisGroupTodo 设置本群待办

func (*Ctx) TransGroupFile

func (ctx *Ctx) TransGroupFile(groupID int64, fileID, targetGroupID string) (APIResult[struct{}], error)

TransGroupFile 传输群文件

https://napcat.apifox.cn/283136366e0.md

func (*Ctx) TranslateEn2Zh

func (ctx *Ctx) TranslateEn2Zh(words []string) (APIResult[[]string], error)

TranslateEn2Zh 英译中

https://napneko.github.io/develop/api/doc#translate-en2zh-%E8%8B%B1%E8%AF%91%E4%B8%AD

func (*Ctx) UploadGroupAlbum

func (ctx *Ctx) UploadGroupAlbum(groupID int64, albumID, file string) (APIResult[gjson.Result], error)

UploadGroupAlbum 上传图片到群相册

https://napcat.apifox.cn/395459739e0.md

func (*Ctx) UploadGroupFile

func (ctx *Ctx) UploadGroupFile(groupID int64, file, name, folder string) (APIResponse, error)

UploadGroupFile 上传群文件 https://github.com/Mrs4s/go-cqhttp/blob/master/docs/cqhttp.md#%E4%B8%8A%E4%BC%A0%E7%BE%A4%E6%96%87%E4%BB%B6

msg: FILE_NOT_FOUND FILE_SYSTEM_UPLOAD_API_ERROR ...

func (*Ctx) UploadPrivateFile

func (ctx *Ctx) UploadPrivateFile(userID int64, file, name string) (APIResult[string], error)

UploadPrivateFile 上传私聊文件

https://napcat.apifox.cn/226658883e0.md

func (*Ctx) UploadThisGroupFile

func (ctx *Ctx) UploadThisGroupFile(file, name, folder string) (APIResponse, error)

UploadThisGroupFile 上传本群文件 https://github.com/Mrs4s/go-cqhttp/blob/master/docs/cqhttp.md#%E4%B8%8A%E4%BC%A0%E7%BE%A4%E6%96%87%E4%BB%B6

msg: FILE_NOT_FOUND FILE_SYSTEM_UPLOAD_API_ERROR ...

type Driver

type Driver interface {
	Connect()
	Listen(func([]byte, APICaller))
}

Driver 与OneBot通信的驱动,使用driver.DefaultWebSocketDriver

type Engine

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

Engine is the pre_handler, post_handler manager

func New

func New() *Engine

New 生成空引擎

func (*Engine) Delete

func (e *Engine) Delete()

Delete 移除该 Engine 注册的所有 Matchers

func (*Engine) On

func (e *Engine) On(typ string, rules ...Rule) *Matcher

On 添加新的指定消息类型的匹配器

func (*Engine) OnCommand

func (e *Engine) OnCommand(commands string, rules ...Rule) *Matcher

OnCommand 命令触发器

func (*Engine) OnCommandGroup

func (e *Engine) OnCommandGroup(commands []string, rules ...Rule) *Matcher

OnCommandGroup 命令触发器组

func (*Engine) OnFullMatch

func (e *Engine) OnFullMatch(src string, rules ...Rule) *Matcher

OnFullMatch 完全匹配触发器

func (*Engine) OnFullMatchGroup

func (e *Engine) OnFullMatchGroup(src []string, rules ...Rule) *Matcher

OnFullMatchGroup 完全匹配触发器组

func (*Engine) OnKeyword

func (e *Engine) OnKeyword(keyword string, rules ...Rule) *Matcher

OnKeyword 关键词触发器

func (*Engine) OnKeywordGroup

func (e *Engine) OnKeywordGroup(keywords []string, rules ...Rule) *Matcher

OnKeywordGroup 关键词触发器组

func (*Engine) OnMessage

func (e *Engine) OnMessage(rules ...Rule) *Matcher

OnMessage 消息触发器

func (*Engine) OnMetaEvent

func (e *Engine) OnMetaEvent(rules ...Rule) *Matcher

OnMetaEvent 元事件触发器

func (*Engine) OnNotice

func (e *Engine) OnNotice(rules ...Rule) *Matcher

OnNotice 系统提示触发器

func (*Engine) OnPrefix

func (e *Engine) OnPrefix(prefix string, rules ...Rule) *Matcher

OnPrefix 前缀触发器

func (*Engine) OnPrefixGroup

func (e *Engine) OnPrefixGroup(prefix []string, rules ...Rule) *Matcher

OnPrefixGroup 前缀触发器组

func (*Engine) OnRegex

func (e *Engine) OnRegex(regexPattern string, rules ...Rule) *Matcher

OnRegex 正则触发器

func (*Engine) OnRequest

func (e *Engine) OnRequest(rules ...Rule) *Matcher

OnRequest 请求消息触发器

func (*Engine) OnShell

func (e *Engine) OnShell(command string, model interface{}, rules ...Rule) *Matcher

OnShell shell命令触发器

func (*Engine) OnSuffix

func (e *Engine) OnSuffix(suffix string, rules ...Rule) *Matcher

OnSuffix 后缀触发器

func (*Engine) OnSuffixGroup

func (e *Engine) OnSuffixGroup(suffix []string, rules ...Rule) *Matcher

OnSuffixGroup 后缀触发器组

func (*Engine) SetBlock

func (e *Engine) SetBlock(block bool) *Engine

func (*Engine) UseMidHandler

func (e *Engine) UseMidHandler(rules ...Rule)

UseMidHandler 向该 Engine 添加新 MidHandler(Rule), 会在 Rule 判断后, Matcher 触发前触发,如果 midHandler 没有通过,则 Matcher 不会触发

可用于速率限制等

func (*Engine) UsePostHandler

func (e *Engine) UsePostHandler(handler ...Handler)

UsePostHandler 向该 Engine 添加新 PostHandler(Rule), 会在 Matcher 触发后触发,如果 PostHandler 返回 false, 则后续的 post handler 不会触发

可用于反并发等

func (*Engine) UsePreHandler

func (e *Engine) UsePreHandler(rules ...Rule)

UsePreHandler 向该 Engine 添加新 PreHandler(Rule), 会在 Rule 判断前触发,如果 preHandler 没有通过,则 Rule, Matcher 不会触发

可用于分群组管理插件等

type Event

type Event struct {
	Time          int64           `json:"time"`
	PostType      string          `json:"post_type"`
	DetailType    string          `json:"-"`
	MessageType   string          `json:"message_type"`
	SubType       string          `json:"sub_type"`
	MessageID     interface{}     `json:"-"`          // int64 in qq or string in guild
	RawMessageID  json.RawMessage `json:"message_id"` // int64 in qq or string in guild
	GroupID       int64           `json:"group_id"`
	ChannelID     string          `json:"channel_id"`
	GuildID       string          `json:"guild_id"`
	UserID        int64           `json:"user_id"`
	TinyID        string          `json:"tiny_id"`
	TargetID      int64           `json:"target_id"`
	SelfID        int64           `json:"self_id"`
	SelfTinyID    string          `json:"self_tiny_id"`
	RawMessage    string          `json:"raw_message"` // raw_message is always string
	Anonymous     interface{}     `json:"anonymous"`
	AnonymousFlag string          `json:"anonymous_flag"` // This field is deprecated and will get removed, see #11
	Event         string          `json:"event"`
	NoticeType    string          `json:"notice_type"` // This field is deprecated and will get removed, see #11
	OperatorID    int64           `json:"operator_id"` // This field is used for Notice Event
	File          *File           `json:"file"`
	RequestType   string          `json:"request_type"`
	Flag          string          `json:"flag"`
	Comment       string          `json:"comment"` // This field is used for Request Event
	Message       message.Message `json:"-"`       // Message parsed
	Sender        *User           `json:"sender"`
	NativeMessage json.RawMessage `json:"message"`
	IsToMe        bool            `json:"-"`
	RawEvent      gjson.Result    `json:"-"` // raw event
}

Event is the event emitted form cqhttp

type File

type File struct {
	ID    string `json:"id"`
	Name  string `json:"name"`
	Size  int64  `json:"size"`
	BusID int64  `json:"busid,omitempty"`
}

File 文件

type FutureEvent

type FutureEvent struct {
	Type     string
	Priority int
	Rule     []Rule
	Block    bool
}

FutureEvent 是 ZeroBot 交互式的核心,用于异步获取指定事件

func NewFutureEvent

func NewFutureEvent(typ string, priority int, block bool, rule ...Rule) *FutureEvent

NewFutureEvent 创建一个FutureEvent, 并返回其指针

func (*FutureEvent) Next

func (n *FutureEvent) Next() <-chan *Ctx

Next 返回一个 chan 用于接收下一个指定事件

该 chan 必须接收,如需手动取消监听,请使用 Repeat 方法

func (*FutureEvent) Repeat

func (n *FutureEvent) Repeat() (recv <-chan *Ctx, cancel func())

Repeat 返回一个 chan 用于接收无穷个指定事件,和一个取消监听的函数

如果没有取消监听,将不断监听指定事件

func (*FutureEvent) Take

func (n *FutureEvent) Take(num int) <-chan *Ctx

Take 基于 Repeat 封装,返回一个 chan 接收指定数量的事件

该 chan 对象必须接收,否则将有 goroutine 泄漏,如需手动取消请使用 Repeat

type Group

type Group struct {
	ID             int64  `json:"group_id"`
	Name           string `json:"group_name"`
	MemberCount    int64  `json:"member_count"`
	MaxMemberCount int64  `json:"max_member_count"`
}

Group 群

type H

type H = Params

H 是 Params 的简称

type Handler

type Handler func(ctx *Ctx)

Handler 事件处理函数

type Matcher

type Matcher struct {
	// Temp 是否为临时Matcher,临时 Matcher 匹配一次后就会删除当前 Matcher
	Temp bool
	// Block 是否阻断后续 Matcher,为 true 时当前Matcher匹配成功后,后续Matcher不参与匹配
	Block bool
	// Break 是否退出后续匹配流程, 只有 rule 返回 false 且此值为真才会退出, 且不对 mid handler 以下的 rule 生效
	Break bool
	// NoTimeout 处理是否不设超时
	NoTimeout bool
	// Priority 优先级,越小优先级越高
	Priority int
	// Event 当前匹配到的事件
	Event *Event
	// Type 匹配的事件类型
	Type Rule
	// Rules 匹配规则
	Rules []Rule
	// Handler 处理事件的函数
	Handler []Handler
	// Engine 注册 Matcher 的 Engine,Engine可为一系列 Matcher 添加通用 Rule 和 其他钩子
	Engine *Engine
}

Matcher 是 ZeroBot 匹配和处理事件的最小单元

func On

func On(typ string, rules ...Rule) *Matcher

On 添加新的指定消息类型的匹配器(默认Engine)

func OnCommand

func OnCommand(commands string, rules ...Rule) *Matcher

OnCommand 命令触发器

func OnCommandGroup

func OnCommandGroup(commands []string, rules ...Rule) *Matcher

OnCommandGroup 命令触发器组

func OnFullMatch

func OnFullMatch(src string, rules ...Rule) *Matcher

OnFullMatch 完全匹配触发器

func OnFullMatchGroup

func OnFullMatchGroup(src []string, rules ...Rule) *Matcher

OnFullMatchGroup 完全匹配触发器组

func OnKeyword

func OnKeyword(keyword string, rules ...Rule) *Matcher

OnKeyword 关键词触发器

func OnKeywordGroup

func OnKeywordGroup(keywords []string, rules ...Rule) *Matcher

OnKeywordGroup 关键词触发器组

func OnMessage

func OnMessage(rules ...Rule) *Matcher

OnMessage 消息触发器

func OnMetaEvent

func OnMetaEvent(rules ...Rule) *Matcher

OnMetaEvent 元事件触发器

func OnNotice

func OnNotice(rules ...Rule) *Matcher

OnNotice 系统提示触发器

func OnPrefix

func OnPrefix(prefix string, rules ...Rule) *Matcher

OnPrefix 前缀触发器

func OnPrefixGroup

func OnPrefixGroup(prefix []string, rules ...Rule) *Matcher

OnPrefixGroup 前缀触发器组

func OnRegex

func OnRegex(regexPattern string, rules ...Rule) *Matcher

OnRegex 正则触发器

func OnRequest

func OnRequest(rules ...Rule) *Matcher

OnRequest 请求消息触发器

func OnShell

func OnShell(command string, model interface{}, rules ...Rule) *Matcher

OnShell shell命令触发器

func OnSuffix

func OnSuffix(suffix string, rules ...Rule) *Matcher

OnSuffix 后缀触发器

func OnSuffixGroup

func OnSuffixGroup(suffix []string, rules ...Rule) *Matcher

OnSuffixGroup 后缀触发器组

func StoreMatcher

func StoreMatcher(m *Matcher) *Matcher

StoreMatcher store a matcher to matcher list.

func StoreTempMatcher

func StoreTempMatcher(m *Matcher) *Matcher

StoreTempMatcher store a matcher only triggered once.

func (*Matcher) BindEngine

func (m *Matcher) BindEngine(e *Engine) *Matcher

BindEngine bind the matcher to a engine

func (*Matcher) Delete

func (m *Matcher) Delete()

Delete remove the matcher from list

func (*Matcher) FirstPriority

func (m *Matcher) FirstPriority() *Matcher

FirstPriority 设置当前 Matcher 优先级 - 0

func (*Matcher) FutureEvent

func (m *Matcher) FutureEvent(typ string, rule ...Rule) *FutureEvent

FutureEvent 返回一个 FutureEvent 实例指针,用于获取满足 Rule 的 未来事件

此 FutureEvent 必然比 Matcher 之优先级少 1

func (*Matcher) Handle

func (m *Matcher) Handle(handler ...Handler) *Matcher

Handle 直接处理事件

func (*Matcher) SecondPriority

func (m *Matcher) SecondPriority() *Matcher

SecondPriority 设置当前 Matcher 优先级 - 1

func (*Matcher) SetBlock

func (m *Matcher) SetBlock(block bool) *Matcher

SetBlock 设置是否阻断后面的 Matcher 触发

func (*Matcher) SetPriority

func (m *Matcher) SetPriority(priority int) *Matcher

SetPriority 设置当前 Matcher 优先级

func (*Matcher) ThirdPriority

func (m *Matcher) ThirdPriority() *Matcher

ThirdPriority 设置当前 Matcher 优先级 - 2

type Message

type Message struct {
	Elements    message.Message
	MessageID   message.ID
	Sender      *User
	MessageType string
}

Message 消息

type Params

type Params map[string]interface{}

Params is the params of call api

type Parser

type Parser func(msg *message.Segment) PatternParsed

func NewAnyParser

func NewAnyParser() Parser

func NewAtParser

func NewAtParser(id ...message.ID) Parser

func NewImageParser

func NewImageParser() Parser

func NewReplyParser

func NewReplyParser() Parser

func NewTextParser

func NewTextParser(regex string) Parser

type Pattern

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

func NewPattern

func NewPattern(option *PatternOption) *Pattern

NewPattern new pattern defaults:

CleanRedundantAt: true
FuzzyAt: false

func (*Pattern) Add

func (p *Pattern) Add(typ string, optional bool, parse Parser) *Pattern

func (*Pattern) Any

func (p *Pattern) Any() *Pattern

Any match any segment

func (*Pattern) AsRule

func (p *Pattern) AsRule() Rule

AsRule build PatternRule

func (*Pattern) At

func (p *Pattern) At(id ...message.ID) *Pattern

At use regex to match an 'at' segment, if id is not empty, only match specific target

func (*Pattern) Image

func (p *Pattern) Image() *Pattern

Image use regex to match an 'at' segment, if id is not empty, only match specific target

func (*Pattern) Reply

func (p *Pattern) Reply() *Pattern

Reply type zero.PatternReplyMatched

func (*Pattern) SetOptional

func (p *Pattern) SetOptional(v ...bool) *Pattern

SetOptional set previous segment is optional, is v is empty, optional will be true if Pattern is empty, panic

func (*Pattern) Text

func (p *Pattern) Text(regex string) *Pattern

Text use regex to search a 'text' segment

type PatternOption

type PatternOption struct {
	CleanRedundantAt bool
	FuzzyAt          bool
}

PatternOption pattern option

type PatternParsed

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

PatternParsed PatternRule parse result

func (PatternParsed) At

func (p PatternParsed) At() string

At 获取被@者ID

func (PatternParsed) Image

func (p PatternParsed) Image() string

Image 获取图片URL

func (PatternParsed) Raw

func (p PatternParsed) Raw() *message.Segment

Raw 获取原始消息

func (PatternParsed) Reply

func (p PatternParsed) Reply() string

Reply 获取被回复的消息ID

func (PatternParsed) Text

func (p PatternParsed) Text() []string

Text 获取正则表达式匹配到的文本数组

type PatternSegment

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

type Rule

type Rule func(ctx *Ctx) bool

Rule filter the event

func CheckGroup

func CheckGroup(grpID ...int64) Rule

CheckGroup only triggered in specific group

func CheckUser

func CheckUser(userID ...int64) Rule

CheckUser only triggered by specific person

func CommandRule

func CommandRule(commands ...string) Rule

CommandRule check if the message is a command and trim the command name

func FullMatchRule

func FullMatchRule(src ...string) Rule

FullMatchRule check if src has the same copy of the message

func GroupHigherPermission

func GroupHigherPermission(gettarget func(ctx *Ctx) int64) Rule

GroupHigherPermission 群发送者权限高于 target

隐含 OnlyGroup 判断

func KeywordRule

func KeywordRule(src ...string) Rule

KeywordRule check if the message has a keyword or keywords

func PrefixRule

func PrefixRule(prefixes ...string) Rule

PrefixRule check if the message has the prefix and trim the prefix

检查消息前缀

func RegexRule

func RegexRule(regexPattern string) Rule

RegexRule check if the message can be matched by the regex pattern

func ReplyRule

func ReplyRule(messageID int64) Rule

ReplyRule check if the message is replying some message

func ShellRule

func ShellRule(cmd string, model interface{}) Rule

ShellRule 定义shell-like规则

func SuffixRule

func SuffixRule(suffixes ...string) Rule

SuffixRule check if the message has the suffix and trim the suffix

检查消息后缀

func Type

func Type(typ string) Rule

Type check the ctx.Event's type

type State

type State map[string]interface{}

State store the context of a matcher.

type User

type User struct {
	// Private sender
	// https://github.com/botuniverse/onebot-11/blob/master/event/message.md#%E7%A7%81%E8%81%8A%E6%B6%88%E6%81%AF
	ID       int64  `json:"user_id"`
	TinyID   string `json:"tiny_id,omitempty"` // TinyID 在 guild 下为 ID 的 string
	NickName string `json:"nickname,omitempty"`
	Sex      string `json:"sex,omitempty"` // "male"、"female"、"unknown"
	Age      int    `json:"age"`
	Area     string `json:"area,omitempty"`
	// Group member
	// https://github.com/botuniverse/onebot-11/blob/master/event/message.md#%E7%BE%A4%E6%B6%88%E6%81%AF
	Card  string `json:"card,omitempty"`
	Title string `json:"title,omitempty"`
	Level string `json:"level,omitempty"`
	Role  string `json:"role,omitempty"` // "owner"、"admin"、"member"
	// Group anonymous
	AnonymousID   int64  `json:"anonymous_id,omitempty" anonymous:"id"`
	AnonymousName string `json:"anonymous_name,omitempty" anonymous:"name"`
	AnonymousFlag string `json:"anonymous_flag,omitempty" anonymous:"flag"`
}

User is a user on QQ.

func (*User) Name

func (u *User) Name() string

Name displays a simple text version of a user.

func (*User) String

func (u *User) String() string

String displays a simple text version of a user. It is normally a user's card, but falls back to a nickname as available.

Directories

Path Synopsis
Package driver provides the default driver of zerobot
Package driver provides the default driver of zerobot
manager
Package manager provides a simple group plugin Manager.
Package manager provides a simple group plugin Manager.
kv
Package kv provides a simple wrap of goleveldb for multi bucket database
Package kv provides a simple wrap of goleveldb for multi bucket database
rate
Package rate provides a rate limiter hooker, this package is based on golang.org/x/time/rate
Package rate provides a rate limiter hooker, this package is based on golang.org/x/time/rate
utils

Jump to

Keyboard shortcuts

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