nano

package module
v0.0.0-...-c22d818 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2023 License: AGPL-3.0 Imports: 38 Imported by: 21

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, 所有插件将被禁用

event-based example

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

Documentation

Index

Constants

View Source
const (
	IntentGuilds                   = 1 << 0
	IntentGuildMembers             = 1 << 1
	IntentGuildMessages            = 1 << 9
	IntentGuildMessageReactions    = 1 << 10
	IntentDirectMessage            = 1 << 12
	IntentOpenForumsEvent          = 1 << 18
	IntentAudioOrLiveChannelMember = 1 << 19
	IntentQQ                       = 1 << 25
	IntentInteraction              = 1 << 26
	IntentMessageAudit             = 1 << 27
	IntentForumsEvent              = 1 << 28
	IntentAudioAction              = 1 << 29
	IntentPublicGuildMessages      = 1 << 30

	// IntentAllGuild 监听全部频道事件
	IntentAllGuild = IntentGuilds | IntentGuildMembers | IntentGuildMessages | IntentGuildMessageReactions |
		IntentDirectMessage | IntentOpenForumsEvent | IntentAudioOrLiveChannelMember | IntentInteraction |
		IntentMessageAudit | IntentForumsEvent | IntentAudioAction | IntentPublicGuildMessages
	// IntentPublic 监听频道公域事件
	IntentGuildPublic = IntentGuilds | IntentGuildMembers | IntentGuildMessageReactions |
		IntentDirectMessage | IntentOpenForumsEvent | IntentAudioOrLiveChannelMember | IntentInteraction |
		IntentMessageAudit | IntentAudioAction | IntentPublicGuildMessages
	// IntentPrivate 监听频道私域事件
	IntentGuildPrivate = IntentGuilds | IntentGuildMembers | IntentGuildMessages | IntentGuildMessageReactions |
		IntentDirectMessage | IntentAudioOrLiveChannelMember | IntentInteraction |
		IntentMessageAudit | IntentForumsEvent | IntentAudioAction
)

https://bot.q.qq.com/wiki/develop/api/gateway/intents.html

View Source
const (
	// StorageFolder 插件控制数据目录
	StorageFolder = "data/control/"
	// Md5File ...
	Md5File = StorageFolder + "stor.spb"
)
View Source
const (
	// StandardAPI 正式环境接口域名
	StandardAPI = `https://api.sgroup.qq.com`
	// SandboxAPI 沙箱环境接口域名
	SandboxAPI = `https://sandbox.api.sgroup.qq.com`
	// AccessTokenAPI 获取接口凭证的 API
	AccessTokenAPI = "https://bots.qq.com/app/getAppAccessToken"
)
View Source
const (
	ChannelTypeText        ChannelType    = iota // 文字子频道
	ChannelTypeReserved1                         // 保留,不可用
	ChannelTypeAudio                             // 语音子频道
	ChannelTypeReserved2                         // 保留,不可用
	ChannelTypeSubchannel                        // 子频道分组
	ChannelTypeLive        = 10000 + iota        // 直播子频道
	ChannelTypeApplication                       // 应用子频道
	ChannelTypeForum                             // 论坛子频道
)
View Source
const (
	SpeakPermissionInvalid        = iota // 无效类型
	SpeakPermissionAll                   // 所有人
	SpeakPermissionAdminAndShimei        // 群主管理员+指定成员,可使用 修改子频道权限接口 指定成员
)
View Source
const (
	RoleIDAll          = "1" // 全体成员
	RoleIDAdmin        = "2" // 管理员
	RoleIDCreater      = "4" // 群主/创建者
	RoleIDChannelAdmin = "5" // 子频道管理员
)
View Source
const (
	FileTypeImage = iota + 1 // png/jpg
	FileTypeVideo            // mp4
	FileTypeAudio            // silk
	FileTypeFile             // 暂不开放
)
View Source
const (
	// SuperUserAllQQUsers 使所有 QQ 用户成为超级用户
	SuperUserAllQQUsers = "AllQQUsers"
)

Variables

View Source
var (
	ErrEmptyToken    = errors.New("empty token")
	ErrInvalidExpire = errors.New("invalid expire")
)
View Source
var (
	ErrEmptyMessagePost = errors.New("empty message post")
)
View Source
var (
	ErrMustGiveChannelID = errors.New("must give channel_id")
)
View Source
var (
	OpenAPI = StandardAPI // OpenAPI 实际使用的 API, 默认 StandardAPI, 可自行赋值配置
)

Functions

func AdminPermission

func AdminPermission(ctx *Ctx) bool

AdminPermission only triggered by the admins or higher permission

func BytesToString

func BytesToString(b []byte) string

BytesToString 没有内存开销的转换

func ChannelAdminPermission

func ChannelAdminPermission(ctx *Ctx) bool

ChannelAdminPermission only triggered by the channel admins or higher permission

func CreaterPermission

func CreaterPermission(ctx *Ctx) bool

CreaterPermission only triggered by the creater or higher permission

func Delete

func Delete(service string)

Delete 删除插件控制器, 不会删除数据

func DigestID

func DigestID(id string) uint64

DigestID 归一化 id 为 uint64

func ForEachByPrio

func ForEachByPrio(iterator func(i int, manager *ctrl.Control[*Ctx]) bool)

ForEachByPrio iterates through managers by their priority.

func GetTriggeredMessages

func GetTriggeredMessages(id string) []string

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

func HasAttachments

func HasAttachments(ctx *Ctx) bool

HasAttachments 消息包含 Attachments (典型: 图片) 返回 true

func HideURL

func HideURL(s string) string

HideURL 转义 URL 以避免审核

func Lookup

func Lookup(service string) (*ctrl.Control[*Ctx], bool)

func MessageUnescape

func MessageUnescape(text string) string

MessageUnescape 消息解转义

https://bot.q.qq.com/wiki/develop/api/openapi/message/message_format.html

func NewHTTPEndpointDeleteRequestWithAuth

func NewHTTPEndpointDeleteRequestWithAuth(ep string, contenttype string, auth, appid string, body io.Reader) (*http.Request, error)

NewHTTPEndpointDeleteRequestWithAuth 新建带鉴权头的 HTTP DELETE 请求

func NewHTTPEndpointGetRequestWithAuth

func NewHTTPEndpointGetRequestWithAuth(ep string, contenttype string, auth, appid string, body io.Reader) (*http.Request, error)

NewHTTPEndpointGetRequestWithAuth 新建带鉴权头的 HTTP GET 请求

func NewHTTPEndpointPatchRequestWithAuth

func NewHTTPEndpointPatchRequestWithAuth(ep string, contenttype string, auth, appid string, body io.Reader) (*http.Request, error)

NewHTTPEndpointPatchRequestWithAuth 新建带鉴权头的 HTTP PATCH 请求

func NewHTTPEndpointPostRequestWithAuth

func NewHTTPEndpointPostRequestWithAuth(ep string, contenttype string, auth, appid string, body io.Reader) (*http.Request, error)

NewHTTPEndpointPostRequestWithAuth 新建带鉴权头的 HTTP POST 请求

func NewHTTPEndpointPutRequestWithAuth

func NewHTTPEndpointPutRequestWithAuth(ep string, contenttype string, auth, appid string, body io.Reader) (*http.Request, error)

NewHTTPEndpointPutRequestWithAuth 新建带鉴权头的 HTTP PUT 请求

func OnlyChannel

func OnlyChannel(ctx *Ctx) bool

OnlyChannel 必须是频道 Channel

func OnlyDirect

func OnlyDirect(ctx *Ctx) bool

OnlyDirect 必须是频道私聊

func OnlyGuild

func OnlyGuild(ctx *Ctx) bool

OnlyGuild 必须是频道消息

func OnlyPrivate

func OnlyPrivate(ctx *Ctx) bool

OnlyPrivate is !OnlyPublic (包括QQ私聊)

func OnlyPublic

func OnlyPublic(ctx *Ctx) bool

OnlyPublic 消息类型包含 At 或 Public (包括QQ群)

func OnlyQQ

func OnlyQQ(ctx *Ctx) bool

OnlyQQ 必须是 QQ 消息

func OnlyQQGroup

func OnlyQQGroup(ctx *Ctx) bool

OnlyQQGroup 只在 QQ 群

func OnlyQQPrivate

func OnlyQQPrivate(ctx *Ctx) bool

OnlyQQPrivate 只在 QQ 私聊

func OnlyToMe

func OnlyToMe(ctx *Ctx) bool

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

this rule only supports Message

func ParseShell

func ParseShell(s string) []string

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

func RangeBot

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

RangeBot 遍历所有bot (Ctx)实例

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

func Run

func Run(preblock func(), bots ...*Bot) error

Run clients and block self in listening last one

func Start

func Start(bots ...*Bot) error

Start clients without blocking

func StringToBytes

func StringToBytes(s string) (b []byte)

StringToBytes 没有内存开销的转换

func SuperUserPermission

func SuperUserPermission(ctx *Ctx) bool

SuperUserPermission only triggered by the bot's owner

func UnderlineToCamel

func UnderlineToCamel(s string) string

UnderlineToCamel convert abc_def to AbcDef

func UserOrChannelAdmin

func UserOrChannelAdmin(ctx *Ctx) bool

UserOrChannelAdmin 允许用户单独使用或频道管理使用

func UserOrGrpAdmin

func UserOrGrpAdmin(ctx *Ctx) bool

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

func WriteBodyByMultipartFormData

func WriteBodyByMultipartFormData(params ...any) (*bytes.Buffer, string, error)

WriteBodyByMultipartFormData 使用 multipart/form-data 上传

func WriteBodyFromJSON

func WriteBodyFromJSON(ptr any) *bytes.Buffer

WriteBodyFromJSON 从 json 结构体 ptr 写入 bytes.Buffer, 忽略 error (内部使用不会出错)

func WriteHTTPQueryIfNotNil

func WriteHTTPQueryIfNotNil(baseurl string, queries ...any) string

WriteHTTPQueryIfNotNil 如果非空则将请求添加到 baseurl 后

ex. WriteHTTPQueryIfNotNil("http://a.com/api", "a", 0, "b", 1, "c", 2) is http://a.com/api?b=1&c=2

Types

type Announces

type Announces struct {
	GuildID           string             `json:"guild_id,omitempty"`
	ChannelID         string             `json:"channel_id,omitempty"`
	MessageID         string             `json:"message_id,omitempty"`
	AnnouncesType     uint32             `json:"announces_type,omitempty"` // 公告类别 0:成员公告 1:欢迎公告,默认成员公告
	RecommendChannels []RecommendChannel `json:"recommend_channels,omitempty"`
}

Announces 公告对象

https://bot.q.qq.com/wiki/develop/api/openapi/announces/model.html#announces

type AudioAction

type AudioAction struct {
	ChannelID string `json:"channel_id"`
	GuildID   string `json:"guild_id"`
	AudioURL  string `json:"audio_url"`
	Text      string `json:"text"`
}

AudioAction 音频事件

https://bot.q.qq.com/wiki/develop/api/openapi/audio/model.html

type AudioControl

type AudioControl struct {
	AudioURL string             `json:"audio_url"`
	Text     string             `json:"text"`
	Status   AudioControlStatus `json:"status"`
}

AudioControl 控制子频道 channel_id 下的音频

https://bot.q.qq.com/wiki/develop/api/openapi/audio/audio_control.html

type AudioControlStatus

type AudioControlStatus int

AudioControlStatus https://bot.q.qq.com/wiki/develop/api/openapi/audio/model.html#status

const (
	AudioControlStatusStart AudioControlStatus = iota
	AudioControlStatusPause
	AudioControlStatusResume
	AudioControlStatusStop
)

type AudioLiveChannelUsersChange

type AudioLiveChannelUsersChange struct {
	GuildID     string `json:"guild_id"`
	ChannelID   string `json:"channel_id"`
	ChannelType int    `json:"channel_type"`
	UserID      string `json:"user_id"`
}

AudioLiveChannelUsersChange 音视频/直播子频道成员进出事件

https://bot.q.qq.com/wiki/develop/api/gateway/audio_or_live_channel_member.html

type AuditResult

type AuditResult struct {
	GuildID   string `json:"guild_id"`
	ChannelID string `json:"channel_id"`
	AuthorID  string `json:"author_id"`
	ThreadID  string `json:"thread_id"`
	PostID    string `json:"post_id"`
	ReplyID   string `json:"reply_id"`
	Type      uint32 `json:"type"`
	Result    uint32 `json:"result"`
	ErrMsg    string `json:"err_msg"`
}

AuditResult 论坛帖子审核结果事件

https://bot.q.qq.com/wiki/develop/api/openapi/forum/model.html#auditresult

type Bot

