Skip to content

Commit

Permalink
Beta27 (#79)
Browse files Browse the repository at this point in the history
* add

* arrayfix

* bugfix
  • Loading branch information
Hoshinonyaruko authored Nov 13, 2023
1 parent 5ab1cbc commit b7de625
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
40 changes: 36 additions & 4 deletions handlers/message_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,21 +388,54 @@ func ConvertToSegmentedMessage(data interface{}) []map[string]interface{} {
// 使用正则表达式查找所有的[@数字]格式
r := regexp.MustCompile(`<@!(\d+)>`)
atMatches := r.FindAllStringSubmatch(msg.Content, -1)

// 将msg.Content里的BotID替换成AppID
msg.Content = strings.ReplaceAll(msg.Content, BotID, AppID)
for _, match := range atMatches {
userID := match[1]

if userID == AppID {
if config.GetRemoveAt() {
// 根据配置移除
msg.Content = strings.Replace(msg.Content, match[0], "", 1)
continue // 跳过当前循环迭代
} else {
//将其转换为AppID
userID = AppID
// 构建at部分的映射并加入到messageSegments
atSegment := map[string]interface{}{
"type": "at",
"data": map[string]interface{}{
"qq": userID,
},
}
messageSegments = append(messageSegments, atSegment)
// 从原始内容中移除at部分
msg.Content = strings.Replace(msg.Content, match[0], "", 1)
continue // 跳过当前循环迭代
}
}
// 不是 AppID,进行正常处理
userID64, err := idmap.StoreIDv2(userID)
if err != nil {
// 如果存储失败,记录错误并继续使用原始 userID
mylog.Printf("Error storing ID: %v", err)
} else {
// 类型转换成功,使用新的 userID
userID = strconv.FormatInt(userID64, 10)
}

// 构建at部分的映射并加入到messageSegments
atSegment := map[string]interface{}{
"type": "at",
"data": map[string]interface{}{
"qq": match[1],
"qq": userID,
},
}
messageSegments = append(messageSegments, atSegment)

// 从原始内容中移除at部分
msg.Content = strings.Replace(msg.Content, match[0], "", 1)
}

// 如果还有其他内容,那么这些内容被视为文本部分
if msg.Content != "" {
textSegment := map[string]interface{}{
Expand All @@ -413,6 +446,5 @@ func ConvertToSegmentedMessage(data interface{}) []map[string]interface{} {
}
messageSegments = append(messageSegments, textSegment)
}

return messageSegments
}
6 changes: 3 additions & 3 deletions handlers/send_private_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ func handleSendPrivateMsg(client callapi.Client, api openapi.OpenAPI, apiv2 open
//当收到发私信调用 并且来源是频道
handleSendGuildChannelPrivateMsg(client, api, apiv2, message, nil, nil)
default:
mylog.Printf("Unknown message type(视为频道私信调用): %s", msgType)
//按频道私信处理
handleSendGuildChannelPrivateMsg(client, api, apiv2, message, nil, nil)
mylog.Printf("Unknown message type: %s", msgType)
//直接返回成功
SendResponse(client, nil, &message)
}
}

Expand Down

0 comments on commit b7de625

Please sign in to comment.