mirror of
https://github.com/fumiama/NanoBot.git
synced 2026-06-11 05:30:24 +08:00
精简 Init 参数
This commit is contained in:
41
bot.go
41
bot.go
@@ -19,31 +19,30 @@ var clients = syncx.Map[string, *Bot]{}
|
|||||||
|
|
||||||
// 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 机器人密钥
|
||||||
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 分片
|
||||||
seq uint32
|
seq uint32
|
||||||
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
|
ready EventReady
|
||||||
properties json.RawMessage
|
heartbeat uint32 // heartbeat 心跳周期, 单位毫秒
|
||||||
ready EventReady
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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