Skip to content

Commit

Permalink
beta406
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoshinonyaruko committed May 24, 2024
1 parent 887f098 commit 6c8a5ad
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 21 deletions.
20 changes: 12 additions & 8 deletions Processor/ProcessC2CMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ func (p *Processors) ProcessC2CMessage(data *dto.WSC2CMessageData) error {
SubType: "friend",
Time: time.Now().Unix(),
}
// 额外字段
if !config.GetNativeOb11() {
privateMsg.RealMessageType = "group_private"
privateMsg.IsBindedUserId = IsBindedUserId
if IsBindedUserId {
privateMsg.Avatar, _ = GenerateAvatarURL(userid64)
}
privateMsg.RealUserID = data.Author.ID
privateMsg.Avatar, _ = GenerateAvatarURLV2(data.Author.ID)
}
// 根据条件判断是否添加Echo字段
if config.GetTwoWayEcho() {
Expand Down Expand Up @@ -238,11 +238,15 @@ func (p *Processors) ProcessC2CMessage(data *dto.WSC2CMessageData) error {
Area: "0",
Level: "0",
},
SubType: "normal",
Time: time.Now().Unix(),
Avatar: "",
RealMessageType: "group_private",
IsBindedUserId: IsBindedUserId,
SubType: "normal",
Time: time.Now().Unix(),
}
//增强配置
if !config.GetNativeOb11() {
groupMsg.RealMessageType = "group_private"
groupMsg.IsBindedUserId = IsBindedUserId
groupMsg.RealUserID = data.Author.ID
groupMsg.Avatar, _ = GenerateAvatarURLV2(data.Author.ID)
}
//根据条件判断是否增加nick和card
var CaN = config.GetCardAndNick()
Expand Down
1 change: 1 addition & 0 deletions Processor/Processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ type OnebotPrivateMessage struct {
Font int `json:"font"` // Optional field
UserID int64 `json:"user_id"` // Can be either string or int depending on logic
RealMessageType string `json:"real_message_type,omitempty"` //当前信息的真实类型 group group_private guild guild_private
RealUserID string `json:"real_user_id,omitempty"` //当前真实uid
IsBindedUserId bool `json:"is_binded_user_id,omitempty"` //当前用户号号是否是binded后的
}

Expand Down
40 changes: 37 additions & 3 deletions handlers/send_group_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,9 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap
groupMessage.Timestamp = time.Now().Unix() // 设置时间戳
}

var resp *dto.GroupMessageResponse
// 发送组合消息
resp, err := apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage)
resp, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage)
if err != nil {
mylog.Printf("发送组合消息失败: %v", err)
}
Expand All @@ -329,6 +330,12 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap
pair.Group = message.Params.GroupID.(string)
pair.GroupMessage = groupMessage
echo.PushGlobalStack(pair)
} else if err != nil && strings.Contains(err.Error(), `"code":40034025`) {
groupMessage.EventID = ""
resp, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage)
if err != nil {
mylog.Printf("发送组合消息失败: %v", err)
}
}

// 发送成功回执
Expand All @@ -351,9 +358,10 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap
return "", nil // 或其他错误处理
}

var resp *dto.GroupMessageResponse
groupMessage.Timestamp = time.Now().Unix() // 设置时间戳
//重新为err赋值
resp, err := apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage)
resp, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage)
if err != nil {
mylog.Printf("发送文本群组信息失败: %v", err)
}
Expand All @@ -363,6 +371,12 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap
pair.Group = message.Params.GroupID.(string)
pair.GroupMessage = groupMessage
echo.PushGlobalStack(pair)
} else if err != nil && strings.Contains(err.Error(), `"code":40034025`) {
groupMessage.EventID = ""
resp, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage)
if err != nil {
mylog.Printf("发送文本群组信息失败: %v", err)
}
}
//发送成功回执
retmsg, _ = SendResponse(client, err, &message, resp, api, apiv2)
Expand Down Expand Up @@ -401,7 +415,7 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap
return "", nil // 或其他错误处理
}
//重新为err赋值
resp, err := apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage)
resp, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage)
if err != nil {
mylog.Printf("发送 MessageToCreate 信息失败: %v", err)
}
Expand All @@ -411,6 +425,14 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap
pair.Group = message.Params.GroupID.(string)
pair.GroupMessage = groupMessage
echo.PushGlobalStack(pair)
} else if err != nil && strings.Contains(err.Error(), `"code":40034025`) {
//请求参数event_id无效 重试
groupMessage.EventID = ""
//重新为err赋值
resp, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage)
if err != nil {
mylog.Printf("发送 MessageToCreate 信息失败 on code 40034025: %v", err)
}
}
//发送成功回执
retmsg, _ = SendResponse(client, err, &message, resp, api, apiv2)
Expand Down Expand Up @@ -442,6 +464,12 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap
pair.Group = message.Params.GroupID.(string)
pair.GroupMessage = groupMessage
echo.PushGlobalStack(pair)
} else if err != nil && strings.Contains(err.Error(), `"code":40034025`) {
groupMessage.EventID = ""
resp, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage)
if err != nil {
mylog.Printf("发送文本报错信息失败: %v", err)
}
}
}
}
Expand Down Expand Up @@ -471,6 +499,12 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap
pair.Group = message.Params.GroupID.(string)
pair.GroupMessage = groupMessage
echo.PushGlobalStack(pair)
} else if err != nil && strings.Contains(err.Error(), `"code":40034025`) {
groupMessage.EventID = ""
resp, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage)
if err != nil {
mylog.Printf("发送图片失败: %v", err)
}
}
}
//发送成功回执
Expand Down
20 changes: 10 additions & 10 deletions httpapi/httpapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,11 +446,11 @@ func convertToString(value interface{}) string {
func handleDeleteMsg(c *gin.Context, api openapi.OpenAPI, apiV2 openapi.OpenAPI) {
// 使用interface{}以适应不同类型的输入,接受动态参数类型
var req struct {
UserID interface{} `json:"user_id,omitempty" form:"user_id"`
GroupID interface{} `json:"group_id,omitempty" form:"group_id"`
ChannelID interface{} `json:"channel_id,omitempty" form:"channel_id"`
GuildID interface{} `json:"guild_id,omitempty" form:"guild_id"`
MessageID interface{} `json:"message_id" form:"message_id"`
UserID string `json:"user_id,omitempty" form:"user_id"`
GroupID string `json:"group_id,omitempty" form:"group_id"`
ChannelID string `json:"channel_id,omitempty" form:"channel_id"`
GuildID string `json:"guild_id,omitempty" form:"guild_id"`
MessageID string `json:"message_id" form:"message_id"`
}

// 根据请求方法解析参数
Expand All @@ -471,19 +471,19 @@ func handleDeleteMsg(c *gin.Context, api openapi.OpenAPI, apiV2 openapi.OpenAPI)
// 构造参数内容,只包括实际有值的字段
params := callapi.ParamsContent{}

if req.UserID != nil {
if req.UserID != "" {
params.UserID = convertToString(req.UserID)
}
if req.GroupID != nil {
if req.GroupID != "" {
params.GroupID = convertToString(req.GroupID)
}
if req.ChannelID != nil {
if req.ChannelID != "" {
params.ChannelID = convertToString(req.ChannelID)
}
if req.GuildID != nil {
if req.GuildID != "" {
params.GuildID = convertToString(req.GuildID)
}
if req.MessageID != nil {
if req.MessageID != "" {
params.MessageID = convertToString(req.MessageID)
}

Expand Down

0 comments on commit 6c8a5ad

Please sign in to comment.