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:
@@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
// ConvertMessageChainToOB11 将通用消息链转换为 OneBot11 格式
|
||||
func ConvertMessageChainToOB11(chain protocol.MessageChain) interface{} {
|
||||
func ConvertMessageChainToOB11(chain protocol.MessageChain) any {
|
||||
if len(chain) == 0 {
|
||||
return ""
|
||||
}
|
||||
@@ -38,7 +38,7 @@ func convertSegmentToOB11(seg protocol.MessageSegment) *MessageSegment {
|
||||
// 文本消息段
|
||||
return &MessageSegment{
|
||||
Type: SegmentTypeText,
|
||||
Data: map[string]interface{}{
|
||||
Data: map[string]any{
|
||||
"text": seg.Data["text"],
|
||||
},
|
||||
}
|
||||
@@ -48,7 +48,7 @@ func convertSegmentToOB11(seg protocol.MessageSegment) *MessageSegment {
|
||||
userID := seg.Data["user_id"]
|
||||
return &MessageSegment{
|
||||
Type: SegmentTypeAt,
|
||||
Data: map[string]interface{}{
|
||||
Data: map[string]any{
|
||||
"qq": userID,
|
||||
},
|
||||
}
|
||||
@@ -61,7 +61,7 @@ func convertSegmentToOB11(seg protocol.MessageSegment) *MessageSegment {
|
||||
}
|
||||
return &MessageSegment{
|
||||
Type: SegmentTypeAt,
|
||||
Data: map[string]interface{}{
|
||||
Data: map[string]any{
|
||||
"qq": userID,
|
||||
},
|
||||
}
|
||||
@@ -75,7 +75,7 @@ func convertSegmentToOB11(seg protocol.MessageSegment) *MessageSegment {
|
||||
}
|
||||
return &MessageSegment{
|
||||
Type: SegmentTypeImage,
|
||||
Data: map[string]interface{}{
|
||||
Data: map[string]any{
|
||||
"file": fileID,
|
||||
},
|
||||
}
|
||||
@@ -88,7 +88,7 @@ func convertSegmentToOB11(seg protocol.MessageSegment) *MessageSegment {
|
||||
}
|
||||
return &MessageSegment{
|
||||
Type: SegmentTypeRecord,
|
||||
Data: map[string]interface{}{
|
||||
Data: map[string]any{
|
||||
"file": fileID,
|
||||
},
|
||||
}
|
||||
@@ -101,7 +101,7 @@ func convertSegmentToOB11(seg protocol.MessageSegment) *MessageSegment {
|
||||
}
|
||||
return &MessageSegment{
|
||||
Type: SegmentTypeRecord,
|
||||
Data: map[string]interface{}{
|
||||
Data: map[string]any{
|
||||
"file": fileID,
|
||||
},
|
||||
}
|
||||
@@ -114,7 +114,7 @@ func convertSegmentToOB11(seg protocol.MessageSegment) *MessageSegment {
|
||||
}
|
||||
return &MessageSegment{
|
||||
Type: SegmentTypeVideo,
|
||||
Data: map[string]interface{}{
|
||||
Data: map[string]any{
|
||||
"file": fileID,
|
||||
},
|
||||
}
|
||||
@@ -124,7 +124,7 @@ func convertSegmentToOB11(seg protocol.MessageSegment) *MessageSegment {
|
||||
messageID := seg.Data["message_id"]
|
||||
return &MessageSegment{
|
||||
Type: SegmentTypeReply,
|
||||
Data: map[string]interface{}{
|
||||
Data: map[string]any{
|
||||
"id": messageID,
|
||||
},
|
||||
}
|
||||
@@ -134,7 +134,7 @@ func convertSegmentToOB11(seg protocol.MessageSegment) *MessageSegment {
|
||||
faceID := seg.Data["id"]
|
||||
return &MessageSegment{
|
||||
Type: SegmentTypeFace,
|
||||
Data: map[string]interface{}{
|
||||
Data: map[string]any{
|
||||
"id": faceID,
|
||||
},
|
||||
}
|
||||
@@ -149,7 +149,7 @@ func convertSegmentToOB11(seg protocol.MessageSegment) *MessageSegment {
|
||||
}
|
||||
|
||||
// ConvertOB11ToMessageChain 将 OneBot11 消息段转换为通用消息链
|
||||
func ConvertOB11ToMessageChain(ob11Message interface{}) (protocol.MessageChain, error) {
|
||||
func ConvertOB11ToMessageChain(ob11Message any) (protocol.MessageChain, error) {
|
||||
chain := protocol.MessageChain{}
|
||||
|
||||
// 如果是字符串,转换为文本消息段
|
||||
@@ -167,11 +167,11 @@ func ConvertOB11ToMessageChain(ob11Message interface{}) (protocol.MessageChain,
|
||||
}
|
||||
|
||||
// 如果是接口数组,尝试转换
|
||||
if segments, ok := ob11Message.([]interface{}); ok {
|
||||
if segments, ok := ob11Message.([]any); ok {
|
||||
for _, seg := range segments {
|
||||
if segMap, ok := seg.(map[string]interface{}); ok {
|
||||
if segMap, ok := seg.(map[string]any); ok {
|
||||
segType, _ := segMap["type"].(string)
|
||||
segData, _ := segMap["data"].(map[string]interface{})
|
||||
segData, _ := segMap["data"].(map[string]any)
|
||||
genericSeg := convertOB11SegmentToGeneric(MessageSegment{
|
||||
Type: segType,
|
||||
Data: segData,
|
||||
@@ -211,7 +211,7 @@ func convertOB11SegmentToGeneric(seg MessageSegment) protocol.MessageSegment {
|
||||
}
|
||||
return protocol.MessageSegment{
|
||||
Type: protocol.SegmentTypeVoice,
|
||||
Data: map[string]interface{}{
|
||||
Data: map[string]any{
|
||||
"file_id": fileID,
|
||||
},
|
||||
}
|
||||
@@ -223,7 +223,7 @@ func convertOB11SegmentToGeneric(seg MessageSegment) protocol.MessageSegment {
|
||||
case SegmentTypeFace:
|
||||
return protocol.MessageSegment{
|
||||
Type: protocol.SegmentTypeFace,
|
||||
Data: map[string]interface{}{
|
||||
Data: map[string]any{
|
||||
"id": seg.Data["id"],
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user