mirror of
https://github.com/fumiama/NanoBot.git
synced 2026-06-13 15:00:41 +08:00
精简 Init 参数
This commit is contained in:
15
bot.go
15
bot.go
@@ -25,6 +25,8 @@ type Bot struct {
|
|||||||
SuperUsers []string // SuperUsers 超级用户
|
SuperUsers []string // SuperUsers 超级用户
|
||||||
Timeout time.Duration // Timeout is API 调用超时
|
Timeout time.Duration // Timeout is API 调用超时
|
||||||
Handler *Handler // Handler 注册对各种事件的处理
|
Handler *Handler // Handler 注册对各种事件的处理
|
||||||
|
Intents uint32 // Intents 欲接收的事件
|
||||||
|
Properties json.RawMessage // Properties 一些环境变量, 目前没用
|
||||||
|
|
||||||
gateway string // gateway 获得的网关
|
gateway string // gateway 获得的网关
|
||||||
shard [2]byte // shard 分片
|
shard [2]byte // shard 分片
|
||||||
@@ -32,18 +34,15 @@ type Bot struct {
|
|||||||
handlers map[string]GeneralHandleType // handlers 方便调用的 handler
|
handlers map[string]GeneralHandleType // handlers 方便调用的 handler
|
||||||
mu sync.Mutex // 写锁
|
mu sync.Mutex // 写锁
|
||||||
conn *websocket.Conn
|
conn *websocket.Conn
|
||||||
heartbeat uint32 // heartbeat 心跳周期, 单位毫秒
|
|
||||||
intents uint32
|
|
||||||
properties json.RawMessage
|
|
||||||
ready EventReady
|
ready EventReady
|
||||||
|
heartbeat uint32 // heartbeat 心跳周期, 单位毫秒
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init 初始化, 只需执行一次
|
// Init 初始化, 只需执行一次
|
||||||
func (b *Bot) Init(gateway string, shard [2]byte, intents uint32, properties json.RawMessage) *Bot {
|
func (b *Bot) Init(gateway string, shard [2]byte) *Bot {
|
||||||
b.gateway = gateway
|
b.gateway = gateway
|
||||||
b.shard = shard
|
b.shard = shard
|
||||||
b.intents = intents
|
|
||||||
b.properties = properties
|
|
||||||
if b.Handler != nil {
|
if b.Handler != nil {
|
||||||
h := reflect.ValueOf(b.Handler).Elem()
|
h := reflect.ValueOf(b.Handler).Elem()
|
||||||
t := h.Type()
|
t := h.Type()
|
||||||
@@ -120,9 +119,9 @@ func (bot *Bot) Connect() {
|
|||||||
payload.Op = OpCodeIdentify
|
payload.Op = OpCodeIdentify
|
||||||
err = payload.WrapData(&OpCodeIdentifyMessage{
|
err = payload.WrapData(&OpCodeIdentifyMessage{
|
||||||
Token: bot.Authorization(),
|
Token: bot.Authorization(),
|
||||||
Intents: bot.intents,
|
Intents: bot.Intents,
|
||||||
Shard: bot.shard,
|
Shard: bot.shard,
|
||||||
Properties: bot.properties,
|
Properties: bot.Properties,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnln("[bot] 包装 Identify 时出现错误:", err)
|
log.Warnln("[bot] 包装 Identify 时出现错误:", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user