type Bot struct {
	AppID string `yaml:"AppID"` // AppID is BotAppID(开发者ID)
	Token string `yaml:"Token"` // Token is 机器人令牌 有 Secret 则使用新版 API

	Secret     string        `yaml:"Secret"`     // Secret is 机器人令牌 V2 (AppSecret/ClientSecret) 沙盒目前虽然能登录但无法收发消息
	SuperUsers []string      `yaml:"SuperUsers"` // SuperUsers 超级用户, 特殊: AllQQUsers 将使所有 QQ 用户成为超级用户
	Timeout    time.Duration `yaml:"Timeout"`    // Timeout is API 调用超时
	Handler    *Handler      `yaml:"-"`          // Handler 注册对各种事件的处理
	Intents    uint32        `yaml:"Intents"`    // Intents 欲接收的事件
	ShardIndex uint8         `yaml:"ShardIndex"` // ShardIndex 本连接为第几个分片, 默认 1, 0 为不使用分片
	ShardCount uint8         `yaml:"ShardCount"` // ShardCount 分片总数

	Properties json.RawMessage `yaml:"Properties"` // Properties 一些环境变量, 目前没用
	// contains filtered or unexported fields
}

Bot 一个机器人实例的配置

func (*Bot) AddRoleToMemberOfGuild

func (bot *Bot) AddRoleToMemberOfGuild(guildid, userid, roleid, channelid string) (string, error)

AddRoleToMemberOfGuild 将频道 guild_id 下的用户 user_id 添加到身份组 role_id

https://bot.q.qq.com/wiki/develop/api/openapi/guild/put_guild_member_role.html

返回 channel_id

func (*Bot) AtMe

func (bot *Bot) AtMe() string

AtMe 返回 <@!bot.ready.User.ID>

func (*Bot) Authorization

func (bot *Bot) Authorization() string

Authorization 返回 Authorization Header value

func (*Bot) CloseMicInChannel

func (bot *Bot) CloseMicInChannel(id string) error

CloseMicInChannel 机器人在 channel_id 对应的语音子频道下麦

https://bot.q.qq.com/wiki/develop/api/openapi/audio/delete_mic.html

func (*Bot) Connect

func (bot *Bot) Connect() *Bot

Connect 连接到 Gateway + 鉴权连接

https://bot.q.qq.com/wiki/develop/api/gateway/reference.html#_1-%E8%BF%9E%E6%8E%A5%E5%88%B0-gateway

func (*Bot) ControlAudioInChannel

func (bot *Bot) ControlAudioInChannel(id string, control *AudioControl) error

ControlAudioInChannel 控制子频道 channel_id 下的音频

https://bot.q.qq.com/wiki/develop/api/openapi/audio/audio_control.html

func (*Bot) CreateChannelInGuild

func (bot *Bot) CreateChannelInGuild(id string, config *ChannelPost) (*Channel, error)

CreateChannelInGuild 用于在 guild_id 指定的频道下创建一个子频道

https://bot.q.qq.com/wiki/develop/api/openapi/channel/post_channels.html

func (*Bot) CreateGuildRoleOf

func (bot *Bot) CreateGuildRoleOf(id string, name string, color uint32, hoist int32) (*GuildRoleCreate, error)

CreateGuildRoleOf 创建频道身份组

https://bot.q.qq.com/wiki/develop/api/openapi/guild/post_guild_role.html

参数为非必填,但至少需要传其中之一,默认为空或 0

func (*Bot) CreatePrivateChat

func (bot *Bot) CreatePrivateChat(guildid, userid string) (*DMS, error)

CreatePrivateChat 机器人和在同一个频道内的成员创建私信会话

https://bot.q.qq.com/wiki/develop/api/openapi/dms/post_dms.html

func (*Bot) CreateScheduleInChannel

func (bot *Bot) CreateScheduleInChannel(id string, schedule *Schedule) error

CreateScheduleInChannel 在 channel_id 指定的日程子频道下创建一个日程

https://bot.q.qq.com/wiki/develop/api/openapi/schedule/post_schedule.html

schedule 会被写入返回的对象

func (*Bot) DeleteAnnounceInGuild

func (bot *Bot) DeleteAnnounceInGuild(guildid, messageid string) error

DeleteAnnounceInGuild 删除频道 guild_id 下指定 message_id 的全局公告

https://bot.q.qq.com/wiki/develop/api/openapi/announces/delete_guild_announces.html

message_id 有值时,会校验 message_id 合法性,若不校验校验 message_id,请将 message_id 设置为 all

func (*Bot) DeleteChannelOf

func (bot *Bot) DeleteChannelOf(id string) error

DeleteChannelOf 删除 channel_id 指定的子频道

https://bot.q.qq.com/wiki/develop/api/openapi/channel/delete_channel.html

func (*Bot) DeleteGuildMemberOf

func (bot *Bot) DeleteGuildMemberOf(guildid, userid string, addblklst bool, delhistmsgdays int) error

DeleteGuildMemberOf 删除 guild_id 指定的频道下的成员 user_id

https://bot.q.qq.com/wiki/develop/api/openapi/member/delete_member.html

- delhistmsgdays: 消息撤回时间范围仅支持固定的天数:3,7,15,30。 特殊的时间范围:-1: 撤回全部消息。默认值为0不撤回任何消息。

func (*Bot) DeleteGuildRoleOf

func (bot *Bot) DeleteGuildRoleOf(guildid, roleid string) error

DeleteGuildRoleOf 删除频道 guild_id下 role_id 对应的身份组

https://bot.q.qq.com/wiki/develop/api/openapi/guild/delete_guild_role.html

func (*Bot) DeleteMessageInChannel

func (bot *Bot) DeleteMessageInChannel(channelid, messageid string, hidetip bool) error

DeleteMessageInChannel 回子频道 channel_id 下的消息 message_id

https://bot.q.qq.com/wiki/develop/api/openapi/message/delete_message.html

func (*Bot) DeleteMessageOfUser

func (bot *Bot) DeleteMessageOfUser(guildid, messageid string, hidetip bool) error

DeleteMessageOfUser 撤回私信频道 guild_id 中 message_id 指定的私信消息, 只能用于撤回机器人自己发送的私信

https://bot.q.qq.com/wiki/develop/api/openapi/dms/delete_dms.html

func (*Bot) DeleteMessageReaction

func (bot *Bot) DeleteMessageReaction(channelid, messageid string, emoji Emoji) error

DeleteMessageReaction 删除自己对消息 message_id 的表情表态

https://bot.q.qq.com/wiki/develop/api/openapi/reaction/delete_own_message_reaction.html

func (*Bot) DeleteOpenAPI

func (bot *Bot) DeleteOpenAPI(ep, contenttype string, body io.Reader) error

DeleteOpenAPI 向 ep 发送 DELETE 请求

func (*Bot) DeleteOpenAPIWithPtr

func (bot *Bot) DeleteOpenAPIWithPtr(ep, contenttype string, ptr any, body io.Reader) error

DeleteOpenAPIWithPtr 带返回值地向 ep 发送 DELETE 请求

func (*Bot) DeleteScheduleInChannel

func (bot *Bot) DeleteScheduleInChannel(channelid string, scheduleid string) error

DeleteScheduleInChannel 删除日程子频道 channel_id 下 schedule_id 指定的日程

https://bot.q.qq.com/wiki/develop/api/openapi/schedule/delete_schedule.html

func (*Bot) DeleteThreadInChannel

func (bot *Bot) DeleteThreadInChannel(channelid, threadid string) error

DeleteThreadInChannel 删除指定子频道下的某个帖子

https://bot.q.qq.com/wiki/develop/api/openapi/forum/delete_thread.html

func (*Bot) GetAppAccessTokenNoContext

func (bot *Bot) GetAppAccessTokenNoContext() error

GetAppAccessTokenNoContext 获取接口凭证并保存到 bot.Token

https://bot.q.qq.com/wiki/develop/api-231017/dev-prepare/interface-framework/api-use.html#%E8%8E%B7%E5%8F%96%E6%8E%A5%E5%8F%A3%E5%87%AD%E8%AF%81

func (*Bot) GetChannelByID

func (bot *Bot) GetChannelByID(id string) (*Channel, error)

GetChannelByID 用于获取 channel_id 指定的子频道的详情

https://bot.q.qq.com/wiki/develop/api/openapi/channel/get_channel.html

func (*Bot) GetChannelPermissionsOfRole

func (bot *Bot) GetChannelPermissionsOfRole(channelid, roleid string) (*ChannelPermissions, error)

GetChannelPermissionsOfRole 获取子频道 channel_id 下身份组 role_id 的权限

https://bot.q.qq.com/wiki/develop/api/openapi/channel_permissions/get_channel_roles_permissions.html

func (*Bot) GetChannelPermissionsOfUser

func (bot *Bot) GetChannelPermissionsOfUser(channelid, userid string) (*ChannelPermissions, error)

GetChannelPermissionsOfUser 获取子频道 channel_id 下用户 user_id 的权限

https://bot.q.qq.com/wiki/develop/api/openapi/channel_permissions/get_channel_permissions.html

func (*Bot) GetChannelSchedules

func (bot *Bot) GetChannelSchedules(id string, since uint64) (schedules []Schedule, err error)

GetChannelSchedules 获取channel_id指定的子频道中当天的日程列表

https://bot.q.qq.com/wiki/develop/api/openapi/schedule/get_schedules.html

func (*Bot) GetChannelThreads

func (bot *Bot) GetChannelThreads(id string) (threads []Thread, isfinish bool, err error)

GetChannelThreads 获取子频道下的帖子列表

https://bot.q.qq.com/wiki/develop/api/openapi/forum/get_threads_list.html

func (*Bot) GetChannelsOfGuild

func (bot *Bot) GetChannelsOfGuild(id string) (channels []Channel, err error)

GetChannelsOfGuild 获取 guild_id 指定的频道下的子频道列表

https://bot.q.qq.com/wiki/develop/api/openapi/channel/get_channels.html

func (*Bot) GetFirstSuperUser

func (bot *Bot) GetFirstSuperUser(ids ...string) string

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

找不到返回 nil

func (*Bot) GetGeneralWSSGatewayNoContext

func (bot *Bot) GetGeneralWSSGatewayNoContext() (string, error)

GetGeneralWSSGatewayNoContext 获取通用 WSS 接入点

https://bot.q.qq.com/wiki/develop/api/openapi/wss/url_get.html

func (*Bot) GetGuildByID

func (bot *Bot) GetGuildByID(id string) (*Guild, error)

GetGuildByID 获取 guild_id 指定的频道的详情

https://bot.q.qq.com/wiki/develop/api/openapi/guild/get_guild.html

func (*Bot) GetGuildMemberOf

func (bot *Bot) GetGuildMemberOf(guildid, userid string) (*Member, error)

GetGuildMemberOf 获取 guild_id 指定的频道中 user_id 对应成员的详细信息

https://bot.q.qq.com/wiki/develop/api/openapi/member/get_member.html

func (*Bot) GetGuildMembersIn

func (bot *Bot) GetGuildMembersIn(id, after string, limit uint32) (members []Member, err error)

GetGuildMembersIn 获取 guild_id 指定的频道中所有成员的详情列表,支持分页

https://bot.q.qq.com/wiki/develop/api/openapi/member/get_members.html

func (*Bot) GetGuildMessageSetting

func (bot *Bot) GetGuildMessageSetting(id string) (*MessageSetting, error)

GetGuildMessageSetting 获取机器人在频道 guild_id 内的消息频率设置

https://bot.q.qq.com/wiki/develop/api/openapi/setting/message_setting.html

func (*Bot) GetGuildRoleListIn

func (bot *Bot) GetGuildRoleListIn(id string) (*GuildRoleList, error)

GetGuildRoleListIn 获取 guild_id 指定的频道下的身份组列表

https://bot.q.qq.com/wiki/develop/api/openapi/guild/get_guild_roles.html

func (*Bot) GetMessageFromChannel

func (bot *Bot) GetMessageFromChannel(messageid, channelid string) (*Message, error)

GetMessageFromChannel 获取子频道 channel_id 下的消息 message_id 的详情

https://bot.q.qq.com/wiki/develop/api/openapi/message/get_message_of_id.html

func (*Bot) GetMessageReactionUsers

func (bot *Bot) GetMessageReactionUsers(channelid, messageid string, emoji Emoji, cookie string, limit int) (*MessageReactionUsers, error)

GetMessageReactionUsers 拉取对消息 message_id 指定表情表态的用户列表

https://bot.q.qq.com/wiki/develop/api/openapi/reaction/get_reaction_users.html

func (*Bot) GetMyGuilds

func (bot *Bot) GetMyGuilds(before, after string, limit int) (guilds []Guild, err error)

GetMyGuilds 获取当前用户(机器人)频道列表,支持分页

https://bot.q.qq.com/wiki/develop/api/openapi/user/guilds.html

func (*Bot) GetMyInfo

func (bot *Bot) GetMyInfo() (*User, error)

GetMyInfo 获取当前用户(机器人)详情

https://bot.q.qq.com/wiki/develop/api/openapi/user/me.html

func (*Bot) GetOnlineNumsInChannel

func (bot *Bot) GetOnlineNumsInChannel(id string) (int, error)

GetOnlineNumsInChannel 查询音视频/直播子频道 channel_id 的在线成员数

https://bot.q.qq.com/wiki/develop/api/openapi/channel/get_online_nums.html

func (*Bot) GetOpenAPI

func (bot *Bot) GetOpenAPI(ep, contenttype string, ptr any) error

GetOpenAPI 从 ep 获取 json 结构化数据写到 ptr, ptr 除 Slice 外必须在开头继承 CodeMessageBase

func (*Bot) GetOpenAPIWithBody

func (bot *Bot) GetOpenAPIWithBody(ep, contenttype string, ptr any, body io.Reader) error

