modulepackage
0.0.0-20231122134259-c22d8183efca
Repository: https://github.com/fumiama/nanobot.git
Documentation: pkg.go.dev
# README

NanoBot
类ZeroBot的官方QQ频道/群聊全域机器人框架, 简单易用Instructions
Note: This framework is built mainly for Chinese users thus may display hard-coded Chinese prompts during the interaction.
参见 QQ 官方文档。
快速开始(基于插件)
查看
example
文件夹以获取更多信息
开始响应 | 服务列表 | 查看用法 |
package main
import (
_ "github.com/fumiama/NanoBot/example/echo"
nano "github.com/fumiama/NanoBot"
log "github.com/sirupsen/logrus"
)
func main() {
log.SetLevel(log.DebugLevel)
nano.OpenAPI = nano.SandboxAPI
nano.OnMessageFullMatch("help").SetBlock(true).
Handle(func(ctx *nano.Ctx) {
_, _ = ctx.SendPlainMessage(false, "echo string")
})
nano.Run(nil, &nano.Bot{
AppID: "你的AppID",
Token: "你的Token",
Secret: "你的Secret, 可以不填 (QQ群Bot必须填写)",
Intents: nano.IntentPublic,
SuperUsers: []string{"用户ID1", "用户ID2"},
})
}
更多选择(传统的事件驱动)
如果声明了 Handler, 所有插件将被禁用
package main
import (
"strings"
nano "github.com/fumiama/NanoBot"
log "github.com/sirupsen/logrus"
)
func main() {
log.SetLevel(log.DebugLevel)
nano.OpenAPI = nano.SandboxAPI
nano.Run(nil, &nano.Bot{
AppID: "你的AppID",
Token: "你的Token",
Secret: "你的Secret, 可以不填 (QQ群Bot必须填写)",
Intents: nano.IntentPublic,
Handler: &nano.Handler{
OnAtMessageCreate: func(s uint32, bot *nano.Bot, d *nano.Message) {
u := ""
if len(d.Attachments) > 0 {
u = d.Attachments[0].URL
if !strings.HasPrefix(u, "http") {
u = "http://" + u
}
}
_, err := bot.PostMessageToChannel(d.ChannelID, &nano.MessagePost{
Content: "您发送了: " + d.Content,
Image: u,
ReplyMessageID: d.ID,
MessageReference: &nano.MessageReference{
MessageID: d.ID,
},
})
if err != nil {
bot.PostMessageToChannel(d.ChannelID, &nano.MessagePost{
Content: "[ERROR]: " + err.Error(),
ReplyMessageID: d.ID,
})
}
},
},
})
}
Thanks
# Functions
AdminPermission only triggered by the admins or higher permission.
At @某人 https://bot.q.qq.com/wiki/develop/api/openapi/message/message_format.html#%E6%94%AF%E6%8C%81%E7%9A%84%E6%A0%BC%E5%BC%8F.
AtAll @全体成员 https://bot.q.qq.com/wiki/develop/api/openapi/message/message_format.html#%E6%94%AF%E6%8C%81%E7%9A%84%E6%A0%BC%E5%BC%8F.
AtChannel #频道 https://bot.q.qq.com/wiki/develop/api/openapi/message/message_format.html#%E6%94%AF%E6%8C%81%E7%9A%84%E6%A0%BC%E5%BC%8F.
BytesToString 没有内存开销的转换.
ChannelAdminPermission only triggered by the channel admins or higher permission.
CheckChannel only triggered in specific channel.
CheckGuild only triggered in specific guild.
CheckUser only triggered by specific person.
CommandGroupRule check if the message is a command and trim the command name
this rule only supports Message.
CommandRule check if the message is a command and trim the command name
this rule only supports Message.
CreaterPermission only triggered by the creater or higher permission.
Delete 删除插件控制器, 不会删除数据.
DigestID 归一化 id 为 uint64.
Face QQ表情 https://bot.q.qq.com/wiki/develop/api/openapi/message/message_format.html#%E6%94%AF%E6%8C%81%E7%9A%84%E6%A0%BC%E5%BC%8F.
ForEachByPrio iterates through managers by their priority.
FullMatchGroupRule check if src has the same copy of the message.
FullMatchRule check if src has the same copy of the message.
GetBot 获取指定的bot (Ctx)实例.
GetTriggeredMessages 获取被 id 消息触发的回复消息 id.
HasAttachments 消息包含 Attachments (典型: 图片) 返回 true.
HideURL 转义 URL 以避免审核.
Image 普通图片.
ImageBytes 普通图片.
KeywordGroupRule check if the message has a keyword or keywords.
No description provided by the author
No description provided by the author
MessageEscape 消息转义
https://bot.q.qq.com/wiki/develop/api/openapi/message/message_format.html.
MessageUnescape 消息解转义
https://bot.q.qq.com/wiki/develop/api/openapi/message/message_format.html.
MustProvidePhoto 消息不存在图片阻塞120秒至有图片,超时返回 false.
NewFutureEvent 创建一个FutureEvent, 并返回其指针.
NewHTTPEndpointDeleteRequestWithAuth 新建带鉴权头的 HTTP DELETE 请求.
NewHTTPEndpointGetRequestWithAuth 新建带鉴权头的 HTTP GET 请求.
NewHTTPEndpointPatchRequestWithAuth 新建带鉴权头的 HTTP PATCH 请求.
NewHTTPEndpointPostRequestWithAuth 新建带鉴权头的 HTTP POST 请求.
NewHTTPEndpointPutRequestWithAuth 新建带鉴权头的 HTTP PUT 请求.
NewSingle 创建反并发中间件.
On 添加新的指定消息类型的匹配器(默认Engine).
OnAudioFinish ...
OnAudioOffMic ...
OnAudioOnMic ...
OnAudioOrLiveChannelMemberEnter ...
OnAudioOrLiveChannelMemberExit ...
OnAudioStart ...
OnChannelCreate ...
OnChannelDelete ...
OnChannelUpdate ...
OnForumPostCreate ...
OnForumPostDelete ...
OnForumPublishAuditResult ...
OnForumReplyCreate ...
OnForumReplyDelete ...
OnForumThreadCreate ...
OnForumThreadDelete ...
OnForumThreadUpdate ...
OnGuildCreate ...
OnGuildDelete ...
OnGuildMemberAdd ...
OnGuildMemberRemove ...
OnGuildMemberUpdate ...
OnGuildUpdate ...
OnlyChannel 必须是频道 Channel.
OnlyDirect 必须是频道私聊.
OnlyGuild 必须是频道消息.
OnlyPrivate is !OnlyPublic (包括QQ私聊).
OnlyPublic 消息类型包含 At 或 Public (包括QQ群).
OnlyQQ 必须是 QQ 消息.
OnlyQQGroup 只在 QQ 群.
OnlyQQPrivate 只在 QQ 私聊.
OnlyToMe only triggered in conditions of @bot or begin with the nicknames
this rule only supports Message.
OnMessage ...
OnMessageAuditPass ...
OnMessageAuditReject ...
OnMessageCommand ...
OnMessageCommandGroup ...
OnMessageDelete ...
OnMessageFullMatch ...
OnMessageFullMatchGroup ...
OnMessageKeyword ...
OnMessageKeywordGroup ...
OnMessagePrefix ...
OnMessagePrefixGroup ...
OnMessageReactionAdd ...
OnMessageReactionRemove ...
OnMessageRegex ...
OnMessageShell shell命令触发器.
OnMessageSuffix ...
OnMessageSuffixGroup ...
OnOpenForumPostCreate ...
OnOpenForumPostDelete ...
OnOpenForumReplyCreate ...
OnOpenForumReplyDelete ...
OnOpenForumThreadCreate ...
OnOpenForumThreadDelete ...
OnOpenForumThreadUpdate ...
ParseShell 将指令转换为指令参数.
PrefixGroupRule check if the text message has the prefix and trim the prefix
检查消息前缀.
PrefixRule check if the text message has the prefix and trim the prefix
检查消息前缀.
RangeBot 遍历所有bot (Ctx)实例
单次操作返回 true 则继续遍历,否则退出.
Record QQ 语音 https://bot.q.qq.com/wiki/develop/api-231017/server-inter/message/send-receive/rich-text-media.html.
RegexRule check if the message can be matched by the regex pattern.
Register 注册插件控制器.
ReplyRule check if the message is replying some message
this rule only supports Message.
Reply 回复 https://github.com/botuniverse/onebot-11/tree/master/message/segment.md#%E5%9B%9E%E5%A4%8D.
ReplyWithMessage returns a reply message.
Run clients and block self in listening last one.
ShellRule 定义shell-like规则
this rule only supports Message.
Start clients without blocking.
StoreMatcher store a matcher to matcher list.
StoreTempMatcher store a matcher only triggered once.
StringToBytes 没有内存开销的转换.
SuffixGroupRule check if the text message has the suffix and trim the suffix
检查消息后缀.
SuffixRule check if the text message has the suffix and trim the suffix
检查消息后缀.
SuperUserPermission only triggered by the bot's owner.
Text 纯文本.
UnderlineToCamel convert abc_def to AbcDef.
UserOrChannelAdmin 允许用户单独使用或频道管理使用.
UserOrGrpAdmin 允许用户单独使用或群管使用.
Video QQ 视频 https://bot.q.qq.com/wiki/develop/api-231017/server-inter/message/send-receive/rich-text-media.html.
WithKeyFn 指定反并发的 Key.
WithPostFn 指定反并发拦截后的操作.
WriteBodyByMultipartFormData 使用 multipart/form-data 上传.
WriteBodyFromJSON 从 json 结构体 ptr 写入 bytes.Buffer, 忽略 error (内部使用不会出错).
WriteHTTPQueryIfNotNil 如果非空则将请求添加到 baseurl 后
ex.
# Constants
AccessTokenAPI 获取接口凭证的 API.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
公告.
闲聊.
开黑.
攻略.
应用子频道.
语音子频道.
论坛子频道.
直播子频道.
保留,不可用.
保留,不可用.
子频道分组.
文字子频道.
silk.
暂不开放.
png/jpg.
mp4.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
IntentAllGuild 监听全部频道事件.
https://bot.q.qq.com/wiki/develop/api/gateway/intents.html.
https://bot.q.qq.com/wiki/develop/api/gateway/intents.html.
https://bot.q.qq.com/wiki/develop/api/gateway/intents.html.
https://bot.q.qq.com/wiki/develop/api/gateway/intents.html.
https://bot.q.qq.com/wiki/develop/api/gateway/intents.html.
https://bot.q.qq.com/wiki/develop/api/gateway/intents.html.
https://bot.q.qq.com/wiki/develop/api/gateway/intents.html.
IntentPrivate 监听频道私域事件.
IntentPublic 监听频道公域事件.
https://bot.q.qq.com/wiki/develop/api/gateway/intents.html.
https://bot.q.qq.com/wiki/develop/api/gateway/intents.html.
https://bot.q.qq.com/wiki/develop/api/gateway/intents.html.
https://bot.q.qq.com/wiki/develop/api/gateway/intents.html.
https://bot.q.qq.com/wiki/develop/api/gateway/intents.html.
https://bot.q.qq.com/wiki/develop/api/gateway/intents.html.
Md5File ...
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Receive.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Send/Receive.
Receive/Reply.
Receive.
Reply.
Send.
Receive.
Receive.
Send.
群主管理员+指定成员,可使用 修改子频道权限接口 指定成员.
群主管理员可见.
公开频道.
管理员.
全体成员.
子频道管理员.
群主/创建者.
SandboxAPI 沙箱环境接口域名.
群主管理员+指定成员,可使用 修改子频道权限接口 指定成员.
所有人.
无效类型.
StandardAPI 正式环境接口域名.
StorageFolder 插件控制数据目录.
SuperUserAllQQUsers 使所有 QQ 用户成为超级用户.
# Variables
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
OpenAPI 实际使用的 API, 默认 StandardAPI, 可自行赋值配置.
# Structs
Announces 公告对象
https://bot.q.qq.com/wiki/develop/api/openapi/announces/model.html#announces.
AudioAction 音频事件
https://bot.q.qq.com/wiki/develop/api/openapi/audio/model.html.
AudioControl 控制子频道 channel_id 下的音频
https://bot.q.qq.com/wiki/develop/api/openapi/audio/audio_control.html.
AudioLiveChannelUsersChange 音视频/直播子频道成员进出事件
https://bot.q.qq.com/wiki/develop/api/gateway/audio_or_live_channel_member.html.
AuditResult 论坛帖子审核结果事件
https://bot.q.qq.com/wiki/develop/api/openapi/forum/model.html#auditresult.
Bot 一个机器人实例的配置.
Channel 子频道对象
https://bot.q.qq.com/wiki/develop/api/openapi/channel/model.html.
ChannelPatch 子频道 patch 操作所用对象
https://bot.q.qq.com/wiki/develop/api/openapi/channel/patch_channel.html.
ChannelPermissions 子频道权限对象
https://bot.q.qq.com/wiki/develop/api/openapi/channel_permissions/model.html.
ChannelPost 子频道 post 操作所用对象
https://bot.q.qq.com/wiki/develop/api/openapi/channel/post_channels.html.
CodeMessageBase 各种消息都有的 code + message 基类.
No description provided by the author
DMS 私信会话对象
https://bot.q.qq.com/wiki/develop/api/openapi/dms/model.html.
Emoji 表情对象
https://bot.q.qq.com/wiki/develop/api/openapi/emoji/model.html.
Engine is the pre_handler, mid_handler, post_handler manager.
Event ...
EventReady https://bot.q.qq.com/wiki/develop/api/gateway/reference.html#_2-%E9%89%B4%E6%9D%83%E8%BF%9E%E6%8E%A5.
FilePost QQ 富媒体消息发送请求参数
https://bot.q.qq.com/wiki/develop/api-231017/server-inter/message/send-receive/rich-text-media.html.
FutureEvent 是 ZeroBot 交互式的核心,用于异步获取指定事件.
Guild 频道对象
https://bot.q.qq.com/wiki/develop/api/openapi/guild/model.html.
GuildRoleChannelID 频道身份组成员返回 只填充了子频道 id 字段的对象
https://bot.q.qq.com/wiki/develop/api/openapi/guild/put_guild_member_role.html#%E5%8F%82%E6%95%B0.
GuildRoleCreate 创建频道身份组响应
https://bot.q.qq.com/wiki/develop/api/openapi/guild/post_guild_role.html#%E8%BF%94%E5%9B%9E.
GuildRoleList 频道身份组列表
https://bot.q.qq.com/wiki/develop/api/openapi/guild/get_guild_roles.html#%E8%BF%94%E5%9B%9E.
GuildRolePatch 修改频道身份组
https://bot.q.qq.com/wiki/develop/api/openapi/guild/patch_guild_role.html#%E8%BF%94%E5%9B%9E.
Handler 事件订阅
https://bot.q.qq.com/wiki/develop/api/gateway/intents.html.
InlineKeyboard 消息按钮对象
https://bot.q.qq.com/wiki/develop/api/openapi/message/message_keyboard.html.
InlineKeyboardButton https://bot.q.qq.com/wiki/develop/api/openapi/message/message_keyboard.html#button.
InlineKeyboardButtonAction https://bot.q.qq.com/wiki/develop/api/openapi/message/message_keyboard.html#action.
InlineKeyboardButtonActionPermission https://bot.q.qq.com/wiki/develop/api/openapi/message/message_keyboard.html#permission.
InlineKeyboardButtonRenderData https://bot.q.qq.com/wiki/develop/api/openapi/message/message_keyboard.html#renderdata.
InlineKeyboardRow https://bot.q.qq.com/wiki/develop/api/openapi/message/message_keyboard.html#inlinekeyboardrow.
Matcher 是 ZeroBot 匹配和处理事件的最小单元.
Member 成员对象 Member and MemberWithGuildID
https://bot.q.qq.com/wiki/develop/api/openapi/member/model.html.
Message 消息对象
https://bot.q.qq.com/wiki/develop/api/openapi/message/model.html#%E6%B6%88%E6%81%AF%E5%AF%B9%E8%B1%A1-message.
MessageArk https://bot.q.qq.com/wiki/develop/api/openapi/message/model.html#messageark.
MessageArkKV https://bot.q.qq.com/wiki/develop/api/openapi/message/model.html#messagearkkv.
MessageArkObj https://bot.q.qq.com/wiki/develop/api/openapi/message/model.html#messagearkobj.
MessageArkObjKV https://bot.q.qq.com/wiki/develop/api/openapi/message/model.html#messagearkobjkv.
MessageAttachment https://bot.q.qq.com/wiki/develop/api/openapi/message/model.html#messageattachment.
MessageAudited 消息审核对象
https://bot.q.qq.com/wiki/develop/api/openapi/message/model.html#%E6%B6%88%E6%81%AF%E5%AE%A1%E6%A0%B8%E5%AF%B9%E8%B1%A1-messageaudited.
MessageDelete https://bot.q.qq.com/wiki/develop/api/openapi/message/model.html#messagedelete.
MessageEmbed https://bot.q.qq.com/wiki/develop/api/openapi/message/model.html#messageembed.
MessageEmbedField https://bot.q.qq.com/wiki/develop/api/openapi/message/model.html#messageembedfield.
MessageEmbedThumbnail https://bot.q.qq.com/wiki/develop/api/openapi/message/model.html#messageembedthumbnail.
MessageKeyboard https://bot.q.qq.com/wiki/develop/api/openapi/message/model.html#messagekeyboard.
MessageMarkdown https://bot.q.qq.com/wiki/develop/api/openapi/message/model.html#messagemarkdown.
MessageMarkdownParams https://bot.q.qq.com/wiki/develop/api/openapi/message/model.html#messagemarkdownparams.
MessageMedia used in MessagePost.
MessagePost 发送消息所需参数
https://bot.q.qq.com/wiki/develop/api/openapi/message/post_messages.html#%E9%80%9A%E7%94%A8%E5%8F%82%E6%95%B0.
MessageReaction https://bot.q.qq.com/wiki/develop/api/openapi/reaction/model.html#messagereaction.
MessageReactionUsers https://bot.q.qq.com/wiki/develop/api/openapi/reaction/get_reaction_users.html#%E8%BF%94%E5%9B%9E.
MessageReference https://bot.q.qq.com/wiki/develop/api/openapi/message/model.html#messagereference.
MessageSegment impl the single message MessageSegment 消息数组.
MessageSetting 频道消息频率设置对象
https://bot.q.qq.com/wiki/develop/api/openapi/setting/model.html.
OpCodeIdentifyMessage https://bot.q.qq.com/wiki/develop/api/gateway/reference.html#_2-%E9%89%B4%E6%9D%83%E8%BF%9E%E6%8E%A5.
PinsMessage 精华消息对象
https://bot.q.qq.com/wiki/develop/api/openapi/pins/model.html#pinsmessage.
Post 话题频道内对主题的评论称为帖子
https://bot.q.qq.com/wiki/develop/api/openapi/forum/model.html#post.
PostInfo 帖子事件包含的帖子内容信息
https://bot.q.qq.com/wiki/develop/api/openapi/forum/model.html#postinfo.
QQRobotStatus https://bot.q.qq.com/wiki/develop/api-231017/server-inter/group.html#%E4%BA%8B%E4%BB%B6.
ReactionTarget https://bot.q.qq.com/wiki/develop/api/openapi/reaction/model.html#reactiontarget.
RecommendChannel 推荐子频道对象
https://bot.q.qq.com/wiki/develop/api/openapi/announces/model.html#recommendchannel.
Reply 话题频道对帖子回复或删除时生产该事件中包含该对象
https://bot.q.qq.com/wiki/develop/api/openapi/forum/model.html#reply.
ReplyInfo 回复事件包含的回复内容信息
https://bot.q.qq.com/wiki/develop/api/openapi/forum/model.html#replyinfo.
Role 频道身份组对象
https://bot.q.qq.com/wiki/develop/api/openapi/guild/role_model.html.
RoleMembers 频道身份组成员列表
https://bot.q.qq.com/wiki/develop/api/openapi/member/get_role_members.html#%E8%BF%94%E5%9B%9E.
Schedule 日程对象
https://bot.q.qq.com/wiki/develop/api/openapi/schedule/model.html.
ShardWSSGateway 带分片 WSS 接入点响应数据
https://bot.q.qq.com/wiki/develop/api/openapi/wss/shard_url_get.html#%E8%BF%94%E5%9B%9E.
Single 反并发.
Thread 话题频道内发表的主帖称为主题
https://bot.q.qq.com/wiki/develop/api/openapi/forum/model.html#thread.
ThreadInfo 帖子事件包含的主帖内容相关信息
https://bot.q.qq.com/wiki/develop/api/openapi/forum/model.html#threadinfo.
User 用户对象
https://bot.q.qq.com/wiki/develop/api/openapi/user/model.html.
WebsocketPayload payload 指的是在 websocket 连接上传输的数据,网关的上下行消息采用的都是同一个结构
https://bot.q.qq.com/wiki/develop/api/gateway/reference.html.
# Type aliases
AudioControlStatus https://bot.q.qq.com/wiki/develop/api/openapi/audio/model.html#status.
ChannelSubType https://bot.q.qq.com/wiki/develop/api/openapi/channel/model.html#channelsubtype.
ChannelType https://bot.q.qq.com/wiki/develop/api/openapi/channel/model.html#channeltype.
FileType 媒体类型.
HTTPRequsetConstructer ...
InlineKeyboardButtonActionPermissionType https://bot.q.qq.com/wiki/develop/api/openapi/message/message_keyboard.html#permissiontype.
InlineKeyboardButtonActionType https://bot.q.qq.com/wiki/develop/api/openapi/message/message_keyboard.html#actiontype.
InlineKeyboardButtonRenderDataStyle https://bot.q.qq.com/wiki/develop/api/openapi/message/message_keyboard.html#renderstyle.
Message impl the array form of message.
No description provided by the author
No description provided by the author
OpCode https://bot.q.qq.com/wiki/develop/api/gateway/opcode.html.
Option 配置项.
PrivateType https://bot.q.qq.com/wiki/develop/api/openapi/channel/model.html#privatetype.
No description provided by the author
ReactionTargetType https://bot.q.qq.com/wiki/develop/api/openapi/reaction/model.html#reactiontargettype.
No description provided by the author
SpeakPermission https://bot.q.qq.com/wiki/develop/api/openapi/channel/model.html#speakpermission.
State store the context of a matcher.