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:
@@ -192,7 +192,7 @@ func handleMCSBindCommand(ctx context.Context, event protocol.Event, botManager
|
||||
|
||||
action := &protocol.BaseAction{
|
||||
Type: protocol.ActionTypeSendGroupMessage,
|
||||
Params: map[string]interface{}{
|
||||
Params: map[string]any{
|
||||
"group_id": groupID,
|
||||
"message": errorMsg,
|
||||
},
|
||||
|
||||
@@ -76,7 +76,7 @@ func Ping(host string, port int, timeout time.Duration) (*ServerStatus, error) {
|
||||
}
|
||||
|
||||
// 解析 JSON 响应
|
||||
var statusData map[string]interface{}
|
||||
var statusData map[string]any
|
||||
if err := json.Unmarshal([]byte(statusJSON), &statusData); err != nil {
|
||||
return nil, fmt.Errorf("failed to parse JSON: %w", err)
|
||||
}
|
||||
@@ -88,14 +88,14 @@ func Ping(host string, port int, timeout time.Duration) (*ServerStatus, error) {
|
||||
}
|
||||
|
||||
// 解析 description
|
||||
if desc, ok := statusData["description"].(map[string]interface{}); ok {
|
||||
if desc, ok := statusData["description"].(map[string]any); ok {
|
||||
if text, ok := desc["text"].(string); ok {
|
||||
status.Description = text
|
||||
} else if text, ok := desc["extra"].([]interface{}); ok && len(text) > 0 {
|
||||
} else if text, ok := desc["extra"].([]any); ok && len(text) > 0 {
|
||||
// 处理 extra 数组
|
||||
var descText strings.Builder
|
||||
for _, item := range text {
|
||||
if itemMap, ok := item.(map[string]interface{}); ok {
|
||||
if itemMap, ok := item.(map[string]any); ok {
|
||||
if text, ok := itemMap["text"].(string); ok {
|
||||
descText.WriteString(text)
|
||||
}
|
||||
@@ -108,7 +108,7 @@ func Ping(host string, port int, timeout time.Duration) (*ServerStatus, error) {
|
||||
}
|
||||
|
||||
// 解析 version
|
||||
if version, ok := statusData["version"].(map[string]interface{}); ok {
|
||||
if version, ok := statusData["version"].(map[string]any); ok {
|
||||
if name, ok := version["name"].(string); ok {
|
||||
status.Version.Name = name
|
||||
}
|
||||
@@ -118,7 +118,7 @@ func Ping(host string, port int, timeout time.Duration) (*ServerStatus, error) {
|
||||
}
|
||||
|
||||
// 解析 players
|
||||
if players, ok := statusData["players"].(map[string]interface{}); ok {
|
||||
if players, ok := statusData["players"].(map[string]any); ok {
|
||||
if online, ok := players["online"].(float64); ok {
|
||||
status.Players.Online = int(online)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user