GetOpenAPIWithBody 不规范地从 ep 获取 json 结构化数据写到 ptr, ptr 除 Slice 外必须在开头继承 CodeMessageBase

func (*Bot) GetPinMessagesOfChannel

func (bot *Bot) GetPinMessagesOfChannel(id string) (*PinsMessage, error)

GetPinMessagesOfChannel 获取子频道 channel_id 内的精华消息

https://bot.q.qq.com/wiki/develop/api/openapi/pins/get_pins_message.html

func (*Bot) GetRoleMembersOf

func (bot *Bot) GetRoleMembersOf(guildid, roleid, startindex string, limit uint32) (*RoleMembers, error)

GetRoleMembersOf 获取 guild_id 频道中指定role_id身份组下所有成员的详情列表,支持分页

https://bot.q.qq.com/wiki/develop/api/openapi/member/get_role_members.html

func (*Bot) GetScheduleInChannel

func (bot *Bot) GetScheduleInChannel(channelid string, scheduleid string) (*Schedule, error)

GetScheduleInChannel 获取日程子频道 channel_id 下 schedule_id 指定的的日程的详情

https://bot.q.qq.com/wiki/develop/api/openapi/schedule/get_schedule.html

func (*Bot) GetShardWSSGatewayNoContext

func (bot *Bot) GetShardWSSGatewayNoContext() (*ShardWSSGateway, error)

GetShardWSSGatewayNoContext 获取带分片 WSS 接入点

https://bot.q.qq.com/wiki/develop/api/openapi/wss/shard_url_get.html

func (*Bot) GetThreadInfo

func (bot *Bot) GetThreadInfo(channelid, threadid string) (*ThreadInfo, error)

GetThreadInfo 获取子频道下的帖子详情

https://bot.q.qq.com/wiki/develop/api/openapi/forum/get_thread.html

func (*Bot) GiveMessageReaction

func (bot *Bot) GiveMessageReaction(channelid, messageid string, emoji Emoji) error

GiveMessageReaction 对消息 message_id 进行表情表态

https://bot.q.qq.com/wiki/develop/api/openapi/reaction/put_message_reaction.html

func (*Bot) Init

func (bot *Bot) Init(secret, gateway string, shard [2]byte) *Bot

Init 初始化, 只需执行一次

func (*Bot) IsV2

func (bot *Bot) IsV2() bool

IsV2 判断是否运行于 V2 API 下

func (*Bot) Listen

func (bot *Bot) Listen()

Listen 监听事件

func (*Bot) OpenMicInChannel

func (bot *Bot) OpenMicInChannel(id string) error

OpenMic 机器人在 channel_id 对应的语音子频道上麦

https://bot.q.qq.com/wiki/develop/api/openapi/audio/put_mic.html

func (*Bot) PatchChannelOf

func (bot *Bot) PatchChannelOf(id string, config *ChannelPatch) (*Channel, error)

PatchChannelOf 修改 channel_id 指定的子频道的信息

https://bot.q.qq.com/wiki/develop/api/openapi/channel/patch_channel.html

func (*Bot) PatchGuildRoleOf

func (bot *Bot) PatchGuildRoleOf(guildid, roleid string, name string, color uint32, hoist int32) (*GuildRolePatch, error)

PatchGuildRoleOf 修改频道 guild_id 下 role_id 指定的身份组

https://bot.q.qq.com/wiki/develop/api/openapi/guild/patch_guild_role.html

func (*Bot) PatchOpenAPI

func (bot *Bot) PatchOpenAPI(ep, contenttype string, ptr any, body io.Reader) error

PatchOpenAPI 从 ep 得到 json 结构化数据返回值写到 ptr, ptr 除 Slice 外必须在开头继承 CodeMessageBase

func (*Bot) PatchScheduleInChannel

func (bot *Bot) PatchScheduleInChannel(channelid string, scheduleid string, schedule *Schedule) error

PatchScheduleInChannel 修改日程子频道 channel_id 下 schedule_id 指定的日程的详情

https://bot.q.qq.com/wiki/develop/api/openapi/schedule/patch_schedule.html

schedule 会被写入返回的对象

func (*Bot) PinMessageInChannel

func (bot *Bot) PinMessageInChannel(channelid, messageid string) (*PinsMessage, error)

PinMessageInChannel 添加子频道 channel_id 内的精华消息

https://bot.q.qq.com/wiki/develop/api/openapi/pins/put_pins_message.html

func (*Bot) PostAnnounceInGuild

func (bot *Bot) PostAnnounceInGuild(id string, content *Announces) error

PostAnnounceInGuild 创建频道全局公告,公告类型分为 消息类型的频道公告 和 推荐子频道类型的频道公告

https://bot.q.qq.com/wiki/develop/api/openapi/announces/post_guild_announces.html

会重写 content 为返回值

func (*Bot) PostMessageToChannel

func (bot *Bot) PostMessageToChannel(id string, content *MessagePost) (*Message, error)

PostMessageToChannel 向 channel_id 指定的子频道发送消息

https://bot.q.qq.com/wiki/develop/api/openapi/message/post_messages.html

func (*Bot) PostMessageToQQGroup

func (bot *Bot) PostMessageToQQGroup(id string, content *MessagePost) (*Message, error)

PostMessageToQQGroup 向 openid 指定的群发送消息

https://bot.q.qq.com/wiki/develop/api-231017/server-inter/message/send-receive/send.html#%E7%BE%A4%E8%81%8A

func (*Bot) PostMessageToQQUser

func (bot *Bot) PostMessageToQQUser(id string, content *MessagePost) (*Message, error)

PostMessageToQQUser 向 openid 指定的用户发送消息

https://bot.q.qq.com/wiki/develop/api-231017/server-inter/message/send-receive/send.html#%E5%8D%95%E8%81%8A

func (*Bot) PostMessageToUser

func (bot *Bot) PostMessageToUser(id string, content *MessagePost) (*Message, error)

PostMessageToUser 发送私信消息,前提是已经创建了私信会话

https://bot.q.qq.com/wiki/develop/api/openapi/dms/post_dms_messages.html

- 私信的 guild_id 在创建私信会话时以及私信消息事件中获取

func (*Bot) PostOpenAPI

func (bot *Bot) PostOpenAPI(ep, contenttype string, ptr any, body io.Reader) error

PostOpenAPI 从 ep 得到 json 结构化数据返回值写到 ptr, ptr 除 Slice 外必须在开头继承 CodeMessageBase

func (*Bot) PostThreadInChannel

func (bot *Bot) PostThreadInChannel(id string, title string, content string, format uint32) (taskid string, createtime string, err error)

PostThread 发表帖子

https://bot.q.qq.com/wiki/develop/api/openapi/forum/put_thread.html

func (*Bot) PutOpenAPI

func (bot *Bot) PutOpenAPI(ep, contenttype string, ptr any, body io.Reader) error

PutOpenAPI 向 ep 发送 PUT 并获取 json 结构化数据返回写到 ptr, ptr 除 Slice 外必须在开头继承 CodeMessageBase

func (*Bot) RemoveRoleFromMemberOfGuild

func (bot *Bot) RemoveRoleFromMemberOfGuild(guildid, userid, roleid, channelid string) error

RemoveRoleFromMemberOfGuild 将用户 user_id 从 频道 guild_id 的 role_id 身份组中移除

https://bot.q.qq.com/wiki/develop/api/openapi/guild/delete_guild_member_role.html

func (*Bot) SendPayload

func (bot *Bot) SendPayload(wp *WebsocketPayload) error

SendPayload 发送 ws 包

func (*Bot) SetAllMuteInGuild

func (bot *Bot) SetAllMuteInGuild(id string, endtimestamp string, seconds string) error

SetAllMuteInGuild 禁言全员 / 解除全员禁言

https://bot.q.qq.com/wiki/develop/api/openapi/guild/patch_guild_mute.html

func (*Bot) SetChannelPermissionsOfRole

func (bot *Bot) SetChannelPermissionsOfRole(channelid, roleid string, add, remove string) error

SetChannelPermissionsOfRole 修改子频道 channel_id 下身份组 role_id 的权限

https://bot.q.qq.com/wiki/develop/api/openapi/channel_permissions/put_channel_roles_permissions.html

func (*Bot) SetChannelPermissionsOfUser

func (bot *Bot) SetChannelPermissionsOfUser(channelid, userid string, add, remove string) error

SetChannelPermissionsOfUser 修改子频道 channel_id 下用户 user_id 的权限

https://bot.q.qq.com/wiki/develop/api/openapi/channel_permissions/put_channel_permissions.html

func (*Bot) SetUserMuteInGuild

func (bot *Bot) SetUserMuteInGuild(guildid, userid string, endtimestamp string, seconds string) error

SetUserMuteInGuild 禁言 / 解除禁言频道 guild_id 下的成员 user_id

https://bot.q.qq.com/wiki/develop/api/openapi/guild/patch_guild_mute.html

func (*Bot) SetUsersMuteInGuild

func (bot *Bot) SetUsersMuteInGuild(guildid string, endtimestamp string, seconds string, userids ...string) ([]string, error)

SetUsersMuteInGuild 批量禁言 / 解除禁言频道 guild_id 下的成员 user_id

https://bot.q.qq.com/wiki/develop/api/openapi/guild/patch_guild_mute.html

func (*Bot) UnpinMessageInChannel

func (bot *Bot) UnpinMessageInChannel(channelid, messageid string) error

UnpinMessageInChannel 子频道 channel_id 下指定 message_id 的精华消息

https://bot.q.qq.com/wiki/develop/api/openapi/pins/delete_pins_message.html

删除子频道内全部精华消息,请将 message_id 设置为 all

type Channel

type Channel struct {
	ID              string          `json:"id"`
	GuildID         string          `json:"guild_id"`
	Name            string          `json:"name"`
	Type            ChannelType     `json:"type"`
	SubType         ChannelSubType  `json:"sub_type"`
	Position        int             `json:"position"`
	ParentID        string          `json:"parent_id"`
	OwnerID         string          `json:"owner_id"`
	PrivateType     PrivateType     `json:"private_type"`
	SpeakPermission SpeakPermission `json:"speak_permission"`
	ApplicationID   string          `json:"application_id"` // ApplicationID see https://bot.q.qq.com/wiki/develop/api/openapi/channel/model.html#%E5%BA%94%E7%94%A8%E5%AD%90%E9%A2%91%E9%81%93%E7%9A%84%E5%BA%94%E7%94%A8%E7%B1%BB%E5%9E%8B
	Permissions     string          `json:"permissions"`
	OpUserID        string          `json:"op_user_id"` // https://bot.q.qq.com/wiki/develop/api/gateway/channel.html#%E5%86%85%E5%AE%B9
}

Channel 子频道对象

https://bot.q.qq.com/wiki/develop/api/openapi/channel/model.html

type ChannelPatch

type ChannelPatch struct {
	Name            string           `json:"name,omitempty"`
	Position        int              `json:"position,omitempty"`
	ParentID        *string          `json:"parent_id,omitempty"`
	PrivateType     *PrivateType     `json:"private_type,omitempty"`
	SpeakPermission *SpeakPermission `json:"speak_permission,omitempty"`
}

ChannelPatch 子频道 patch 操作所用对象

https://bot.q.qq.com/wiki/develop/api/openapi/channel/patch_channel.html

type ChannelPermissions

type ChannelPermissions struct {
	ChannelID   string `json:"channel_id"`
	UserID      string `json:"user_id"` // UserID 不与 RoleID 同时出现
	RoleID      string `json:"role_id"` // RoleID 不与 UserID 同时出现
	Permissions string `json:"permissions"`
}

ChannelPermissions 子频道权限对象

https://bot.q.qq.com/wiki/develop/api/openapi/channel_permissions/model.html

type ChannelPost

type ChannelPost struct {
	Name            string          `json:"name"`
	Type            ChannelType     `json:"type"`
	SubType         ChannelSubType  `json:"sub_type"`
	Position        int             `json:"position"`
	ParentID        string          `json:"parent_id"`
	OwnerID         string          `json:"owner_id,omitempty"`
	PrivateType     PrivateType     `json:"private_type"`
	PrivateUserIDs  []string        `json:"private_user_ids,omitempty"`
	SpeakPermission SpeakPermission `json:"speak_permission,omitempty"`
	ApplicationID   string          `json:"application_id,omitempty"`
}

ChannelPost 子频道 post 操作所用对象

https://bot.q.qq.com/wiki/develop/api/openapi/channel/post_channels.html

type ChannelSubType

type ChannelSubType int

ChannelSubType https://bot.q.qq.com/wiki/develop/api/openapi/channel/model.html#channelsubtype

const (
	ChannelSubTypeChat     ChannelSubType = iota // 闲聊
	ChannelSubTypeAnnounce                       // 公告
	ChannelSubTypeKouryaku                       // 攻略
	ChannelSubTypeGame                           // 开黑
)

type CodeMessageBase

type CodeMessageBase struct {
	C int    `json:"code"`
	M string `json:"message"`
}

CodeMessageBase 各种消息都有的 code + message 基类

type Ctx

type Ctx struct {
	Event
	State
	Message *Message
	IsToMe  bool
	IsQQ    bool
	// contains filtered or unexported fields
}

func GetBot

