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:
@@ -105,7 +105,7 @@ func (b *Bot) Disconnect(ctx context.Context) error {
|
||||
}
|
||||
|
||||
// SendAction 发送动作
|
||||
func (b *Bot) SendAction(ctx context.Context, action protocol.Action) (map[string]interface{}, error) {
|
||||
func (b *Bot) SendAction(ctx context.Context, action protocol.Action) (map[string]any, error) {
|
||||
if b.status != protocol.BotStatusRunning {
|
||||
return nil, fmt.Errorf("bot is not running")
|
||||
}
|
||||
@@ -119,8 +119,8 @@ func (b *Bot) GetAdapter() *Adapter {
|
||||
}
|
||||
|
||||
// GetInfo 获取机器人信息
|
||||
func (b *Bot) GetInfo() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
func (b *Bot) GetInfo() map[string]any {
|
||||
return map[string]any{
|
||||
"id": b.id,
|
||||
"protocol": "milky",
|
||||
"status": b.status,
|
||||
@@ -144,7 +144,7 @@ func (b *Bot) SetStatus(status protocol.BotStatus) {
|
||||
|
||||
// SendPrivateMessage 发送私聊消息
|
||||
func (b *Bot) SendPrivateMessage(ctx context.Context, userID int64, segments []OutgoingSegment) (*APIResponse, error) {
|
||||
params := map[string]interface{}{
|
||||
params := map[string]any{
|
||||
"user_id": userID,
|
||||
"segments": segments,
|
||||
}
|
||||
@@ -153,7 +153,7 @@ func (b *Bot) SendPrivateMessage(ctx context.Context, userID int64, segments []O
|
||||
|
||||
// SendGroupMessage 发送群消息
|
||||
func (b *Bot) SendGroupMessage(ctx context.Context, groupID int64, segments []OutgoingSegment) (*APIResponse, error) {
|
||||
params := map[string]interface{}{
|
||||
params := map[string]any{
|
||||
"group_id": groupID,
|
||||
"segments": segments,
|
||||
}
|
||||
@@ -162,7 +162,7 @@ func (b *Bot) SendGroupMessage(ctx context.Context, groupID int64, segments []Ou
|
||||
|
||||
// SendTempMessage 发送临时消息
|
||||
func (b *Bot) SendTempMessage(ctx context.Context, groupID, userID int64, segments []OutgoingSegment) (*APIResponse, error) {
|
||||
params := map[string]interface{}{
|
||||
params := map[string]any{
|
||||
"group_id": groupID,
|
||||
"user_id": userID,
|
||||
"segments": segments,
|
||||
@@ -172,7 +172,7 @@ func (b *Bot) SendTempMessage(ctx context.Context, groupID, userID int64, segmen
|
||||
|
||||
// RecallMessage 撤回消息
|
||||
func (b *Bot) RecallMessage(ctx context.Context, messageScene string, peerID, messageSeq int64) (*APIResponse, error) {
|
||||
params := map[string]interface{}{
|
||||
params := map[string]any{
|
||||
"message_scene": messageScene,
|
||||
"peer_id": peerID,
|
||||
"message_seq": messageSeq,
|
||||
@@ -192,7 +192,7 @@ func (b *Bot) GetGroupList(ctx context.Context) (*APIResponse, error) {
|
||||
|
||||
// GetGroupMemberList 获取群成员列表
|
||||
func (b *Bot) GetGroupMemberList(ctx context.Context, groupID int64) (*APIResponse, error) {
|
||||
params := map[string]interface{}{
|
||||
params := map[string]any{
|
||||
"group_id": groupID,
|
||||
}
|
||||
return b.adapter.CallAPI(ctx, "get_group_member_list", params)
|
||||
@@ -200,7 +200,7 @@ func (b *Bot) GetGroupMemberList(ctx context.Context, groupID int64) (*APIRespon
|
||||
|
||||
// GetGroupMemberInfo 获取群成员信息
|
||||
func (b *Bot) GetGroupMemberInfo(ctx context.Context, groupID, userID int64) (*APIResponse, error) {
|
||||
params := map[string]interface{}{
|
||||
params := map[string]any{
|
||||
"group_id": groupID,
|
||||
"user_id": userID,
|
||||
}
|
||||
@@ -209,7 +209,7 @@ func (b *Bot) GetGroupMemberInfo(ctx context.Context, groupID, userID int64) (*A
|
||||
|
||||
// SetGroupAdmin 设置群管理员
|
||||
func (b *Bot) SetGroupAdmin(ctx context.Context, groupID, userID int64, isSet bool) (*APIResponse, error) {
|
||||
params := map[string]interface{}{
|
||||
params := map[string]any{
|
||||
"group_id": groupID,
|
||||
"user_id": userID,
|
||||
"is_set": isSet,
|
||||
@@ -219,7 +219,7 @@ func (b *Bot) SetGroupAdmin(ctx context.Context, groupID, userID int64, isSet bo
|
||||
|
||||
// SetGroupCard 设置群名片
|
||||
func (b *Bot) SetGroupCard(ctx context.Context, groupID, userID int64, card string) (*APIResponse, error) {
|
||||
params := map[string]interface{}{
|
||||
params := map[string]any{
|
||||
"group_id": groupID,
|
||||
"user_id": userID,
|
||||
"card": card,
|
||||
@@ -229,7 +229,7 @@ func (b *Bot) SetGroupCard(ctx context.Context, groupID, userID int64, card stri
|
||||
|
||||
// SetGroupName 设置群名
|
||||
func (b *Bot) SetGroupName(ctx context.Context, groupID int64, groupName string) (*APIResponse, error) {
|
||||
params := map[string]interface{}{
|
||||
params := map[string]any{
|
||||
"group_id": groupID,
|
||||
"group_name": groupName,
|
||||
}
|
||||
@@ -238,7 +238,7 @@ func (b *Bot) SetGroupName(ctx context.Context, groupID int64, groupName string)
|
||||
|
||||
// KickGroupMember 踢出群成员
|
||||
func (b *Bot) KickGroupMember(ctx context.Context, groupID, userID int64, rejectAddRequest bool) (*APIResponse, error) {
|
||||
params := map[string]interface{}{
|
||||
params := map[string]any{
|
||||
"group_id": groupID,
|
||||
"user_id": userID,
|
||||
"reject_add_request": rejectAddRequest,
|
||||
@@ -248,7 +248,7 @@ func (b *Bot) KickGroupMember(ctx context.Context, groupID, userID int64, reject
|
||||
|
||||
// MuteGroupMember 禁言群成员
|
||||
func (b *Bot) MuteGroupMember(ctx context.Context, groupID, userID int64, duration int32) (*APIResponse, error) {
|
||||
params := map[string]interface{}{
|
||||
params := map[string]any{
|
||||
"group_id": groupID,
|
||||
"user_id": userID,
|
||||
"duration": duration,
|
||||
@@ -258,7 +258,7 @@ func (b *Bot) MuteGroupMember(ctx context.Context, groupID, userID int64, durati
|
||||
|
||||
// MuteGroupWhole 全体禁言
|
||||
func (b *Bot) MuteGroupWhole(ctx context.Context, groupID int64, isMute bool) (*APIResponse, error) {
|
||||
params := map[string]interface{}{
|
||||
params := map[string]any{
|
||||
"group_id": groupID,
|
||||
"is_mute": isMute,
|
||||
}
|
||||
@@ -267,7 +267,7 @@ func (b *Bot) MuteGroupWhole(ctx context.Context, groupID int64, isMute bool) (*
|
||||
|
||||
// LeaveGroup 退出群
|
||||
func (b *Bot) LeaveGroup(ctx context.Context, groupID int64) (*APIResponse, error) {
|
||||
params := map[string]interface{}{
|
||||
params := map[string]any{
|
||||
"group_id": groupID,
|
||||
}
|
||||
return b.adapter.CallAPI(ctx, "leave_group", params)
|
||||
@@ -275,7 +275,7 @@ func (b *Bot) LeaveGroup(ctx context.Context, groupID int64) (*APIResponse, erro
|
||||
|
||||
// HandleFriendRequest 处理好友请求
|
||||
func (b *Bot) HandleFriendRequest(ctx context.Context, initiatorUID string, accept bool) (*APIResponse, error) {
|
||||
params := map[string]interface{}{
|
||||
params := map[string]any{
|
||||
"initiator_uid": initiatorUID,
|
||||
"accept": accept,
|
||||
}
|
||||
@@ -284,7 +284,7 @@ func (b *Bot) HandleFriendRequest(ctx context.Context, initiatorUID string, acce
|
||||
|
||||
// HandleGroupJoinRequest 处理入群申请
|
||||
func (b *Bot) HandleGroupJoinRequest(ctx context.Context, groupID, notificationSeq int64, accept bool, rejectReason string) (*APIResponse, error) {
|
||||
params := map[string]interface{}{
|
||||
params := map[string]any{
|
||||
"group_id": groupID,
|
||||
"notification_seq": notificationSeq,
|
||||
"accept": accept,
|
||||
@@ -295,7 +295,7 @@ func (b *Bot) HandleGroupJoinRequest(ctx context.Context, groupID, notificationS
|
||||
|
||||
// HandleGroupInvitation 处理群邀请
|
||||
func (b *Bot) HandleGroupInvitation(ctx context.Context, groupID, invitationSeq int64, accept bool) (*APIResponse, error) {
|
||||
params := map[string]interface{}{
|
||||
params := map[string]any{
|
||||
"group_id": groupID,
|
||||
"invitation_seq": invitationSeq,
|
||||
"accept": accept,
|
||||
@@ -305,7 +305,7 @@ func (b *Bot) HandleGroupInvitation(ctx context.Context, groupID, invitationSeq
|
||||
|
||||
// UploadFile 上传文件
|
||||
func (b *Bot) UploadFile(ctx context.Context, fileType, filePath string) (*APIResponse, error) {
|
||||
params := map[string]interface{}{
|
||||
params := map[string]any{
|
||||
"file_type": fileType,
|
||||
"file_path": filePath,
|
||||
}
|
||||
@@ -314,7 +314,7 @@ func (b *Bot) UploadFile(ctx context.Context, fileType, filePath string) (*APIRe
|
||||
|
||||
// GetFile 获取文件
|
||||
func (b *Bot) GetFile(ctx context.Context, fileID string) (*APIResponse, error) {
|
||||
params := map[string]interface{}{
|
||||
params := map[string]any{
|
||||
"file_id": fileID,
|
||||
}
|
||||
return b.adapter.CallAPI(ctx, "get_file", params)
|
||||
|
||||
Reference in New Issue
Block a user