mirror of
https://github.com/fumiama/NanoBot.git
synced 2026-06-11 05:30:24 +08:00
add part of handler
This commit is contained in:
17
bot.go
17
bot.go
@@ -4,10 +4,19 @@ import "time"
|
|||||||
|
|
||||||
// Bot 一个机器人实例的配置
|
// Bot 一个机器人实例的配置
|
||||||
type Bot struct {
|
type Bot struct {
|
||||||
AppID string // AppID is BotAppID(开发者ID)
|
AppID string // AppID is BotAppID(开发者ID)
|
||||||
Token string // Token is 机器人令牌
|
Token string // Token is 机器人令牌
|
||||||
Secret string // Secret is 机器人密钥
|
Secret string // Secret is 机器人密钥
|
||||||
Timeout time.Duration // Timeout is API 调用超时
|
SuperUsers []string // SuperUsers 超级用户
|
||||||
|
Timeout time.Duration // Timeout is API 调用超时
|
||||||
|
Handler *Handler // Handler 注册对各种事件的处理
|
||||||
|
|
||||||
|
handlers map[string]GeneralHandleType // handlers 方便调用的 handler
|
||||||
|
}
|
||||||
|
|
||||||
|
// Init 初始化, 只需执行一次
|
||||||
|
func (b *Bot) Init() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Authorization 返回 Authorization Header value
|
// Authorization 返回 Authorization Header value
|
||||||
|
|||||||
33
define.go
33
define.go
@@ -1,5 +1,7 @@
|
|||||||
package nano
|
package nano
|
||||||
|
|
||||||
|
import "encoding/json"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// StandardAPI 正式环境接口域名
|
// StandardAPI 正式环境接口域名
|
||||||
StandardAPI = `https://api.sgroup.qq.com`
|
StandardAPI = `https://api.sgroup.qq.com`
|
||||||
@@ -8,7 +10,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
OpenAPI = StandardAPI // OpenAPI 实际使用的 API, 可自行配置
|
OpenAPI = StandardAPI // OpenAPI 实际使用的 API, 默认 StandardAPI, 可自行赋值配置
|
||||||
)
|
)
|
||||||
|
|
||||||
// CodeMessageBase 各种消息都有的 code + message 基类
|
// CodeMessageBase 各种消息都有的 code + message 基类
|
||||||
@@ -16,3 +18,32 @@ type CodeMessageBase struct {
|
|||||||
C int `json:"code"`
|
C int `json:"code"`
|
||||||
M string `json:"message"`
|
M string `json:"message"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OpCode https://bot.q.qq.com/wiki/develop/api/gateway/opcode.html
|
||||||
|
type OpCode int
|
||||||
|
|
||||||
|
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
|
||||||
|
)
|
||||||
|
|
||||||
|
// WebsocketPayload payload 指的是在 websocket 连接上传输的数据,网关的上下行消息采用的都是同一个结构
|
||||||
|
//
|
||||||
|
// https://bot.q.qq.com/wiki/develop/api/gateway/reference.html
|
||||||
|
type WebsocketPayload struct {
|
||||||
|
Op OpCode `json:"op"`
|
||||||
|
D json.RawMessage `json:"d"`
|
||||||
|
S int `json:"s"`
|
||||||
|
T string `json:"t"`
|
||||||
|
}
|
||||||
|
|||||||
31
handler.go
Normal file
31
handler.go
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package nano
|
||||||
|
|
||||||
|
import "unsafe"
|
||||||
|
|
||||||
|
// GeneralHandleType 作为通用的 handler 函数调用约定使用
|
||||||
|
type GeneralHandleType func(int, *Bot, unsafe.Pointer)
|
||||||
|
|
||||||
|
// Handler 事件订阅
|
||||||
|
//
|
||||||
|
// https://bot.q.qq.com/wiki/develop/api/gateway/intents.html
|
||||||
|
type Handler struct {
|
||||||
|
// GUILDS (1 << 0)
|
||||||
|
|
||||||
|
OnGuildCreate func(s int, bot *Bot, d *Guild)
|
||||||
|
OnGuildUpdate func(s int, bot *Bot, d *Guild)
|
||||||
|
OnGuildDelete func(s int, bot *Bot, d *Guild)
|
||||||
|
OnChannelCreate func(s int, bot *Bot, d *Channel)
|
||||||
|
OnChannelUpdate func(s int, bot *Bot, d *Channel)
|
||||||
|
OnChannelDelete func(s int, bot *Bot, d *Channel)
|
||||||
|
// GUILD_MEMBERS (1 << 1)
|
||||||
|
|
||||||
|
OnGuildMemberAdd func(s int, bot *Bot, d *Member)
|
||||||
|
OnGuildMemberUpdate func(s int, bot *Bot, d *Member)
|
||||||
|
OnGuildMemberRemove func(s int, bot *Bot, d *Member)
|
||||||
|
// GUILD_MESSAGES (1 << 9) // 消息事件,仅 *私域* 机器人能够设置此 intents。
|
||||||
|
|
||||||
|
OnMessageCreate func(s int, bot *Bot, d *Message)
|
||||||
|
OnMessageDelete func(s int, bot *Bot, d *Message)
|
||||||
|
// GUILD_MESSAGE_REACTIONS (1 << 10)
|
||||||
|
|
||||||
|
}
|
||||||
@@ -58,6 +58,7 @@ type Channel struct {
|
|||||||
SpeakPermission SpeakPermission `json:"speak_permission"`
|
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
|
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"`
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetChannelsOfGuild 获取 guild_id 指定的频道下的子频道列表
|
// GetChannelsOfGuild 获取 guild_id 指定的频道下的子频道列表
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ type Guild struct {
|
|||||||
MemberCount int `json:"member_count"`
|
MemberCount int `json:"member_count"`
|
||||||
MaxMembers int `json:"max_members"`
|
MaxMembers int `json:"max_members"`
|
||||||
Description string `json:"description"`
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetGuildByID 获取 guild_id 指定的频道的详情
|
// GetGuildByID 获取 guild_id 指定的频道的详情
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ type Member struct {
|
|||||||
Deaf bool `json:"deaf"`
|
Deaf bool `json:"deaf"`
|
||||||
Mute bool `json:"mute"`
|
Mute bool `json:"mute"`
|
||||||
Pending bool `json:"pending"`
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetGuildMembersIn 获取 guild_id 指定的频道中所有成员的详情列表,支持分页
|
// GetGuildMembersIn 获取 guild_id 指定的频道中所有成员的详情列表,支持分页
|
||||||
|
|||||||
Reference in New Issue
Block a user