func GetBot(id string) *Ctx

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

func (*Ctx) AddRoleToMemberOfGuild

func (ctx *Ctx) AddRoleToMemberOfGuild(guildid, userid, roleid, channelid string) (string, error)

AddRoleToMemberOfGuild 将频道 guild_id 下的用户 user_id 添加到身份组 role_id

https://bot.q.qq.com/wiki/develop/api/openapi/guild/put_guild_member_role.html

返回 channel_id

func (*Ctx) AtMe

func (ctx *Ctx) AtMe() string

AtMe 返回 <@!bot.ready.User.ID>

func (*Ctx) Block

func (ctx *Ctx) Block()

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

func (*Ctx) Break

func (ctx *Ctx) Break()

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

func (*Ctx) CheckSession

func (ctx *Ctx) CheckSession() Rule

CheckSession 判断会话连续性

func (*Ctx) CloseMicInChannel

func (ctx *Ctx) CloseMicInChannel(id string) error

CloseMicInChannel 机器人在 channel_id 对应的语音子频道下麦

https://bot.q.qq.com/wiki/develop/api/openapi/audio/delete_mic.html

func (*Ctx) ControlAudioInChannel

func (ctx *Ctx) ControlAudioInChannel(id string, control *AudioControl) error

ControlAudioInChannel 控制子频道 channel_id 下的音频

https://bot.q.qq.com/wiki/develop/api/openapi/audio/audio_control.html

func (*Ctx) CreateChannelInGuild

func (ctx *Ctx) CreateChannelInGuild(id string, config *ChannelPost) (*Channel, error)

CreateChannelInGuild 用于在 guild_id 指定的频道下创建一个子频道

https://bot.q.qq.com/wiki/develop/api/openapi/channel/post_channels.html

func (*Ctx) CreateGuildRoleOf

func (ctx *Ctx) CreateGuildRoleOf(id string, name string, color uint32, hoist int32) (*GuildRoleCreate, error)

CreateGuildRoleOf 创建频道身份组

https://bot.q.qq.com/wiki/develop/api/openapi/guild/post_guild_role.html

参数为非必填,但至少需要传其中之一,默认为空或 0

func (*Ctx) CreatePrivateChat

func (ctx *Ctx) CreatePrivateChat(guildid, userid string) (*DMS, error)

CreatePrivateChat 机器人和在同一个频道内的成员创建私信会话

https://bot.q.qq.com/wiki/develop/api/openapi/dms/post_dms.html

func (*Ctx) CreateScheduleInChannel

func (ctx *Ctx) CreateScheduleInChannel(id string, schedule *Schedule) error

CreateScheduleInChannel 在 channel_id 指定的日程子频道下创建一个日程

https://bot.q.qq.com/wiki/develop/api/openapi/schedule/post_schedule.html

schedule 会被写入返回的对象

func (*Ctx) DeleteAnnounceInGuild

func (ctx *Ctx) DeleteAnnounceInGuild(guildid, messageid string) error

DeleteAnnounceInGuild 删除频道 guild_id 下指定 message_id 的全局公告

https://bot.q.qq.com/wiki/develop/api/openapi/announces/delete_guild_announces.html

message_id 有值时,会校验 message_id 合法性,若不校验校验 message_id,请将 message_id 设置为 all

func (*Ctx) DeleteChannelOf

func (ctx *Ctx) DeleteChannelOf(id string) error

DeleteChannelOf 删除 channel_id 指定的子频道

https://bot.q.qq.com/wiki/develop/api/openapi/channel/delete_channel.html

func (*Ctx) DeleteGuildMemberOf

func (ctx *Ctx) DeleteGuildMemberOf(guildid, userid string, addblklst bool, delhistmsgdays int) error

DeleteGuildMemberOf 删除 guild_id 指定的频道下的成员 user_id

https://bot.q.qq.com/wiki/develop/api/openapi/member/delete_member.html

- delhistmsgdays: 消息撤回时间范围仅支持固定的天数:3,7,15,30。 特殊的时间范围:-1: 撤回全部消息。默认值为0不撤回任何消息。

func (*Ctx) DeleteGuildRoleOf

func (ctx *Ctx) DeleteGuildRoleOf(guildid, roleid string) error

DeleteGuildRoleOf 删除频道 guild_id下 role_id 对应的身份组

https://bot.q.qq.com/wiki/develop/api/openapi/guild/delete_guild_role.html

func (*Ctx) DeleteMessageInChannel

func (ctx *Ctx) DeleteMessageInChannel(channelid, messageid string, hidetip bool) error

DeleteMessageInChannel 回子频道 channel_id 下的消息 message_id

https://bot.q.qq.com/wiki/develop/api/openapi/message/delete_message.html

func (*Ctx) DeleteMessageOfUser

func (ctx *Ctx) DeleteMessageOfUser(guildid, messageid string, hidetip bool) error

DeleteMessageOfUser 撤回私信频道 guild_id 中 message_id 指定的私信消息, 只能用于撤回机器人自己发送的私信

https://bot.q.qq.com/wiki/develop/api/openapi/dms/delete_dms.html

func (*Ctx) DeleteMessageReaction

func (ctx *Ctx) DeleteMessageReaction(channelid, messageid string, emoji Emoji) error

DeleteMessageReaction 删除自己对消息 message_id 的表情表态

https://bot.q.qq.com/wiki/develop/api/openapi/reaction/delete_own_message_reaction.html

func (*Ctx) DeleteScheduleInChannel

func (ctx *Ctx) DeleteScheduleInChannel(channelid string, scheduleid string) error

DeleteScheduleInChannel 删除日程子频道 channel_id 下 schedule_id 指定的日程

https://bot.q.qq.com/wiki/develop/api/openapi/schedule/delete_schedule.html

func (*Ctx) DeleteThreadInChannel

func (ctx *Ctx) DeleteThreadInChannel(channelid, threadid string) error

DeleteThreadInChannel 删除指定子频道下的某个帖子

https://bot.q.qq.com/wiki/develop/api/openapi/forum/delete_thread.html

func (*Ctx) Echo

func (ctx *Ctx) Echo(payload *WebsocketPayload)

Echo 向自身分发虚拟事件

func (*Ctx) ExtractPlainText

func (ctx *Ctx) ExtractPlainText() string

ExtractPlainText 提取消息中的纯文本

func (*Ctx) FutureEvent

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

FutureEvent ...

func (*Ctx) Get

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

Get 从 promt 获得回复

func (*Ctx) GetChannelByID

func (ctx *Ctx) GetChannelByID(id string) (*Channel, error)

GetChannelByID 用于获取 channel_id 指定的子频道的详情

https://bot.q.qq.com/wiki/develop/api/openapi/channel/get_channel.html

func (*Ctx) GetChannelPermissionsOfRole

func (ctx *Ctx) GetChannelPermissionsOfRole(channelid, roleid string) (*ChannelPermissions, error)

GetChannelPermissionsOfRole 获取子频道 channel_id 下身份组 role_id 的权限

https://bot.q.qq.com/wiki/develop/api/openapi/channel_permissions/get_channel_roles_permissions.html

func (*Ctx) GetChannelPermissionsOfUser

func (ctx *Ctx) GetChannelPermissionsOfUser(channelid, userid string) (*ChannelPermissions, error)

GetChannelPermissionsOfUser 获取子频道 channel_id 下用户 user_id 的权限

https://bot.q.qq.com/wiki/develop/api/openapi/channel_permissions/get_channel_permissions.html

func (*Ctx) GetChannelSchedules

func (ctx *Ctx) GetChannelSchedules(id string, since uint64) (schedules []Schedule, err error)

GetChannelSchedules 获取channel_id指定的子频道中当天的日程列表

https://bot.q.qq.com/wiki/develop/api/openapi/schedule/get_schedules.html

func (*Ctx) GetChannelThreads

func (ctx *Ctx) GetChannelThreads(id string) (threads []Thread, isfinish bool, err error)

GetChannelThreads 获取子频道下的帖子列表

https://bot.q.qq.com/wiki/develop/api/openapi/forum/get_threads_list.html

func (*Ctx) GetChannelsOfGuild

func (ctx *Ctx) GetChannelsOfGuild(id string) (channels []Channel, err error)

GetChannelsOfGuild 获取 guild_id 指定的频道下的子频道列表

https://bot.q.qq.com/wiki/develop/api/openapi/channel/get_channels.html

func (*Ctx) GetGuildByID

func (ctx *Ctx) GetGuildByID(id string) (*Guild, error)

GetGuildByID 获取 guild_id 指定的频道的详情

https://bot.q.qq.com/wiki/develop/api/openapi/guild/get_guild.html

func (*Ctx) GetGuildMemberOf

func (ctx *Ctx) GetGuildMemberOf(guildid, userid string) (*Member, error)

GetGuildMemberOf 获取 guild_id 指定的频道中 user_id 对应成员的详细信息

https://bot.q.qq.com/wiki/develop/api/openapi/member/get_member.html

func (*Ctx) GetGuildMembersIn

func (ctx *Ctx) GetGuildMembersIn(id, after string, limit uint32) (members []Member, err error)

GetGuildMembersIn 获取 guild_id 指定的频道中所有成员的详情列表,支持分页

https://bot.q.qq.com/wiki/develop/api/openapi/member/get_members.html

func (*Ctx) GetGuildMessageSetting

func (ctx *Ctx) GetGuildMessageSetting(id string) (*MessageSetting, error)

GetGuildMessageSetting 获取机器人在频道 guild_id 内的消息频率设置

https://bot.q.qq.com/wiki/develop/api/openapi/setting/message_setting.html

func (*Ctx) GetGuildRoleListIn

func (ctx *Ctx) GetGuildRoleListIn(id string) (*GuildRoleList, error)

GetGuildRoleListIn 获取 guild_id 指定的频道下的身份组列表

https://bot.q.qq.com/wiki/develop/api/openapi/guild/get_guild_roles.html

func (*Ctx) GetMessageFromChannel

func (ctx *Ctx) GetMessageFromChannel(messageid, channelid string) (*Message, error)

GetMessageFromChannel 获取子频道 channel_id 下的消息 message_id 的详情

https://bot.q.qq.com/wiki/develop/api/openapi/message/get_message_of_id.html

func (*Ctx) GetMessageReactionUsers

func (ctx *Ctx) GetMessageReactionUsers(channelid, messageid string, emoji Emoji, cookie string, limit int) (*MessageReactionUsers, error)

GetMessageReactionUsers 拉取对消息 message_id 指定表情表态的用户列表

https://bot.q.qq.com/wiki/develop/api/openapi/reaction/get_reaction_users.html

func (*Ctx) GetMyGuilds

func (ctx *Ctx) GetMyGuilds(before, after string, limit int) (guilds []Guild, err error)

GetMyGuilds 获取当前用户(机器人)频道列表,支持分页

https://bot.q.qq.com/wiki/develop/api/openapi/user/guilds.html

func (*Ctx) GetMyInfo

func (ctx *Ctx) GetMyInfo() (*User, error)

GetMyInfo 获取当前用户(机器人)详情

https://bot.q.qq.com/wiki/develop/api/openapi/user/me.html

func (*Ctx) GetOnlineNumsInChannel

func (ctx *Ctx) GetOnlineNumsInChannel(id string) (int, error)

GetOnlineNumsInChannel 查询音视频/直播子频道 channel_id 的在线成员数

https://bot.q.qq.com/wiki/develop/api/openapi/channel/get_online_nums.html

func (*Ctx) GetPinMessagesOfChannel

func (ctx *Ctx) GetPinMessagesOfChannel(id string) (*PinsMessage, error)

GetPinMessagesOfChannel 获取子频道 channel_id 内的精华消息

https://bot.q.qq.com/wiki/develop/api/openapi/pins/get_pins_message.html

func (*Ctx) GetReady

func (ctx *Ctx) GetReady() *EventReady

GetReady 获得 bot 基本信息

func (*Ctx) GetRoleMembersOf

func (ctx *Ctx) GetRoleMembersOf(guildid, roleid, startindex string, limit uint32) (*RoleMembers, error)

GetRoleMembersOf 获取 guild_id 频道中指定role_id身份组下所有成员的详情列表,支持分页

https://bot.q.qq.com/wiki/develop/api/openapi/member/get_role_members.html

func (*Ctx) GetScheduleInChannel

func (ctx *Ctx) GetScheduleInChannel(channelid string, scheduleid string) (*Schedule, error)

GetScheduleInChannel 获取日程子频道 channel_id 下 schedule_id 指定的的日程的详情

https://bot.q.qq.com/wiki/develop/api/openapi/schedule/get_schedule.html

func (*Ctx) GetThreadInfo

func (ctx *Ctx) GetThreadInfo(channelid, threadid string) (*ThreadInfo, error)

GetThreadInfo 获取子频道下的帖子详情

https://bot.q.qq.com/wiki/develop/api/openapi/forum/get_thread.html

func (*Ctx) GiveMessageReaction

func (ctx *Ctx) GiveMessageReaction(channelid, messageid string, emoji Emoji) error

GiveMessageReaction 对消息 message_id 进行表情表态

https://bot.q.qq.com/wiki/develop/api/openapi/reaction/put_message_reaction.html

func (*Ctx) GroupID

func (ctx *Ctx) GroupID() uint64

