From dd054c168ceaedf4ca7f1a40731374423aa66b7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Sun, 15 Oct 2023 01:13:02 +0900 Subject: [PATCH] =?UTF-8?q?=E7=B2=BE=E7=AE=80=20Init=20=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot.go | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/bot.go b/bot.go index d1c8afd..e12cd7e 100644 --- a/bot.go +++ b/bot.go @@ -19,31 +19,30 @@ var clients = syncx.Map[string, *Bot]{} // Bot 一个机器人实例的配置 type Bot struct { - AppID string // AppID is BotAppID(开发者ID) - Token string // Token is 机器人令牌 - Secret string // Secret is 机器人密钥 - SuperUsers []string // SuperUsers 超级用户 - Timeout time.Duration // Timeout is API 调用超时 - Handler *Handler // Handler 注册对各种事件的处理 + AppID string // AppID is BotAppID(开发者ID) + Token string // Token is 机器人令牌 + Secret string // Secret is 机器人密钥 + SuperUsers []string // SuperUsers 超级用户 + Timeout time.Duration // Timeout is API 调用超时 + Handler *Handler // Handler 注册对各种事件的处理 + Intents uint32 // Intents 欲接收的事件 + Properties json.RawMessage // Properties 一些环境变量, 目前没用 - gateway string // gateway 获得的网关 - shard [2]byte // shard 分片 - seq uint32 - handlers map[string]GeneralHandleType // handlers 方便调用的 handler - mu sync.Mutex // 写锁 - conn *websocket.Conn - heartbeat uint32 // heartbeat 心跳周期, 单位毫秒 - intents uint32 - properties json.RawMessage - ready EventReady + gateway string // gateway 获得的网关 + shard [2]byte // shard 分片 + seq uint32 + handlers map[string]GeneralHandleType // handlers 方便调用的 handler + mu sync.Mutex // 写锁 + conn *websocket.Conn + + ready EventReady + heartbeat uint32 // heartbeat 心跳周期, 单位毫秒 } // 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.shard = shard - b.intents = intents - b.properties = properties if b.Handler != nil { h := reflect.ValueOf(b.Handler).Elem() t := h.Type() @@ -120,9 +119,9 @@ func (bot *Bot) Connect() { payload.Op = OpCodeIdentify err = payload.WrapData(&OpCodeIdentifyMessage{ Token: bot.Authorization(), - Intents: bot.intents, + Intents: bot.Intents, Shard: bot.shard, - Properties: bot.properties, + Properties: bot.Properties, }) if err != nil { log.Warnln("[bot] 包装 Identify 时出现错误:", err)