Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

beta68 #198

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions Processor/Processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,12 @@ func (p *Processors) Autobind(data interface{}) error {
mylog.Printf("Error storing ID: %v", err)
return nil
}
//转换idmap-pro 虚拟值
//将真实id转为int userid64
_, _, err = idmap.StoreIDv2Pro(groupID, realID)
if err != nil {
mylog.Fatalf("Error storing ID689: %v", err)
}
// 单独检查vuin和gid的绑定状态
vuinBound := strconv.FormatInt(userid64, 10) == vuinstr
gidBound := strconv.FormatInt(GroupID64, 10) == idValuestr
Expand All @@ -692,9 +698,10 @@ func (p *Processors) Autobind(data interface{}) error {
return err
}
// idmaps pro也更新
idmap.UpdateVirtualValuev2Pro(GroupID64, idValue, userid64, vuinValue)
// 处理同一个群群友的gid刷新
idmap.UpdateKeysWithNewID(groupID, idValuestr)
err = idmap.UpdateVirtualValuev2Pro(GroupID64, idValue, userid64, vuinValue)
if err != nil {
mylog.Fatalf("Error storing ID703: %v", err)
}
} else if !vuinBound {
// 只有vuin未绑定,更新vuin映射
if err := idmap.UpdateVirtualValuev2(userid64, vuinValue); err != nil {
Expand All @@ -703,8 +710,6 @@ func (p *Processors) Autobind(data interface{}) error {
}
// idmaps pro也更新,但只更新vuin
idmap.UpdateVirtualValuev2Pro(GroupID64, idValue, userid64, vuinValue)
// 处理同一个群群友的gid刷新
idmap.UpdateKeysWithNewID(groupID, idValuestr)
} else if !gidBound {
// 只有gid未绑定,更新gid映射
if err := idmap.UpdateVirtualValuev2(GroupID64, idValue); err != nil {
Expand All @@ -713,8 +718,6 @@ func (p *Processors) Autobind(data interface{}) error {
}
// idmaps pro也更新,但只更新gid
idmap.UpdateVirtualValuev2Pro(GroupID64, idValue, userid64, vuinValue)
// 处理同一个群群友的gid刷新
idmap.UpdateKeysWithNewID(groupID, idValuestr)
} else {
// 两者都已绑定,不执行任何操作
mylog.Errorf("Both vuin and gid are already binded")
Expand Down
2 changes: 2 additions & 0 deletions handlers/message_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func parseMessageContent(paramsMessage callapi.ParamsContent) (string, map[strin
urlImagePattern := regexp.MustCompile(`\[CQ:image,file=https?://(.+)\]`)
base64ImagePattern := regexp.MustCompile(`\[CQ:image,file=base64://(.+)\]`)
base64RecordPattern := regexp.MustCompile(`\[CQ:record,file=base64://(.+)\]`)
urlRecordPattern := regexp.MustCompile(`\[CQ:record,file=https?://(.+)\]`)

patterns := []struct {
key string
Expand All @@ -160,6 +161,7 @@ func parseMessageContent(paramsMessage callapi.ParamsContent) (string, map[strin
{"base64_image", base64ImagePattern},
{"base64_record", base64RecordPattern},
{"local_record", localRecordPattern},
{"url_record", urlRecordPattern},
}

foundItems := make(map[string][]string)
Expand Down
65 changes: 65 additions & 0 deletions handlers/send_group_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,71 @@ func generateGroupMessage(id string, foundItems map[string][]string, messageText
SrvSendMsg: false,
}
}
} else if imageURLs, ok := foundItems["url_record"]; ok && len(imageURLs) > 0 {
var newpiclink string
if config.GetUrlPicTransfer() {
// 从URL下载图片
resp, err := http.Get("http://" + imageURLs[0])
if err != nil {
mylog.Printf("Error downloading the record: %v", err)
return &dto.MessageToCreate{
Content: "错误: 下载语音失败",
MsgID: id,
MsgSeq: msgseq,
MsgType: 0, // 默认文本类型
}
}
defer resp.Body.Close()

// 读取图片数据
recordData, err := io.ReadAll(resp.Body)
if err != nil {
mylog.Printf("Error reading the record data: %v", err)
return &dto.MessageToCreate{
Content: "错误: 读取语音数据失败",
MsgID: id,
MsgSeq: msgseq,
MsgType: 0,
}
}

// 转换为base64
base64Encoded := base64.StdEncoding.EncodeToString(recordData)

// 上传图片并获取新的URL
newURL, err := images.UploadBase64RecordToServer(base64Encoded)
if err != nil {
mylog.Printf("Error uploading base64 encoded image: %v", err)
return &dto.MessageToCreate{
Content: "错误: 上传图片失败",
MsgID: id,
MsgSeq: msgseq,
MsgType: 0,
}
}
// 将图片链接缩短 避免 url not allow
if config.GetLotusValue() {
// 连接到另一个gensokyo
newURL = url.GenerateShortURL(newURL)
} else {
// 自己是主节点
newURL = url.GenerateShortURL(newURL)
// 使用getBaseURL函数来获取baseUrl并与newURL组合
newURL = url.GetBaseURL() + "/url/" + newURL
}
newpiclink = newURL
} else {
newpiclink = "http://" + imageURLs[0]
}

// 发链接图片
return &dto.RichMediaMessage{
EventID: id,
FileType: 3, // 3代表语音
URL: newpiclink, // 新语音链接
Content: "", // 这个字段文档没有了
SrvSendMsg: false,
}
} else if base64_image, ok := foundItems["base64_image"]; ok && len(base64_image) > 0 {
// todo 适配base64图片
//因为QQ群没有 form方式上传,所以在gensokyo内置了图床,需公网,或以lotus方式连接位于公网的gensokyo
Expand Down
2 changes: 1 addition & 1 deletion idmap/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ func FindSubKeysById(id string) ([]string, error) {
return subKeys, nil
}

// 场景: xxx:yyy zzz:bbb zzz:bbb xxx:yyy 把xxx(id)替换为newID 比如更换群号
// 场景: xxx:yyy zzz:bbb zzz:bbb xxx:yyy 把xxx(id)替换为newID 比如更换群号(会卡住)
func UpdateKeysWithNewID(id, newID string) error {
return db.Update(func(tx *bolt.Tx) error {
b := tx.Bucket([]byte(BucketName))
Expand Down
Loading