GroupID 唯一的发送者所属组 ID

func (*Ctx) MessageString

func (ctx *Ctx) MessageString() string

MessageString 字符串消息便于Regex

func (*Ctx) OpenMicInChannel

func (ctx *Ctx) OpenMicInChannel(id string) error

OpenMic 机器人在 channel_id 对应的语音子频道上麦

https://bot.q.qq.com/wiki/develop/api/openapi/audio/put_mic.html

func (*Ctx) Parse

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

Parse 将 Ctx.State 映射到结构体

func (*Ctx) PatchChannelOf

func (ctx *Ctx) PatchChannelOf(id string, config *ChannelPatch) (*Channel, error)

PatchChannelOf 修改 channel_id 指定的子频道的信息

https://bot.q.qq.com/wiki/develop/api/openapi/channel/patch_channel.html

func (*Ctx) PatchGuildRoleOf

func (ctx *Ctx) PatchGuildRoleOf(guildid, roleid string, name string, color uint32, hoist int32) (*GuildRolePatch, error)

PatchGuildRoleOf 修改频道 guild_id 下 role_id 指定的身份组

https://bot.q.qq.com/wiki/develop/api/openapi/guild/patch_guild_role.html

func (*Ctx) PatchScheduleInChannel

func (ctx *Ctx) PatchScheduleInChannel(channelid string, scheduleid string, schedule *Schedule) error

PatchScheduleInChannel 修改日程子频道 channel_id 下 schedule_id 指定的日程的详情

https://bot.q.qq.com/wiki/develop/api/openapi/schedule/patch_schedule.html

schedule 会被写入返回的对象

func (*Ctx) PinMessageInChannel

func (ctx *Ctx) PinMessageInChannel(channelid, messageid string) (*PinsMessage, error)

PinMessageInChannel 添加子频道 channel_id 内的精华消息

https://bot.q.qq.com/wiki/develop/api/openapi/pins/put_pins_message.html

func (*Ctx) Post

func (ctx *Ctx) Post(replytosender bool, post *MessagePost) (reply *Message, err error)

Post 发送消息到对方

func (*Ctx) PostAnnounceInGuild

func (ctx *Ctx) PostAnnounceInGuild(id string, content *Announces) error

PostAnnounceInGuild 创建频道全局公告,公告类型分为 消息类型的频道公告 和 推荐子频道类型的频道公告

https://bot.q.qq.com/wiki/develop/api/openapi/announces/post_guild_announces.html

会重写 content 为返回值

func (*Ctx) PostMessageToChannel

func (ctx *Ctx) PostMessageToChannel(id string, content *MessagePost) (*Message, error)

PostMessageToChannel 向 channel_id 指定的子频道发送消息

https://bot.q.qq.com/wiki/develop/api/openapi/message/post_messages.html

func (*Ctx) PostMessageToQQGroup

func (ctx *Ctx) PostMessageToQQGroup(id string, content *MessagePost) (*Message, error)

PostMessageToQQGroup 向 openid 指定的群发送消息

https://bot.q.qq.com/wiki/develop/api-231017/server-inter/message/send-receive/send.html#%E7%BE%A4%E8%81%8A

func (*Ctx) PostMessageToQQUser

func (ctx *Ctx) PostMessageToQQUser(id string, content *MessagePost) (*Message, error)

PostMessageToQQUser 向 openid 指定的用户发送消息

https://bot.q.qq.com/wiki/develop/api-231017/server-inter/message/send-receive/send.html#%E5%8D%95%E8%81%8A

func (*Ctx) PostMessageToUser

func (ctx *Ctx) PostMessageToUser(id string, content *MessagePost) (*Message, error)

PostMessageToUser 发送私信消息,前提是已经创建了私信会话

https://bot.q.qq.com/wiki/develop/api/openapi/dms/post_dms_messages.html

- 私信的 guild_id 在创建私信会话时以及私信消息事件中获取

func (*Ctx) PostThreadInChannel

func (ctx *Ctx) PostThreadInChannel(id string, title string, content string, format uint32) (taskid string, createtime string, err error)

PostThread 发表帖子

https://bot.q.qq.com/wiki/develop/api/openapi/forum/put_thread.html

func (*Ctx) RemoveRoleFromMemberOfGuild

func (ctx *Ctx) RemoveRoleFromMemberOfGuild(guildid, userid, roleid, channelid string) error

RemoveRoleFromMemberOfGuild 将用户 user_id 从 频道 guild_id 的 role_id 身份组中移除

https://bot.q.qq.com/wiki/develop/api/openapi/guild/delete_guild_member_role.html

func (*Ctx) Send

func (ctx *Ctx) Send(messages Messages) (m []*Message, err error)

Send 发送一批消息

func (*Ctx) SendChain

func (ctx *Ctx) SendChain(message ...MessageSegment) (m []*Message, err error)

SendChain 链式发送

func (*Ctx) SendImage

func (ctx *Ctx) SendImage(file string, replytosender bool, caption ...any) (reply *Message, err error)

SendImage 发送带图片消息到对方

func (*Ctx) SendImageBytes

func (ctx *Ctx) SendImageBytes(data []byte, replytosender bool, caption ...any) (*Message, error)

SendImageBytes 发送带图片消息到对方

func (*Ctx) SendPlainMessage

func (ctx *Ctx) SendPlainMessage(replytosender bool, printable ...any) (*Message, error)

SendPlainMessage 发送纯文本消息到对方

func (*Ctx) SetAllMuteInGuild

func (ctx *Ctx) SetAllMuteInGuild(id string, endtimestamp string, seconds string) error

SetAllMuteInGuild 禁言全员 / 解除全员禁言

https://bot.q.qq.com/wiki/develop/api/openapi/guild/patch_guild_mute.html

func (*Ctx) SetChannelPermissionsOfRole

func (ctx *Ctx) SetChannelPermissionsOfRole(channelid, roleid string, add, remove string) error

SetChannelPermissionsOfRole 修改子频道 channel_id 下身份组 role_id 的权限

https://bot.q.qq.com/wiki/develop/api/openapi/channel_permissions/put_channel_roles_permissions.html

func (*Ctx) SetChannelPermissionsOfUser

func (ctx *Ctx) SetChannelPermissionsOfUser(channelid, userid string, add, remove string) error

SetChannelPermissionsOfUser 修改子频道 channel_id 下用户 user_id 的权限

https://bot.q.qq.com/wiki/develop/api/openapi/channel_permissions/put_channel_permissions.html

func (*Ctx) SetUserMuteInGuild

func (ctx *Ctx) SetUserMuteInGuild(guildid, userid string, endtimestamp string, seconds string) error

SetUserMuteInGuild 禁言 / 解除禁言频道 guild_id 下的成员 user_id

https://bot.q.qq.com/wiki/develop/api/openapi/guild/patch_guild_mute.html

func (*Ctx) SetUsersMuteInGuild

func (ctx *Ctx) SetUsersMuteInGuild(guildid string, endtimestamp string, seconds string, userids ...string) ([]string, error)

SetUsersMuteInGuild 批量禁言 / 解除禁言频道 guild_id 下的成员 user_id

https://bot.q.qq.com/wiki/develop/api/openapi/guild/patch_guild_mute.html

func (*Ctx) UnpinMessageInChannel

func (ctx *Ctx) UnpinMessageInChannel(channelid, messageid string) error

UnpinMessageInChannel 子频道 channel_id 下指定 message_id 的精华消息

https://bot.q.qq.com/wiki/develop/api/openapi/pins/delete_pins_message.html

删除子频道内全部精华消息,请将 message_id 设置为 all

func (*Ctx) UserID

func (ctx *Ctx) UserID() uint64

GroupID 唯一的发送者 ID

type DMS

type DMS struct {
	GuildID    string `json:"guild_id"`
	ChannelID  string `json:"channel_id"`
	CreateTime string `json:"create_time"` // 创建私信会话时间戳
}

DMS 私信会话对象

https://bot.q.qq.com/wiki/develop/api/openapi/dms/model.html

type Emoji

type Emoji struct {
	ID   string `json:"id"`
	Type uint32 `json:"type"`
}

Emoji 表情对象

https://bot.q.qq.com/wiki/develop/api/openapi/emoji/model.html

func (*Emoji) String

func (e *Emoji) String() string

type Engine

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

Engine is the pre_handler, mid_handler, post_handler manager

func Register

func Register(service string, o *ctrl.Options[*Ctx]) *Engine

Register 注册插件控制器

func (*Engine) ApplySingle

func (e *Engine) ApplySingle(s *Single[int64]) *Engine

ApplySingle 应用反并发

func (*Engine) DataFolder

func (e *Engine) DataFolder() string

DataFolder 本插件数据目录, 默认 data/rbp/

func (*Engine) Delete

func (e *Engine) Delete()

Delete 移除该 Engine 注册的所有 Matchers

func (*Engine) GetLazyData

func (e *Engine) GetLazyData(filename string, isDataMustEqual bool) ([]byte, error)

下载并获取本 engine 文件夹下的懒加载数据

func (*Engine) On

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

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

func (*Engine) OnAudioFinish

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

OnAudioFinish ...

func (*Engine) OnAudioOffMic

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

OnAudioOffMic ...

func (*Engine) OnAudioOnMic

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

OnAudioOnMic ...

func (*Engine) OnAudioOrLiveChannelMemberEnter

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

OnAudioOrLiveChannelMemberEnter ...

func (*Engine) OnAudioOrLiveChannelMemberExit

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

OnAudioOrLiveChannelMemberExit ...

func (*Engine) OnAudioStart

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

OnAudioStart ...

func (*Engine) OnChannelCreate

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

OnChannelCreate ...

func (*Engine) OnChannelDelete

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

OnChannelDelete ...

func (*Engine) OnChannelUpdate

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

OnChannelUpdate ...

func (*Engine) OnForumPostCreate

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

OnForumPostCreate ...

func (*Engine) OnForumPostDelete

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

OnForumPostDelete ...

func (*Engine) OnForumPublishAuditResult

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

OnForumPublishAuditResult ...

func (*Engine) OnForumReplyCreate

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

OnForumReplyCreate ...

func (*Engine) OnForumReplyDelete

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

OnForumReplyDelete ...

func (*Engine) OnForumThreadCreate

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

OnForumThreadCreate ...

func (*Engine) OnForumThreadDelete

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

OnForumThreadDelete ...

func (*Engine) OnForumThreadUpdate

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

OnForumThreadUpdate ...

func (*Engine) OnGuildCreate

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

OnGuildCreate ...

func (*Engine) OnGuildDelete

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

OnGuildDelete ...

func (*Engine) OnGuildMemberAdd

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

OnGuildMemberAdd ...

func (*Engine) OnGuildMemberRemove

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

OnGuildMemberRemove ...

func (*Engine) OnGuildMemberUpdate

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

OnGuildMemberUpdate ...

func (*Engine) OnGuildUpdate

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

OnGuildUpdate ...

func (*Engine) OnMessage

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

OnMessage ...

func (*Engine) OnMessageAuditPass

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

OnMessageAuditPass ...

func (*Engine) OnMessageAuditReject

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

OnMessageAuditReject ...

func (*Engine) OnMessageCommand

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

OnMessageCommand ...

func (*Engine) OnMessageCommandGroup

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

OnMessageCommandGroup ...

func (*Engine) OnMessageDelete

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

OnMessageDelete ...

func (*Engine) OnMessageFullMatch

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

OnMessageFullMatch ...

func (*Engine) OnMessageFullMatchGroup

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

OnMessageFullMatchGroup ...

func (*Engine) OnMessageKeyword

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

OnMessageKeyword ...

func (*Engine) OnMessageKeywordGroup

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

OnMessageKeywordGroup ...

func (*Engine) OnMessagePrefix

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

OnMessagePrefix ...

func (*Engine) OnMessagePrefixGroup

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

OnMessagePrefixGroup ...

func (*Engine) OnMessageReactionAdd

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

OnMessageReactionAdd ...

func (*Engine) OnMessageReactionRemove

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

OnMessageReactionRemove ...

func (*Engine) OnMessageRegex

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

OnMessageRegex ...

func (*Engine) OnMessageShell

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

OnMessageShell shell命令触发器

func (*Engine) OnMessageSuffix

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

OnMessageSuffix ...

func (*Engine) OnMessageSuffixGroup

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

OnMessageSuffixGroup ...

func (*Engine) OnOpenForumPostCreate

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

OnOpenForumPostCreate ...

func (*Engine) OnOpenForumPostDelete

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

OnOpenForumPostDelete ...

func (*Engine) OnOpenForumReplyCreate

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

OnOpenForumReplyCreate ...

func (*Engine) OnOpenForumReplyDelete

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

OnOpenForumReplyDelete ...

func (*Engine) OnOpenForumThreadCreate

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

OnOpenForumThreadCreate ...

func (*Engine) OnOpenForumThreadDelete

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

OnOpenForumThreadDelete ...

func (*Engine) OnOpenForumThreadUpdate

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

OnOpenForumThreadUpdate ...

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 ...Process)

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 {
	// Type is payload.T
	Type string
	// Seq 序列号
	Seq uint32
	// Value 是 D
	Value any
	// contains filtered or unexported fields
}

Event ...

type EventReady

