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:
@@ -14,7 +14,7 @@ func (a *Adapter) convertToEvent(raw *RawEvent) (protocol.Event, error) {
|
||||
baseEvent := &protocol.BaseEvent{
|
||||
Timestamp: raw.Time,
|
||||
SelfID: strconv.FormatInt(raw.SelfID, 10),
|
||||
Data: make(map[string]interface{}),
|
||||
Data: make(map[string]any),
|
||||
}
|
||||
|
||||
switch raw.PostType {
|
||||
@@ -49,7 +49,7 @@ func (a *Adapter) convertMessageEvent(raw *RawEvent, base *protocol.BaseEvent) (
|
||||
}
|
||||
|
||||
if raw.Sender != nil {
|
||||
senderData := map[string]interface{}{
|
||||
senderData := map[string]any{
|
||||
"user_id": raw.Sender.UserID,
|
||||
"nickname": raw.Sender.Nickname,
|
||||
}
|
||||
@@ -69,7 +69,7 @@ func (a *Adapter) convertMessageEvent(raw *RawEvent, base *protocol.BaseEvent) (
|
||||
}
|
||||
|
||||
if raw.Anonymous != nil {
|
||||
base.Data["anonymous"] = map[string]interface{}{
|
||||
base.Data["anonymous"] = map[string]any{
|
||||
"id": raw.Anonymous.ID,
|
||||
"name": raw.Anonymous.Name,
|
||||
"flag": raw.Anonymous.Flag,
|
||||
@@ -111,7 +111,7 @@ func (a *Adapter) convertNoticeEvent(raw *RawEvent, base *protocol.BaseEvent) (p
|
||||
case NoticeTypeGroupUpload:
|
||||
// 文件上传信息
|
||||
if raw.File != nil {
|
||||
base.Data["file"] = map[string]interface{}{
|
||||
base.Data["file"] = map[string]any{
|
||||
"id": raw.File.ID,
|
||||
"name": raw.File.Name,
|
||||
"size": raw.File.Size,
|
||||
@@ -156,12 +156,12 @@ func (a *Adapter) convertMetaEvent(raw *RawEvent, base *protocol.BaseEvent) (pro
|
||||
base.DetailType = raw.MetaType
|
||||
|
||||
if raw.Status != nil {
|
||||
statusData := map[string]interface{}{
|
||||
statusData := map[string]any{
|
||||
"online": raw.Status.Online,
|
||||
"good": raw.Status.Good,
|
||||
}
|
||||
if raw.Status.Stat != nil {
|
||||
statusData["stat"] = map[string]interface{}{
|
||||
statusData["stat"] = map[string]any{
|
||||
"packet_received": raw.Status.Stat.PacketReceived,
|
||||
"packet_sent": raw.Status.Stat.PacketSent,
|
||||
"packet_lost": raw.Status.Stat.PacketLost,
|
||||
@@ -183,7 +183,7 @@ func (a *Adapter) convertMetaEvent(raw *RawEvent, base *protocol.BaseEvent) (pro
|
||||
}
|
||||
|
||||
// parseMessageSegments 解析消息段
|
||||
func (a *Adapter) parseMessageSegments(message interface{}) ([]MessageSegment, error) {
|
||||
func (a *Adapter) parseMessageSegments(message any) ([]MessageSegment, error) {
|
||||
if message == nil {
|
||||
return nil, fmt.Errorf("message is nil")
|
||||
}
|
||||
@@ -193,7 +193,7 @@ func (a *Adapter) parseMessageSegments(message interface{}) ([]MessageSegment, e
|
||||
return []MessageSegment{
|
||||
{
|
||||
Type: SegmentTypeText,
|
||||
Data: map[string]interface{}{
|
||||
Data: map[string]any{
|
||||
"text": str,
|
||||
},
|
||||
},
|
||||
@@ -215,7 +215,7 @@ func (a *Adapter) parseMessageSegments(message interface{}) ([]MessageSegment, e
|
||||
}
|
||||
|
||||
// BuildMessage 构建OneBot11消息
|
||||
func BuildMessage(segments []MessageSegment) interface{} {
|
||||
func BuildMessage(segments []MessageSegment) any {
|
||||
if len(segments) == 0 {
|
||||
return ""
|
||||
}
|
||||
@@ -235,7 +235,7 @@ func BuildTextMessage(text string) []MessageSegment {
|
||||
return []MessageSegment{
|
||||
{
|
||||
Type: SegmentTypeText,
|
||||
Data: map[string]interface{}{
|
||||
Data: map[string]any{
|
||||
"text": text,
|
||||
},
|
||||
},
|
||||
@@ -247,7 +247,7 @@ func BuildImageMessage(file string) []MessageSegment {
|
||||
return []MessageSegment{
|
||||
{
|
||||
Type: SegmentTypeImage,
|
||||
Data: map[string]interface{}{
|
||||
Data: map[string]any{
|
||||
"file": file,
|
||||
},
|
||||
},
|
||||
@@ -258,7 +258,7 @@ func BuildImageMessage(file string) []MessageSegment {
|
||||
func BuildAtMessage(userID int64) MessageSegment {
|
||||
return MessageSegment{
|
||||
Type: SegmentTypeAt,
|
||||
Data: map[string]interface{}{
|
||||
Data: map[string]any{
|
||||
"qq": userID,
|
||||
},
|
||||
}
|
||||
@@ -268,7 +268,7 @@ func BuildAtMessage(userID int64) MessageSegment {
|
||||
func BuildReplyMessage(messageID int32) MessageSegment {
|
||||
return MessageSegment{
|
||||
Type: SegmentTypeReply,
|
||||
Data: map[string]interface{}{
|
||||
Data: map[string]any{
|
||||
"id": messageID,
|
||||
},
|
||||
}
|
||||
@@ -278,7 +278,7 @@ func BuildReplyMessage(messageID int32) MessageSegment {
|
||||
func BuildFaceMessage(faceID int) MessageSegment {
|
||||
return MessageSegment{
|
||||
Type: SegmentTypeFace,
|
||||
Data: map[string]interface{}{
|
||||
Data: map[string]any{
|
||||
"id": faceID,
|
||||
},
|
||||
}
|
||||
@@ -288,7 +288,7 @@ func BuildFaceMessage(faceID int) MessageSegment {
|
||||
func BuildRecordMessage(file string) MessageSegment {
|
||||
return MessageSegment{
|
||||
Type: SegmentTypeRecord,
|
||||
Data: map[string]interface{}{
|
||||
Data: map[string]any{
|
||||
"file": file,
|
||||
},
|
||||
}
|
||||
@@ -298,7 +298,7 @@ func BuildRecordMessage(file string) MessageSegment {
|
||||
func BuildVideoMessage(file string) MessageSegment {
|
||||
return MessageSegment{
|
||||
Type: SegmentTypeVideo,
|
||||
Data: map[string]interface{}{
|
||||
Data: map[string]any{
|
||||
"file": file,
|
||||
},
|
||||
}
|
||||
@@ -308,7 +308,7 @@ func BuildVideoMessage(file string) MessageSegment {
|
||||
func BuildShareMessage(url, title string) MessageSegment {
|
||||
return MessageSegment{
|
||||
Type: SegmentTypeShare,
|
||||
Data: map[string]interface{}{
|
||||
Data: map[string]any{
|
||||
"url": url,
|
||||
"title": title,
|
||||
},
|
||||
@@ -319,7 +319,7 @@ func BuildShareMessage(url, title string) MessageSegment {
|
||||
func BuildLocationMessage(lat, lon float64, title, content string) MessageSegment {
|
||||
return MessageSegment{
|
||||
Type: SegmentTypeLocation,
|
||||
Data: map[string]interface{}{
|
||||
Data: map[string]any{
|
||||
"lat": lat,
|
||||
"lon": lon,
|
||||
"title": title,
|
||||
@@ -332,7 +332,7 @@ func BuildLocationMessage(lat, lon float64, title, content string) MessageSegmen
|
||||
func BuildMusicMessage(musicType, musicID string) MessageSegment {
|
||||
return MessageSegment{
|
||||
Type: SegmentTypeMusic,
|
||||
Data: map[string]interface{}{
|
||||
Data: map[string]any{
|
||||
"type": musicType,
|
||||
"id": musicID,
|
||||
},
|
||||
@@ -343,7 +343,7 @@ func BuildMusicMessage(musicType, musicID string) MessageSegment {
|
||||
func BuildCustomMusicMessage(url, audio, title, content, image string) MessageSegment {
|
||||
return MessageSegment{
|
||||
Type: SegmentTypeMusic,
|
||||
Data: map[string]interface{}{
|
||||
Data: map[string]any{
|
||||
"type": "custom",
|
||||
"url": url,
|
||||
"audio": audio,
|
||||
|
||||
Reference in New Issue
Block a user