- Upgrade Go version to 1.24.0 and update toolchain. - Update various dependencies in go.mod and go.sum, including: - Upgrade `fasthttp/websocket` to v1.5.12 - Upgrade `fsnotify/fsnotify` to v1.9.0 - Upgrade `valyala/fasthttp` to v1.58.0 - Add new dependencies for `bytedance/sonic` and `google/uuid`. - Refactor bot configuration in config.toml to support multiple bot protocols, including "milky" and "onebot11". - Modify internal configuration structures to accommodate new bot settings. - Enhance event dispatcher with metrics tracking and asynchronous processing capabilities. - Implement WebSocket connection management with heartbeat and reconnection logic. - Update server handling for bot management and event publishing.
37 lines
764 B
Go
37 lines
764 B
Go
package onebot11
|
|
|
|
import (
|
|
"cellbot/internal/engine"
|
|
"cellbot/internal/protocol"
|
|
"cellbot/pkg/net"
|
|
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
// Bot OneBot11机器人实例
|
|
type Bot struct {
|
|
*protocol.BaseBotInstance
|
|
adapter *Adapter
|
|
}
|
|
|
|
// NewBot 创建OneBot11机器人实例
|
|
func NewBot(id string, config *Config, logger *zap.Logger, wsManager *net.WebSocketManager, eventBus *engine.EventBus) *Bot {
|
|
adapter := NewAdapter(config, logger, wsManager, eventBus)
|
|
baseBot := protocol.NewBaseBotInstance(id, adapter, logger)
|
|
|
|
return &Bot{
|
|
BaseBotInstance: baseBot,
|
|
adapter: adapter,
|
|
}
|
|
}
|
|
|
|
// GetAdapter 获取适配器
|
|
func (b *Bot) GetAdapter() *Adapter {
|
|
return b.adapter
|
|
}
|
|
|
|
// GetConfig 获取配置
|
|
func (b *Bot) GetConfig() *Config {
|
|
return b.adapter.config
|
|
}
|