type EventReady struct {
	Version   int     `json:"version"`
	SessionID string  `json:"session_id"`
	User      *User   `json:"user"`
	Shard     [2]byte `json:"shard"`
}

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

type FilePost

type FilePost struct {
	Type       FileType `json:"file_type"`
	URL        string   `json:"url"`
	IsPositive bool     `json:"srv_send_msg"` // IsPositive

}

FilePost QQ 富媒体消息发送请求参数

https://bot.q.qq.com/wiki/develop/api-231017/server-inter/message/send-receive/rich-text-media.html

func (*FilePost) String

func (fp *FilePost) String() string

type FileType

type FileType int

FileType 媒体类型

func (FileType) String

func (ft FileType) String() string

type FutureEvent

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

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

func NewFutureEvent

func NewFutureEvent(Type 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 Guild

type Guild struct {
	ID          string    `json:"id"`
	Name        string    `json:"name"`
	Icon        string    `json:"icon"`
	OwnerID     string    `json:"owner_id"`
	Owner       bool      `json:"owner"`
	JoinedAt    time.Time `json:"joined_at"`
	MemberCount int       `json:"member_count"`
	MaxMembers  int       `json:"max_members"`
	Description string    `json:"description"`
	OpUserID    string    `json:"op_user_id"` // https://bot.q.qq.com/wiki/develop/api/gateway/guild.html#%E4%BA%8B%E4%BB%B6%E5%86%85%E5%AE%B9
}

Guild 频道对象

https://bot.q.qq.com/wiki/develop/api/openapi/guild/model.html

type GuildRoleChannelID

type GuildRoleChannelID struct {
	Channel struct {
		ID string `json:"id"`
	} `json:"channel"`
}

GuildRoleChannelID 频道身份组成员返回 只填充了子频道 id 字段的对象

https://bot.q.qq.com/wiki/develop/api/openapi/guild/put_guild_member_role.html#%E5%8F%82%E6%95%B0

type GuildRoleCreate

type GuildRoleCreate struct {
	RoleID string `json:"role_id"`
	Role   Role   `json:"role"`
}

GuildRoleCreate 创建频道身份组响应

https://bot.q.qq.com/wiki/develop/api/openapi/guild/post_guild_role.html#%E8%BF%94%E5%9B%9E

type GuildRoleList

type GuildRoleList struct {
	GuildID      string `json:"guild_id"`
	Roles        []Role `json:"roles"`
	RoleNumLimit string `json:"role_num_limit"`
}

GuildRoleList 频道身份组列表

https://bot.q.qq.com/wiki/develop/api/openapi/guild/get_guild_roles.html#%E8%BF%94%E5%9B%9E

type GuildRolePatch

type GuildRolePatch struct {
	GuildID string `json:"guild_id"`
	RoleID  string `json:"role_id"`
	Role    Role   `json:"role"`
}

GuildRolePatch 修改频道身份组

https://bot.q.qq.com/wiki/develop/api/openapi/guild/patch_guild_role.html#%E8%BF%94%E5%9B%9E

type HTTPRequsetConstructer

type HTTPRequsetConstructer func(ep string, contenttype string, auth, appid string, body io.Reader) (*http.Request, error)

HTTPRequsetConstructer ...

type Handler

type Handler struct {
	OnGuildCreate   func(s uint32, bot *Bot, d *Guild)
	OnGuildUpdate   func(s uint32, bot *Bot, d *Guild)
	OnGuildDelete   func(s uint32, bot *Bot, d *Guild)
	OnChannelCreate func(s uint32, bot *Bot, d *Channel)
	OnChannelUpdate func(s uint32, bot *Bot, d *Channel)
	OnChannelDelete func(s uint32, bot *Bot, d *Channel)

	OnGuildMemberAdd    func(s uint32, bot *Bot, d *Member)
	OnGuildMemberUpdate func(s uint32, bot *Bot, d *Member)
	OnGuildMemberRemove func(s uint32, bot *Bot, d *Member)

	OnMessageCreate func(s uint32, bot *Bot, d *Message)
	OnMessageDelete func(s uint32, bot *Bot, d *MessageDelete)

	OnMessageReactionAdd    func(s uint32, bot *Bot, d *MessageReaction)
	OnMessageReactionRemove func(s uint32, bot *Bot, d *MessageReaction)

	OnDirectMessageCreate func(s uint32, bot *Bot, d *Message)
	OnDirectMessageDelete func(s uint32, bot *Bot, d *MessageDelete)

	OnOpenForumThreadCreate func(s uint32, bot *Bot, d *Thread)
	OnOpenForumThreadUpdate func(s uint32, bot *Bot, d *Thread)
	OnOpenForumThreadDelete func(s uint32, bot *Bot, d *Thread)
	OnOpenForumPostCreate   func(s uint32, bot *Bot, d *Post)
	OnOpenForumPostDelete   func(s uint32, bot *Bot, d *Post)
	OnOpenForumReplyCreate  func(s uint32, bot *Bot, d *Reply)
	OnOpenForumReplyDelete  func(s uint32, bot *Bot, d *Reply)

	OnAudioOrLiveChannelMemberEnter func(s uint32, bot *Bot, d *AudioLiveChannelUsersChange)
	OnAudioOrLiveChannelMemberExit  func(s uint32, bot *Bot, d *AudioLiveChannelUsersChange)

	OnC2cMessageCreate     func(s uint32, bot *Bot, d *Message)
	OnGroupAtMessageCreate func(s uint32, bot *Bot, d *Message)
	OnGroupAddRobot        func(s uint32, bot *Bot, d *QQRobotStatus)
	OnGroupDelRobot        func(s uint32, bot *Bot, d *QQRobotStatus)
	OnGroupMsgReject       func(s uint32, bot *Bot, d *QQRobotStatus)
	OnGroupMsgReceive      func(s uint32, bot *Bot, d *QQRobotStatus)
	OnFriendAdd            func(s uint32, bot *Bot, d *QQRobotStatus)
	OnFriendDel            func(s uint32, bot *Bot, d *QQRobotStatus)
	OnC2cMsgReject         func(s uint32, bot *Bot, d *QQRobotStatus)
	OnC2cMsgReceive        func(s uint32, bot *Bot, d *QQRobotStatus)

	OnMessageAuditPass   func(s uint32, bot *Bot, d *MessageAudited)
	OnMessageAuditReject func(s uint32, bot *Bot, d *MessageAudited)

	OnForumThreadCreate       func(s uint32, bot *Bot, d *Thread)
	OnForumThreadUpdate       func(s uint32, bot *Bot, d *Thread)
	OnForumThreadDelete       func(s uint32, bot *Bot, d *Thread)
	OnForumPostCreate         func(s uint32, bot *Bot, d *Post)
	OnForumPostDelete         func(s uint32, bot *Bot, d *Post)
	OnForumReplyCreate        func(s uint32, bot *Bot, d *Reply)
	OnForumReplyDelete        func(s uint32, bot *Bot, d *Reply)
	OnForumPublishAuditResult func(s uint32, bot *Bot, d *AuditResult)

	OnAudioStart  func(s uint32, bot *Bot, d *AudioAction)
	OnAudioFinish func(s uint32, bot *Bot, d *AudioAction)
	OnAudioOnMic  func(s uint32, bot *Bot, d *AudioAction)
	OnAudioOffMic func(s uint32, bot *Bot, d *AudioAction)

	OnAtMessageCreate     func(s uint32, bot *Bot, d *Message)
	OnPublicMessageDelete func(s uint32, bot *Bot, d *MessageDelete)
}

Handler 事件订阅

https://bot.q.qq.com/wiki/develop/api/gateway/intents.html

type InlineKeyboard

type InlineKeyboard struct {
	Rows     []InlineKeyboardRow `json:"rows"`
	BotAppID int                 `json:"bot_appid"`
}

InlineKeyboard 消息按钮对象

https://bot.q.qq.com/wiki/develop/api/openapi/message/message_keyboard.html

type InlineKeyboardButton

type InlineKeyboardButton struct {
	ID         string                         `json:"id"`
	RenderData InlineKeyboardButtonRenderData `json:"render_data"`
	Action     InlineKeyboardButtonAction     `json:"action"`
}

InlineKeyboardButton https://bot.q.qq.com/wiki/develop/api/openapi/message/message_keyboard.html#button

type InlineKeyboardButtonAction

type InlineKeyboardButtonAction struct {
	Type                 InlineKeyboardButtonActionType       `json:"type"`
	Permission           InlineKeyboardButtonActionPermission `json:"permission"`
	ClickLimit           int                                  `json:"click_limit"`
	UnsupportTips        string                               `json:"unsupport_tips"`
	Data                 string                               `json:"data"`
	AtBotShowChannelList bool                                 `json:"at_bot_show_channel_list"`
}

InlineKeyboardButtonAction https://bot.q.qq.com/wiki/develop/api/openapi/message/message_keyboard.html#action

type InlineKeyboardButtonActionPermission

type InlineKeyboardButtonActionPermission struct {
	Type           InlineKeyboardButtonActionPermissionType `json:"type"`
	SpecifyRoleIDs []string                                 `json:"specify_role_ids"`
	SpecifyUserIDs []string                                 `json:"specify_user_ids"`
}

InlineKeyboardButtonActionPermission https://bot.q.qq.com/wiki/develop/api/openapi/message/message_keyboard.html#permission

type InlineKeyboardButtonActionPermissionType

type InlineKeyboardButtonActionPermissionType int

InlineKeyboardButtonActionPermissionType https://bot.q.qq.com/wiki/develop/api/openapi/message/message_keyboard.html#permissiontype

const (
	InlineKeyboardButtonActionPermissionTypeShimeiUser InlineKeyboardButtonActionPermissionType = iota
	InlineKeyboardButtonActionPermissionTypeAdmin
	InlineKeyboardButtonActionPermissionTypeAll
	InlineKeyboardButtonActionPermissionTypeShimeiRole
)

type InlineKeyboardButtonActionType

type InlineKeyboardButtonActionType int

InlineKeyboardButtonActionType https://bot.q.qq.com/wiki/develop/api/openapi/message/message_keyboard.html#actiontype

const (
	InlineKeyboardButtonActionTypeHTTP InlineKeyboardButtonActionType = iota
	InlineKeyboardButtonActionTypeCallback
	InlineKeyboardButtonActionTypeAtBot
)

type InlineKeyboardButtonRenderData

type InlineKeyboardButtonRenderData struct {
	Label        string                              `json:"label"`
	VisitedLabel string                              `json:"visited_label"`
	Style        InlineKeyboardButtonRenderDataStyle `json:"style"`
}

InlineKeyboardButtonRenderData https://bot.q.qq.com/wiki/develop/api/openapi/message/message_keyboard.html#renderdata

type InlineKeyboardButtonRenderDataStyle

type InlineKeyboardButtonRenderDataStyle int

InlineKeyboardButtonRenderDataStyle https://bot.q.qq.com/wiki/develop/api/openapi/message/message_keyboard.html#renderstyle

const (
	InlineKeyboardButtonRenderDataStyleGray InlineKeyboardButtonRenderDataStyle = iota
	InlineKeyboardButtonRenderDataStyleBlue
)

type InlineKeyboardRow

type InlineKeyboardRow struct {
	Buttons []InlineKeyboardButton `json:"buttons"`
}

InlineKeyboardRow https://bot.q.qq.com/wiki/develop/api/openapi/message/message_keyboard.html#inlinekeyboardrow

type Manager

type Manager ctrl.Manager[*Ctx]

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

	// Event 当前匹配到的事件
	Event *Event
	// Type 匹配的事件类型
	Type string
	// Rules 匹配规则
	Rules []Rule
	// Process 处理事件的函数
	Process Process
	// Engine 注册 Matcher 的 Engine,Engine可为一系列 Matcher 添加通用 Rule 和 其他钩子
	Engine *Engine
	// contains filtered or unexported fields
}

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

func On

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

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

func OnAudioFinish

func OnAudioFinish(rules ...Rule) *Matcher

OnAudioFinish ...

func OnAudioOffMic

func OnAudioOffMic(rules ...Rule) *Matcher

OnAudioOffMic ...

func OnAudioOnMic

func OnAudioOnMic(rules ...Rule) *Matcher

OnAudioOnMic ...

func OnAudioOrLiveChannelMemberEnter

func OnAudioOrLiveChannelMemberEnter(rules ...Rule) *Matcher

OnAudioOrLiveChannelMemberEnter ...

func OnAudioOrLiveChannelMemberExit

func OnAudioOrLiveChannelMemberExit(rules ...Rule) *Matcher

OnAudioOrLiveChannelMemberExit ...

func OnAudioStart

func OnAudioStart(rules ...Rule) *Matcher

OnAudioStart ...

func OnChannelCreate

func OnChannelCreate(rules ...Rule) *Matcher

OnChannelCreate ...

func OnChannelDelete

func OnChannelDelete(rules ...Rule) *Matcher

OnChannelDelete ...

func OnChannelUpdate

func OnChannelUpdate(rules ...Rule) *Matcher

OnChannelUpdate ...

func OnForumPostCreate

func OnForumPostCreate(rules ...Rule) *Matcher

OnForumPostCreate ...

func OnForumPostDelete

func OnForumPostDelete(rules ...Rule) *Matcher

OnForumPostDelete ...

func OnForumPublishAuditResult

