refactor: modernize codebase for Go 1.26 and fix adapter issues
- Upgrade Go version from 1.24 to 1.26.1 with updated dependencies
- Replace interface{} with any type throughout codebase
- Add message deduplication in OneBot11 adapter to prevent duplicate event processing
- URL-encode access token in WebSocket connections to handle special characters
- Remove duplicate bot startup hooks in DI providers (now handled by botManager.StartAll)
- Use slices.Clone and errgroup.Go patterns for cleaner concurrent code
- Apply omitzero JSON tags for optional fields (Go 1.24+ feature)
This commit is contained in:
@@ -35,7 +35,7 @@ type Event interface {
|
||||
// GetSelfID 获取机器人自身ID
|
||||
GetSelfID() string
|
||||
// GetData 获取事件数据
|
||||
GetData() map[string]interface{}
|
||||
GetData() map[string]any
|
||||
// Reply 在消息发生的群/私聊进行回复
|
||||
Reply(ctx context.Context, botManager *BotManager, logger *zap.Logger, message MessageChain) error
|
||||
// ReplyText 在消息发生的群/私聊进行文本回复(便捷方法)
|
||||
@@ -44,12 +44,12 @@ type Event interface {
|
||||
|
||||
// BaseEvent 基础事件结构
|
||||
type BaseEvent struct {
|
||||
Type EventType `json:"type"`
|
||||
DetailType string `json:"detail_type"`
|
||||
SubType string `json:"sub_type,omitempty"`
|
||||
Timestamp int64 `json:"timestamp"`
|
||||
SelfID string `json:"self_id"`
|
||||
Data map[string]interface{} `json:"data"`
|
||||
Type EventType `json:"type"`
|
||||
DetailType string `json:"detail_type"`
|
||||
SubType string `json:"sub_type,omitzero"`
|
||||
Timestamp int64 `json:"timestamp"`
|
||||
SelfID string `json:"self_id"`
|
||||
Data map[string]any `json:"data"`
|
||||
}
|
||||
|
||||
// GetType 获取事件类型
|
||||
@@ -78,7 +78,7 @@ func (e *BaseEvent) GetSelfID() string {
|
||||
}
|
||||
|
||||
// GetData 获取事件数据
|
||||
func (e *BaseEvent) GetData() map[string]interface{} {
|
||||
func (e *BaseEvent) GetData() map[string]any {
|
||||
return e.Data
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ func (e *BaseEvent) Reply(ctx context.Context, botManager *BotManager, logger *z
|
||||
if e.GetDetailType() == "private" {
|
||||
action = &BaseAction{
|
||||
Type: ActionTypeSendPrivateMessage,
|
||||
Params: map[string]interface{}{
|
||||
Params: map[string]any{
|
||||
"user_id": userID,
|
||||
"message": message,
|
||||
},
|
||||
@@ -114,7 +114,7 @@ func (e *BaseEvent) Reply(ctx context.Context, botManager *BotManager, logger *z
|
||||
// 群聊或其他有 group_id 的事件
|
||||
action = &BaseAction{
|
||||
Type: ActionTypeSendGroupMessage,
|
||||
Params: map[string]interface{}{
|
||||
Params: map[string]any{
|
||||
"group_id": groupID,
|
||||
"message": message,
|
||||
},
|
||||
@@ -151,15 +151,15 @@ type MessageEvent struct {
|
||||
BaseEvent
|
||||
MessageID string `json:"message_id"`
|
||||
Message string `json:"message"`
|
||||
AltText string `json:"alt_text,omitempty"`
|
||||
AltText string `json:"alt_text,omitzero"`
|
||||
}
|
||||
|
||||
// NoticeEvent 通知事件
|
||||
type NoticeEvent struct {
|
||||
BaseEvent
|
||||
GroupID string `json:"group_id,omitempty"`
|
||||
UserID string `json:"user_id,omitempty"`
|
||||
Operator string `json:"operator,omitempty"`
|
||||
GroupID string `json:"group_id,omitzero"`
|
||||
UserID string `json:"user_id,omitzero"`
|
||||
Operator string `json:"operator,omitzero"`
|
||||
}
|
||||
|
||||
// RequestEvent 请求事件
|
||||
|
||||
Reference in New Issue
Block a user