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:
lafay
2026-03-18 01:22:49 +08:00
parent f3a72264af
commit f3220a2381
32 changed files with 2262 additions and 296 deletions

View File

@@ -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,
},

View File

@@ -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)
}

View File

@@ -49,7 +49,7 @@ func handleWelcomeEvent(ctx context.Context, event protocol.Event, botManager *p
zap.Any("user_id", userID))
// 获取操作者ID邀请者或审批者
var operatorID interface{}
var operatorID any
if opID, exists := data["operator_id"]; exists {
operatorID = opID
}
@@ -95,7 +95,7 @@ func handleWelcomeEvent(ctx context.Context, event protocol.Event, botManager *p
action := &protocol.BaseAction{
Type: protocol.ActionTypeSendGroupMessage,
Params: map[string]interface{}{
Params: map[string]any{
"group_id": groupID,
"message": welcomeChain,
},
@@ -285,14 +285,14 @@ const welcomeTemplate = `
`
// buildWelcomeMessage 构建欢迎消息链使用HTML模板渲染图片
func buildWelcomeMessage(ctx context.Context, userID, operatorID interface{}, subType string, logger *zap.Logger) (protocol.MessageChain, error) {
func buildWelcomeMessage(ctx context.Context, userID, operatorID any, subType string, logger *zap.Logger) (protocol.MessageChain, error) {
logger.Debug("Starting to build welcome message",
zap.Any("user_id", userID),
zap.Any("operator_id", operatorID),
zap.String("sub_type", subType))
// 准备模板数据
data := map[string]interface{}{
data := map[string]any{
"UserID": fmt.Sprintf("%v", userID),
}
logger.Debug("Template data prepared", zap.Any("data", data))