func OnForumPublishAuditResult(rules ...Rule) *Matcher

OnForumPublishAuditResult ...

func OnForumReplyCreate

func OnForumReplyCreate(rules ...Rule) *Matcher

OnForumReplyCreate ...

func OnForumReplyDelete

func OnForumReplyDelete(rules ...Rule) *Matcher

OnForumReplyDelete ...

func OnForumThreadCreate

func OnForumThreadCreate(rules ...Rule) *Matcher

OnForumThreadCreate ...

func OnForumThreadDelete

func OnForumThreadDelete(rules ...Rule) *Matcher

OnForumThreadDelete ...

func OnForumThreadUpdate

func OnForumThreadUpdate(rules ...Rule) *Matcher

OnForumThreadUpdate ...

func OnGuildCreate

func OnGuildCreate(rules ...Rule) *Matcher

OnGuildCreate ...

func OnGuildDelete

func OnGuildDelete(rules ...Rule) *Matcher

OnGuildDelete ...

func OnGuildMemberAdd

func OnGuildMemberAdd(rules ...Rule) *Matcher

OnGuildMemberAdd ...

func OnGuildMemberRemove

func OnGuildMemberRemove(rules ...Rule) *Matcher

OnGuildMemberRemove ...

func OnGuildMemberUpdate

func OnGuildMemberUpdate(rules ...Rule) *Matcher

OnGuildMemberUpdate ...

func OnGuildUpdate

func OnGuildUpdate(rules ...Rule) *Matcher

OnGuildUpdate ...

func OnMessage

func OnMessage(rules ...Rule) *Matcher

OnMessage ...

func OnMessageAuditPass

func OnMessageAuditPass(rules ...Rule) *Matcher

OnMessageAuditPass ...

func OnMessageAuditReject

func OnMessageAuditReject(rules ...Rule) *Matcher

OnMessageAuditReject ...

func OnMessageCommand

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

OnMessageCommand ...

func OnMessageCommandGroup

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

OnMessageCommandGroup ...

func OnMessageDelete

func OnMessageDelete(rules ...Rule) *Matcher

OnMessageDelete ...

func OnMessageFullMatch

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

OnMessageFullMatch ...

func OnMessageFullMatchGroup

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

OnMessageFullMatchGroup ...

func OnMessageKeyword

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

OnMessageKeyword ...

func OnMessageKeywordGroup

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

OnMessageKeywordGroup ...

func OnMessagePrefix

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

OnMessagePrefix ...

func OnMessagePrefixGroup

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

OnMessagePrefixGroup ...

func OnMessageReactionAdd

func OnMessageReactionAdd(rules ...Rule) *Matcher

OnMessageReactionAdd ...

func OnMessageReactionRemove

func OnMessageReactionRemove(rules ...Rule) *Matcher

OnMessageReactionRemove ...

func OnMessageRegex

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

OnMessageRegex ...

func OnMessageShell

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

OnMessageShell shell命令触发器

func OnMessageSuffix

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

OnMessageSuffix ...

func OnMessageSuffixGroup

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

OnMessageSuffixGroup ...

func OnOpenForumPostCreate

func OnOpenForumPostCreate(rules ...Rule) *Matcher

OnOpenForumPostCreate ...

func OnOpenForumPostDelete

func OnOpenForumPostDelete(rules ...Rule) *Matcher

OnOpenForumPostDelete ...

func OnOpenForumReplyCreate

func OnOpenForumReplyCreate(rules ...Rule) *Matcher

OnOpenForumReplyCreate ...

func OnOpenForumReplyDelete

func OnOpenForumReplyDelete(rules ...Rule) *Matcher

OnOpenForumReplyDelete ...

func OnOpenForumThreadCreate

func OnOpenForumThreadCreate(rules ...Rule) *Matcher

OnOpenForumThreadCreate ...

func OnOpenForumThreadDelete

func OnOpenForumThreadDelete(rules ...Rule) *Matcher

OnOpenForumThreadDelete ...

func OnOpenForumThreadUpdate

func OnOpenForumThreadUpdate(rules ...Rule) *Matcher

OnOpenForumThreadUpdate ...

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) Delete

func (m *Matcher) Delete()

Delete remove the matcher from list

func (*Matcher) FutureEvent

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

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

func (*Matcher) Handle

func (m *Matcher) Handle(handler Process) *Matcher

Handle 直接处理事件

func (*Matcher) Limit

func (m *Matcher) Limit(limiterfn func(*Ctx) *rate.Limiter, postfn ...func(*Ctx)) *Matcher

Limit 限速器

postfn 当请求被拒绝时的操作

func (*Matcher) SetBlock

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

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

type Member

type Member struct {
	GuildID  string    `json:"guild_id"` // MemberWithGuildID only
	User     *User     `json:"user"`
	Nick     string    `json:"nick"`
	Roles    []string  `json:"roles"`
	JoinedAt time.Time `json:"joined_at"`
	Deaf     bool      `json:"deaf"`
	Mute     bool      `json:"mute"`
	Pending  bool      `json:"pending"`
	OpUserID string    `json:"op_user_id"` // https://bot.q.qq.com/wiki/develop/api/gateway/guild_member.html#%E5%86%85%E5%AE%B9
}

Member 成员对象 Member and MemberWithGuildID

https://bot.q.qq.com/wiki/develop/api/openapi/member/model.html

type Message

type Message struct {
	ID               string              `json:"id"`
	ChannelID        string              `json:"channel_id"`
	GuildID          string              `json:"guild_id"`
	GroupOpenID      string              `json:"group_openid"`
	FileUUID         string              `json:"file_uuid"`
	FileInfo         string              `json:"file_info"`
	Content          string              `json:"content"`
	Timestamp        *time.Time          `json:"timestamp"`
	EditedTimestamp  *time.Time          `json:"edited_timestamp"`
	FileInfoTTL      int                 `json:"ttl"`
	MentionEveryone  bool                `json:"mention_everyone"`
	Author           *User               `json:"author"`
	Attachments      []MessageAttachment `json:"attachments"`
	Embeds           []MessageEmbed      `json:"embeds"`
	Member           *Member             `json:"member"`
	Ark              *MessageArk         `json:"ark"`
	SeqInChannel     string              `json:"seq_in_channel"`
	MessageReference *MessageReference   `json:"message_reference"`
	SrcGuildID       string              `json:"src_guild_id"`
	Data             *struct {
		MessageAudit *MessageAudited `json:"message_audit,omitempty"`
	} `json:"data,omitempty"`
}

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

func (*Message) String

func (m *Message) String() string

"=> ギルド:", ctx.Message.GuildID+", 频道:", ctx.Message.ChannelID+", 用户:", ctx.Message.Author.Username+"("+ctx.Message.Author.ID+"), 内容:", ctx.Message.Content

type MessageArk

type MessageArk struct {
	TemplateID int            `json:"template_id"`
	KV         []MessageArkKV `json:"kv"`
}

MessageArk https://bot.q.qq.com/wiki/develop/api/openapi/message/model.html#messageark

type MessageArkKV

type MessageArkKV struct {
	Key   string          `json:"key"`
	Value string          `json:"value"`
	Obj   []MessageArkObj `json:"obj"`
}

MessageArkKV https://bot.q.qq.com/wiki/develop/api/openapi/message/model.html#messagearkkv

type MessageArkObj

type MessageArkObj struct {
	ObjKV []MessageArkObjKV `json:"obj_kv"`
}

MessageArkObj https://bot.q.qq.com/wiki/develop/api/openapi/message/model.html#messagearkobj

type MessageArkObjKV

type MessageArkObjKV struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

MessageArkObjKV https://bot.q.qq.com/wiki/develop/api/openapi/message/model.html#messagearkobjkv

type MessageAttachment

type MessageAttachment struct {
	ContentType string `json:"content_type,omitempty"`
	Filename    string `json:"filename,omitempty"`
	Height      int    `json:"height,omitempty"`
	ID          string `json:"id,omitempty"`
	Size        int    `json:"size,omitempty"`
	URL         string `json:"url,omitempty"`
	Width       int    `json:"width,omitempty"`
}

MessageAttachment https://bot.q.qq.com/wiki/develop/api/openapi/message/model.html#messageattachment

type MessageAudited

type MessageAudited struct {
	AuditID    string    `json:"audit_id"`
	AuditTime  time.Time `json:"audit_time"`
	ChannelID  string    `json:"channel_id"`
	CreateTime time.Time `json:"create_time"`
	GuildID    string    `json:"guild_id"`
	MessageID  string    `json:"message_id"`
}

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

type MessageDelete

type MessageDelete struct {
	Message *Message `json:"message"`
	OpUser  *User    `json:"op_user"`
}

MessageDelete https://bot.q.qq.com/wiki/develop/api/openapi/message/model.html#messagedelete

func (*MessageDelete) String

func (mdl *MessageDelete) String() string

type MessageEmbed

type MessageEmbed struct {
	Title     string                 `json:"title"`
	Prompt    string                 `json:"prompt"`
	Thumbnail *MessageEmbedThumbnail `json:"thumbnail"`
	Fields    []MessageEmbedField    `json:"fields"`
}

MessageEmbed https://bot.q.qq.com/wiki/develop/api/openapi/message/model.html#messageembed

type MessageEmbedField

type MessageEmbedField struct {
	Name string `json:"name"`
}

MessageEmbedField https://bot.q.qq.com/wiki/develop/api/openapi/message/model.html#messageembedfield

type MessageEmbedThumbnail

type MessageEmbedThumbnail struct {
	URL string `json:"url"`
}

MessageEmbedThumbnail https://bot.q.qq.com/wiki/develop/api/openapi/message/model.html#messageembedthumbnail

type MessageKeyboard

type MessageKeyboard struct {
	ID      string          `json:"id,omitempty"`
	Content *InlineKeyboard `json:"content,omitempty"` // 自定义 keyboard 内容,与 id 参数互斥,参数都传值将报错
}

MessageKeyboard https://bot.q.qq.com/wiki/develop/api/openapi/message/model.html#messagekeyboard

type MessageMarkdown

type MessageMarkdown struct {
	TemplateID       int                     `json:"template_id,omitempty"`
	CustomTemplateID string                  `json:"custom_template_id,omitempty"`
	Params           []MessageMarkdownParams `json:"params,omitempty"`
	Content          string                  `json:"content,omitempty"` // 原生 markdown 内容,与上面三个参数互斥,参数都传值将报错
}

MessageMarkdown https://bot.q.qq.com/wiki/develop/api/openapi/message/model.html#messagemarkdown

type MessageMarkdownParams

type MessageMarkdownParams struct {
	Key    string   `json:"key"`
	Values []string `json:"values"`
}

MessageMarkdownParams https://bot.q.qq.com/wiki/develop/api/openapi/message/model.html#messagemarkdownparams

type MessageMedia

type MessageMedia struct {
	FileInfo string `json:"file_info"`
}

MessageMedia used in MessagePost

type MessagePost

type MessagePost struct {
	// https://bot.q.qq.com/wiki/develop/api-231017/server-inter/message/send-receive/send.html
	Type             MessageType       `json:"msg_type"`
	Seq              int               `json:"msg_seq,omitempty"` // 回复消息的序号,与 msg_id 联合使用,避免相同消息id回复重复发送,不填默认是1。相同的 msg_id + msg_seq 重复发送会失败。
	Content          string            `json:"content,omitempty"`
	Embed            *MessageEmbed     `json:"embed,omitempty"` // https://bot.q.qq.com/wiki/develop/api/openapi/message/template/embed_message.html
	Ark              *MessageArk       `json:"ark,omitempty"`   // https://bot.q.qq.com/wiki/develop/api/openapi/message/message_template.html
	MessageReference *MessageReference `json:"message_reference,omitempty"`
	Image            string            `json:"image,omitempty"`
	ImageFile        string            `json:"-"` // ImageFile 为图片路径 file:/// or base64:// or base16384:// , 与 Image, ImageBytes 参数二选一, 优先 ImageBytes
	ImageBytes       []byte            `json:"-"` // ImageBytes 图片数据
	ReplyMessageID   string            `json:"msg_id,omitempty"`
	ReplyEventID     string            `json:"event_id,omitempty"`
	Markdown         *MessageMarkdown  `json:"markdown,omitempty"`
	KeyBoard         *MessageKeyboard  `json:"keyboard,omitempty"`
	Media            *MessageMedia     `json:"media,omitempty"`
}

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

func (*MessagePost) String

func (mp *MessagePost) String() string

type MessageReaction

type MessageReaction struct {
	UserID    string          `json:"user_id"`
	GuildID   string          `json:"guild_id"`
	ChannelID string          `json:"channel_id"`
	Target    *ReactionTarget `json:"target"`
	Emoji     *Emoji          `json:"emoji"`
}

MessageReaction https://bot.q.qq.com/wiki/develop/api/openapi/reaction/model.html#messagereaction

type MessageReactionUsers

type MessageReactionUsers struct {
	Users  []User `json:"users"`
	Cookie string `json:"cookie"`
	IsEnd  bool   `json:"is_end"`
}

MessageReactionUsers https://bot.q.qq.com/wiki/develop/api/openapi/reaction/get_reaction_users.html#%E8%BF%94%E5%9B%9E

type MessageReference

type MessageReference struct {
	MessageID             string `json:"message_id"`
	IgnoreGetMessageError bool   `json:"ignore_get_message_error"`
}

MessageReference https://bot.q.qq.com/wiki/develop/api/openapi/message/model.html#messagereference

type MessageSegment

type MessageSegment struct {
	Type MessageSegmentType
	Data string
}

MessageSegment impl the single message MessageSegment 消息数组

func Image

func Image(file string) MessageSegment

Image 普通图片

func ImageBytes

func ImageBytes(data []byte) MessageSegment

ImageBytes 普通图片

func Text

func Text(text ...interface{}) MessageSegment

Text 纯文本

func (MessageSegment) String

func (m MessageSegment) String() string

String impls the interface fmt.Stringer

type MessageSegmentType

type MessageSegmentType int
const (
	MessageSegmentTypeText MessageSegmentType = iota
	MessageSegmentTypeImage
	MessageSegmentTypeImageBytes
	MessageSegmentTypeReply
	MessageSegmentTypeAudio
	MessageSegmentTypeVideo
)

type MessageSetting

type MessageSetting struct {
	DisableCreateDm   bool     `json:"disable_create_dm"`
	DisablePushMsg    bool     `json:"disable_push_msg"`
	ChannelIDs        []string `json:"channel_ids"`
	ChannelPushMaxNum uint32   `json:"channel_push_max_num"`
}

MessageSetting 频道消息频率设置对象

https://bot.q.qq.com/wiki/develop/api/openapi/setting/model.html

type MessageType

type MessageType int
const (
	MessageTypeText MessageType = iota
	MessageTypeTextImage
	MessageTypeMarkdown
	MessageTypeArk
	MessageTypeEmbed
	MessageTypeUnk1
	MessageTypeUnk2
	MessageTypeMedia
)

func (MessageType) String

func (mt2 MessageType) String() string

type Messages

type Messages []MessageSegment

Message impl the array form of message

func ReplyWithMessage

func ReplyWithMessage(messageID string, m ...MessageSegment) Messages

ReplyWithMessage returns a reply message

type OpCode

type OpCode int

OpCode https://bot.q.qq.com/wiki/develop/api/gateway/opcode.html

const (
	OpCodeDispatch  OpCode = iota // Receive
	OpCodeHeartbeat               // Send/Receive
	OpCodeIdentify                // Send
	OpCodeEmpty1
	OpCodeEmpty2
	OpCodeEmpty3
	OpCodeResume    // Send
	OpCodeReconnect // Receive
	OpCodeEmpty4
	OpCodeInvalidSession  // Receive
	OpCodeHello           // Receive
	OpCodeHeartbeatACK    // Receive/Reply
	OpCodeHTTPCallbackACK // Reply
)

type OpCodeIdentifyMessage

type OpCodeIdentifyMessage struct {
	Token      string          `json:"token"`
	Intents    uint32          `json:"intents"`
	Shard      [2]byte         `json:"shard"`
	Properties json.RawMessage `json:"properties"`
}

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

type Option

type Option[K comparable] func(*Single[K])

Option 配置项

func WithKeyFn

func WithKeyFn[K comparable](fn func(ctx *Ctx) K) Option[K]

WithKeyFn 指定反并发的 Key

func WithPostFn

func WithPostFn[K comparable](fn func(ctx *Ctx)) Option[K]

WithPostFn 指定反并发拦截后的操作

type PinsMessage

type PinsMessage struct {
	GuildID    string   `json:"guild_id"`
	ChannelID  string   `json:"channel_id"`
	MessageIDs []string `json:"message_ids"`
}

PinsMessage 精华消息对象

https://bot.q.qq.com/wiki/develop/api/openapi/pins/model.html#pinsmessage

type Post

type Post struct {
	GuildID   string    `json:"guild_id"`
	ChannelID string    `json:"channel_id"`
	AuthorID  string    `json:"author_id"`
	PostInfo  *PostInfo `json:"post_info"`
}

Post 话题频道内对主题的评论称为帖子

https://bot.q.qq.com/wiki/develop/api/openapi/forum/model.html#post

type PostInfo

type PostInfo struct {
	ThreadID string    `json:"thread_id"`
	PostID   string    `json:"post_id"`
	Content  string    `json:"content"`
	DateTime time.Time `json:"date_time"`
}

PostInfo 帖子事件包含的帖子内容信息

https://bot.q.qq.com/wiki/develop/api/openapi/forum/model.html#postinfo

type PrivateType

type PrivateType int

PrivateType https://bot.q.qq.com/wiki/develop/api/openapi/channel/model.html#privatetype

const (
	PrivateTypePublic         PrivateType = iota // 公开频道
	PrivateTypeOnlyAdmin                         // 群主管理员可见
	PrivateTypeAdminAndShimei                    // 群主管理员+指定成员,可使用 修改子频道权限接口 指定成员
)

type Process

type Process func(ctx *Ctx)

Process 事件处理函数

type QQRobotStatus

type QQRobotStatus struct {
	OpenID         string `json:"openid"`
	GroupOpenID    string `json:"group_openid"`
	OpMemberOpenID string `json:"op_member_openid"`
	Timestamp      int    `json:"timestamp"`
}

QQRobotStatus https://bot.q.qq.com/wiki/develop/api-231017/server-inter/group.html#%E4%BA%8B%E4%BB%B6

type ReactionTarget

type ReactionTarget struct {
	ID   string             `json:"id"`
	Type ReactionTargetType `json:"type"` // 实际是 string 而非 int
}

ReactionTarget https://bot.q.qq.com/wiki/develop/api/openapi/reaction/model.html#reactiontarget

type RecommendChannel

type RecommendChannel struct {
	ChannelID string `json:"channel_id"`
	Introduce string `json:"introduce"`
}

RecommendChannel 推荐子频道对象

https://bot.q.qq.com/wiki/develop/api/openapi/announces/model.html#recommendchannel

type Reply

type Reply struct {
	GuildID   string     `json:"guild_id"`
	ChannelID string     `json:"channel_id"`
	AuthorID  string     `json:"author_id"`
	ReplyInfo *ReplyInfo `json:"reply_info"`
}

Reply 话题频道对帖子回复或删除时生产该事件中包含该对象

https://bot.q.qq.com/wiki/develop/api/openapi/forum/model.html#reply

type ReplyInfo

type ReplyInfo struct {
	ThreadID string    `json:"thread_id"`
	PostID   string    `json:"post_id"`
	ReplyID  string    `json:"reply_id"`
	Content  string    `json:"content"`
	DateTime time.Time `json:"date_time"`
}

ReplyInfo 回复事件包含的回复内容信息

https://bot.q.qq.com/wiki/develop/api/openapi/forum/model.html#replyinfo

type Role

type Role struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Color       uint32 `json:"color"`
	Hoist       uint32 `json:"hoist"`
	Number      uint32 `json:"number"`
	MemberLimit uint32 `json:"member_limit"`
}

Role 频道身份组对象

https://bot.q.qq.com/wiki/develop/api/openapi/guild/role_model.html

type RoleMembers

type RoleMembers struct {
	Data []Member `json:"data"`
	Next string   `json:"next"`
}

RoleMembers 频道身份组成员列表

https://bot.q.qq.com/wiki/develop/api/openapi/member/get_role_members.html#%E8%BF%94%E5%9B%9E

type Rule

type Rule func(ctx *Ctx) bool

Rule filter the event

func CheckChannel

func CheckChannel(channelID ...string) Rule

CheckChannel only triggered in specific channel

func CheckGuild

func CheckGuild(guildID ...string) Rule

CheckGuild only triggered in specific guild

func CheckUser

func CheckUser(userID ...string) Rule

CheckUser only triggered by specific person

func CommandGroupRule

func CommandGroupRule(commands ...string) Rule

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

this rule only supports Message

func CommandRule

func CommandRule(command string) Rule

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

this rule only supports Message

func FullMatchGroupRule

func FullMatchGroupRule(src ...string) Rule

FullMatchGroupRule check if src has the same copy of the message

func FullMatchRule

func FullMatchRule(src string) Rule

FullMatchRule check if src has the same copy of the message

func KeywordGroupRule

func KeywordGroupRule(src ...string) Rule

KeywordGroupRule check if the message has a keyword or keywords

func KeywordRule

func KeywordRule(src string) Rule

func MustProvidePhoto

func MustProvidePhoto(onmessage string, needphohint, failhint string) Rule

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

func PrefixGroupRule

func PrefixGroupRule(prefixes ...string) Rule

PrefixGroupRule check if the text message has the prefix and trim the prefix

检查消息前缀

func PrefixRule

func PrefixRule(prefix string) Rule

PrefixRule check if the text 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 string) Rule

ReplyRule check if the message is replying some message

this rule only supports Message

func ShellRule

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

ShellRule 定义shell-like规则

this rule only supports Message

func SuffixGroupRule

func SuffixGroupRule(suffixes ...string) Rule

SuffixGroupRule check if the text message has the suffix and trim the suffix

检查消息后缀

func SuffixRule

func SuffixRule(suffix string) Rule

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

检查消息后缀

type Schedule

type Schedule struct {
	ID             string  `json:"id,omitempty"`
	Name           string  `json:"name,omitempty"`
	Description    string  `json:"description,omitempty"`
	StartTimestamp string  `json:"start_timestamp,omitempty"`
	EndTimestamp   string  `json:"end_timestamp,omitempty"`
	Creator        *Member `json:"creator,omitempty"`
	JumpChannelID  string  `json:"jump_channel_id,omitempty"`
	RemindType     string  `json:"remind_type,omitempty"` // https://bot.q.qq.com/wiki/develop/api/openapi/schedule/model.html#remindtype
}

Schedule 日程对象

https://bot.q.qq.com/wiki/develop/api/openapi/schedule/model.html

type ShardWSSGateway

type ShardWSSGateway struct {
	URL               string `json:"url"`
	Shards            int    `json:"shards"`
	SessionStartLimit struct {
		Total          int `json:"total"`
		Remaining      int `json:"remaining"`
		ResetAfter     int `json:"reset_after"`
		MaxConcurrency int `json:"max_concurrency"`
	} `json:"session_start_limit"`
}

ShardWSSGateway 带分片 WSS 接入点响应数据

https://bot.q.qq.com/wiki/develop/api/openapi/wss/shard_url_get.html#%E8%BF%94%E5%9B%9E

type Single

type Single[K comparable] struct {
	// contains filtered or unexported fields
}

Single 反并发

func NewSingle

func NewSingle[K comparable](op ...Option[K]) *Single[K]

NewSingle 创建反并发中间件

func (*Single[K]) Apply

func (s *Single[K]) Apply(engine *Engine)

Apply 为指定 Engine 添加反并发功能

type State

type State map[string]any

State store the context of a matcher.

type Thread

type Thread struct {
	GuildID    string      `json:"guild_id"`
	ChannelID  string      `json:"channel_id"`
	AuthorID   string      `json:"author_id"`
	ThreadInfo *ThreadInfo `json:"thread_info"`
}

Thread 话题频道内发表的主帖称为主题

https://bot.q.qq.com/wiki/develop/api/openapi/forum/model.html#thread

type ThreadInfo

type ThreadInfo struct {
	ThreadID string    `json:"thread_id"`
	Title    string    `json:"title"`
	Content  string    `json:"content"`
	DateTime time.Time `json:"date_time"`
}

ThreadInfo 帖子事件包含的主帖内容相关信息

https://bot.q.qq.com/wiki/develop/api/openapi/forum/model.html#threadinfo

type User

type User struct {
	ID               string `json:"id"`
	Username         string `json:"username"`
	Avatar           string `json:"avatar"`
	Bot              bool   `json:"bot"`
	UnionOpenid      string `json:"union_openid"`
	UnionUserAccount string `json:"union_user_account"`
	UserOpenID       string `json:"user_openid"`
	MemberOpenID     string `json:"member_openid"`
}

User 用户对象

https://bot.q.qq.com/wiki/develop/api/openapi/user/model.html

func (*User) At

func (u *User) At() string

At 返回 <@!u.ID>

type WebsocketPayload

type WebsocketPayload struct {
	Op OpCode          `json:"op"`
	D  json.RawMessage `json:"d,omitempty"`
	S  uint32          `json:"s,omitempty"`
	T  string          `json:"t,omitempty"`
}

WebsocketPayload payload 指的是在 websocket 连接上传输的数据,网关的上下行消息采用的都是同一个结构

https://bot.q.qq.com/wiki/develop/api/gateway/reference.html

func (*WebsocketPayload) GetEventReady

func (wp *WebsocketPayload) GetEventReady() (er EventReady, seq uint32, err error)

GetEventReady OpCodeDispatch READY

func (*WebsocketPayload) GetHeartbeatInterval

func (wp *WebsocketPayload) GetHeartbeatInterval() (uint32, error)

GetHeartbeatInterval OpCodeHello 获得心跳周期 单位毫秒

func (*WebsocketPayload) Reset

func (wp *WebsocketPayload) Reset()

Reset 恢复到 0 值

func (*WebsocketPayload) WrapData

func (wp *WebsocketPayload) WrapData(v any) (err error)

WrapData 将结构体序列化到 wp.D

Directories

Path Synopsis
codegen

Jump to

Keyboard shortcuts

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