Skip to content

Commit

Permalink
Beta336 (#339)
Browse files Browse the repository at this point in the history
* beta318

* beta319

* beta320

* beata321

* beta322

* beta323

* beta324

* beta325

* beta326

* beta334

* beta335

* beta336
  • Loading branch information
Hoshinonyaruko authored Feb 29, 2024
1 parent 93345de commit c928854
Show file tree
Hide file tree
Showing 13 changed files with 900 additions and 52 deletions.
18 changes: 16 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ type Settings struct {
GlobalInteractionToMessage bool `yaml:"global_interaction_to_message"`
AutoPutInteraction bool `yaml:"auto_put_interaction"`
PutInteractionDelay int `yaml:"put_interaction_delay"`
ImgUpApiVtv2 bool `yaml:"img_up_api_ntv2"`
}

// LoadConfig 从文件中加载配置并初始化单例配置
Expand Down Expand Up @@ -183,7 +184,7 @@ func LoadConfig(path string) (*Config, error) {
}

// 确保配置完整性
if err := ensureConfigComplete(conf, path); err != nil {
if err := ensureConfigComplete(path); err != nil {
return nil, err
}

Expand All @@ -193,7 +194,7 @@ func LoadConfig(path string) (*Config, error) {
}

// 确保配置完整性
func ensureConfigComplete(conf *Config, path string) error {
func ensureConfigComplete(path string) error {
// 读取配置文件到缓冲区
configData, err := os.ReadFile(path)
if err != nil {
Expand Down Expand Up @@ -1844,3 +1845,16 @@ func GetPutInteractionDelay() int {
}
return instance.Settings.PutInteractionDelay
}

// 获取ntv2转换开关
func GetImgUpApiVtv2() bool {
mu.Lock()
defer mu.Unlock()

if instance == nil {
mylog.Println("Warning: instance is nil when trying to ImgUpApiVtv2 value.")
return false
}
return instance.Settings.ImgUpApiVtv2
}

3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ require (
require (
github.com/clbanning/mxj v1.8.4 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-querystring v1.0.0 // indirect
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
Expand Down Expand Up @@ -69,6 +70,6 @@ require (
golang.org/x/net v0.10.0
golang.org/x/sys v0.13.0
golang.org/x/text v0.9.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
google.golang.org/protobuf v1.32.0 // indirect
mvdan.cc/xurls v1.1.0
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvq
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
Expand Down Expand Up @@ -276,6 +278,8 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
10 changes: 6 additions & 4 deletions handlers/message_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ func parseQQMuiscMDData(musicid string) (*dto.Markdown, *keyboard.MessageKeyboar
return nil, nil, errors.New("song not found")
}
albumMid := info.Get("track_info.album.mid").String()
pinfo, _ := FetchTrackInfo(info.Get("track_info.mid").Str)
//pinfo, _ := FetchTrackInfo(info.Get("track_info.mid").Str)
jumpURL := "https://i.y.qq.com/v8/playsong.html?platform=11&appshare=android_qq&appversion=10030010&hosteuin=oKnlNenz7i-s7c**&songmid=" + info.Get("track_info.mid").Str + "&type=0&appsongtype=1&_wv=1&source=qq&ADTAG=qfshare"
content := info.Get("track_info.singer.0.name").String()

Expand Down Expand Up @@ -1077,9 +1077,10 @@ func parseQQMuiscMDData(musicid string) (*dto.Markdown, *keyboard.MessageKeyboar
Params: mdParams,
}
// 使用gjson获取musicUrl
musicUrl := gjson.Get(pinfo, "url_mid.data.midurlinfo.0.purl").String()
//musicUrl := gjson.Get(pinfo, "url_mid.data.midurlinfo.0.purl").String()
// 处理 Keyboard
kb := createMusicKeyboard(jumpURL, musicUrl)
//kb := createMusicKeyboard(jumpURL, musicUrl)
kb := createMusicKeyboard(jumpURL)

return md, kb, nil
}
Expand All @@ -1093,7 +1094,8 @@ func QQMusicSongInfo(id string) (gjson.Result, error) {
return gjson.Get(d, "songinfo.data"), nil
}

func createMusicKeyboard(jumpURL string, musicURL string) *keyboard.MessageKeyboard {
// func createMusicKeyboard(jumpURL string, musicURL string) *keyboard.MessageKeyboard {
func createMusicKeyboard(jumpURL string) *keyboard.MessageKeyboard {
// 初始化自定义键盘
customKeyboard := &keyboard.CustomKeyboard{}
currentRow := &keyboard.Row{} // 创建一个新行
Expand Down
43 changes: 17 additions & 26 deletions handlers/send_group_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap
if message.Params.UserID != nil {
messageID = echo.GetLazyMessagesIdv2(message.Params.GroupID.(string), message.Params.UserID.(string))
mylog.Printf("GetLazyMessagesIdv2: %v", messageID)
} else {
//如果应用端没有传递userid 那就用群号模式的lazyid 但是不保证顺序是对的
messageID = echo.GetLazyMessagesId(message.Params.GroupID.(string))
mylog.Printf("GetLazyMessagesIdv1: %v", messageID)
}
//2000是群主动 此时不能被动转主动
//仅在开启lazy_message_id时,有信息主动转被动特性,即,SSM
Expand Down Expand Up @@ -205,7 +209,7 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap
singleItem[imageType] = []string{imageUrl}
msgseq := echo.GetMappingSeq(messageID)
echo.AddMappingSeq(messageID, msgseq+1)
groupReply := generateGroupMessage(messageID, singleItem, "", msgseq+1)
groupReply := generateGroupMessage(messageID, singleItem, "", msgseq+1, apiv2, message.Params.GroupID.(string))
// 进行类型断言
richMediaMessage, ok := groupReply.(*dto.RichMediaMessage)
if !ok {
Expand Down Expand Up @@ -262,7 +266,6 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap
_, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage)
if err != nil {
mylog.Printf("发送组合消息失败: %v", err)
return "", nil // 或其他错误处理
}
if err != nil && strings.Contains(err.Error(), `"code":22009`) {
mylog.Printf("信息发送失败,加入到队列中,下次被动信息进行发送")
Expand All @@ -283,7 +286,7 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap
if messageText != "" {
msgseq := echo.GetMappingSeq(messageID)
echo.AddMappingSeq(messageID, msgseq+1)
groupReply := generateGroupMessage(messageID, nil, messageText, msgseq+1)
groupReply := generateGroupMessage(messageID, nil, messageText, msgseq+1, apiv2, message.Params.GroupID.(string))

// 进行类型断言
groupMessage, ok := groupReply.(*dto.MessageToCreate)
Expand Down Expand Up @@ -317,7 +320,7 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap
//mylog.Println("singleItem:", singleItem)
msgseq := echo.GetMappingSeq(messageID)
echo.AddMappingSeq(messageID, msgseq+1)
groupReply := generateGroupMessage(messageID, singleItem, "", msgseq+1)
groupReply := generateGroupMessage(messageID, singleItem, "", msgseq+1, apiv2, message.Params.GroupID.(string))
// 进行类型断言
richMediaMessage, ok := groupReply.(*dto.RichMediaMessage)
if !ok {
Expand Down Expand Up @@ -352,7 +355,7 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap
if config.GetSendError() { //把报错当作文本发出去
msgseq := echo.GetMappingSeq(messageID)
echo.AddMappingSeq(messageID, msgseq+1)
groupReply := generateGroupMessage(messageID, nil, err.Error(), msgseq+1)
groupReply := generateGroupMessage(messageID, nil, err.Error(), msgseq+1, apiv2, message.Params.GroupID.(string))
// 进行类型断言
groupMessage, ok := groupReply.(*dto.MessageToCreate)
if !ok {
Expand Down Expand Up @@ -496,7 +499,7 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap
}

// 上传富媒体信息
func generateGroupMessage(id string, foundItems map[string][]string, messageText string, msgseq int) interface{} {
func generateGroupMessage(id string, foundItems map[string][]string, messageText string, msgseq int, apiv2 openapi.OpenAPI, groupid string) interface{} {
if imageURLs, ok := foundItems["local_image"]; ok && len(imageURLs) > 0 {
// 从本地路径读取图片
imageData, err := os.ReadFile(imageURLs[0])
Expand Down Expand Up @@ -527,7 +530,7 @@ func generateGroupMessage(id string, foundItems map[string][]string, messageText
base64Encoded := base64.StdEncoding.EncodeToString(compressedData)

// 上传base64编码的图片并获取其URL
imageURL, err := images.UploadBase64ImageToServer(base64Encoded)
imageURL, _, _, _, err := images.UploadBase64ImageToServer(id, base64Encoded, groupid, apiv2)
if err != nil {
mylog.Printf("Error uploading base64 encoded image: %v", err)
// 如果上传失败,也返回文本信息,提示上传失败
Expand Down Expand Up @@ -569,10 +572,7 @@ func generateGroupMessage(id string, foundItems map[string][]string, messageText
return nil
}
RecordData = silk.EncoderSilk(RecordData)
mylog.Errorf("音频转码ing")
if err != nil {
return nil
}
mylog.Printf("音频转码ing")
}
// 将解码的语音数据转换回base64格式并上传
imageURL, err := images.UploadBase64RecordToServer(base64.StdEncoding.EncodeToString(RecordData))
Expand Down Expand Up @@ -620,7 +620,7 @@ func generateGroupMessage(id string, foundItems map[string][]string, messageText
base64Encoded := base64.StdEncoding.EncodeToString(imageData)

// 上传图片并获取新的URL
newURL, err := images.UploadBase64ImageToServer(base64Encoded)
newURL, _, _, _, err := images.UploadBase64ImageToServer(id, base64Encoded, groupid, apiv2)
if err != nil {
mylog.Printf("Error uploading base64 encoded image: %v", err)
return &dto.MessageToCreate{
Expand Down Expand Up @@ -685,7 +685,7 @@ func generateGroupMessage(id string, foundItems map[string][]string, messageText
base64Encoded := base64.StdEncoding.EncodeToString(imageData)

// 上传图片并获取新的URL
newURL, err := images.UploadBase64ImageToServer(base64Encoded)
newURL, _, _, _, err := images.UploadBase64ImageToServer(id, base64Encoded, groupid, apiv2)
if err != nil {
mylog.Printf("Error uploading base64 encoded image: %v", err)
return &dto.MessageToCreate{
Expand Down Expand Up @@ -735,10 +735,7 @@ func generateGroupMessage(id string, foundItems map[string][]string, messageText
return nil
}
fileRecordData = silk.EncoderSilk(fileRecordData)
mylog.Errorf("音频转码ing")
if err != nil {
return nil
}
mylog.Printf("音频转码ing")
}
// 将解码的语音数据转换回base64格式并上传
imageURL, err := images.UploadBase64RecordToServer(base64.StdEncoding.EncodeToString(fileRecordData))
Expand Down Expand Up @@ -788,10 +785,7 @@ func generateGroupMessage(id string, foundItems map[string][]string, messageText
return nil
}
recordData = silk.EncoderSilk(recordData)
mylog.Errorf("音频转码ing")
if err != nil {
return nil
}
mylog.Printf("音频转码ing")
}
// 转换为base64
base64Encoded := base64.StdEncoding.EncodeToString(recordData)
Expand Down Expand Up @@ -849,10 +843,7 @@ func generateGroupMessage(id string, foundItems map[string][]string, messageText
return nil
}
recordData = silk.EncoderSilk(recordData)
mylog.Errorf("音频转码ing")
if err != nil {
return nil
}
mylog.Printf("音频转码ing")
}
// 转换为base64
base64Encoded := base64.StdEncoding.EncodeToString(recordData)
Expand Down Expand Up @@ -899,7 +890,7 @@ func generateGroupMessage(id string, foundItems map[string][]string, messageText
}
}
// 将解码的图片数据转换回base64格式并上传
imageURL, err := images.UploadBase64ImageToServer(base64.StdEncoding.EncodeToString(compressedData))
imageURL, _, _, _, err := images.UploadBase64ImageToServer(id, base64.StdEncoding.EncodeToString(compressedData), groupid, apiv2)
if err != nil {
mylog.Printf("failed to upload base64 image: %v", err)
return nil
Expand Down
6 changes: 3 additions & 3 deletions handlers/send_guild_channel_forum.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func HandleSendGuildChannelForum(client callapi.Client, api openapi.OpenAPI, api

mylog.Println("频道发帖子messageText:", messageText)

Forum, err := GenerateForumMessage(foundItems, messageText)
Forum, err := GenerateForumMessage(foundItems, messageText, apiv2)
if err != nil {
mylog.Printf("组合帖子信息失败: %v", err)
}
Expand Down Expand Up @@ -152,7 +152,7 @@ func HandleSendGuildChannelForum(client callapi.Client, api openapi.OpenAPI, api
// }

// GenerateForumMessage 生成帖子消息
func GenerateForumMessage(foundItems map[string][]string, messageText string) (*dto.FourmToCreate, error) {
func GenerateForumMessage(foundItems map[string][]string, messageText string, apiv2 openapi.OpenAPI) (*dto.FourmToCreate, error) {
var forum dto.FourmToCreate

// 设置标题
Expand Down Expand Up @@ -231,7 +231,7 @@ func GenerateForumMessage(foundItems map[string][]string, messageText string) (*
mylog.Printf("Error compressing image: %v", err)
return nil, fmt.Errorf("error compressing image: %v", err)
}
imageURL, err := images.UploadBase64ImageToServer(base64.StdEncoding.EncodeToString(compressedData))
imageURL, _, _, _, err := images.UploadBase64ImageToServer("", base64.StdEncoding.EncodeToString(compressedData), "", apiv2)
if err != nil {
mylog.Printf("failed to upload base64 image: %v", err)
return nil, fmt.Errorf("failed to upload base64 image: %v", err)
Expand Down
8 changes: 4 additions & 4 deletions handlers/send_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ func HandleSendMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openapi.Ope
var err error

if message.Params.GroupID != "" {
idInt64, _ = ConvertToInt64(message.Params.GroupID)
idInt642, _ = ConvertToInt64(message.Params.UserID)
idInt64, err = ConvertToInt64(message.Params.GroupID)
idInt642, err = ConvertToInt64(message.Params.UserID)
} else if message.Params.UserID != "" {
idInt64, _ = ConvertToInt64(message.Params.UserID)
idInt642, _ = ConvertToInt64(message.Params.GroupID)
idInt64, err = ConvertToInt64(message.Params.UserID)
idInt642, err = ConvertToInt64(message.Params.GroupID)
}

//设置递归 对直接向gsk发送action时有效果
Expand Down
8 changes: 4 additions & 4 deletions handlers/send_private_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func HandleSendPrivateMsg(client callapi.Client, api openapi.OpenAPI, apiv2 open
singleItem[imageType] = []string{imageUrl}
msgseq := echo.GetMappingSeq(messageID)
echo.AddMappingSeq(messageID, msgseq+1)
groupReply := generateGroupMessage(messageID, singleItem, "", msgseq+1)
groupReply := generateGroupMessage(messageID, singleItem, "", msgseq+1, apiv2, message.Params.GroupID.(string))
// 进行类型断言
richMediaMessage, ok := groupReply.(*dto.RichMediaMessage)
if !ok {
Expand Down Expand Up @@ -192,7 +192,7 @@ func HandleSendPrivateMsg(client callapi.Client, api openapi.OpenAPI, apiv2 open
if messageText != "" {
msgseq := echo.GetMappingSeq(messageID)
echo.AddMappingSeq(messageID, msgseq+1)
groupReply := generateGroupMessage(messageID, nil, messageText, msgseq+1)
groupReply := generateGroupMessage(messageID, nil, messageText, msgseq+1, apiv2, message.Params.GroupID.(string))

// 进行类型断言
groupMessage, ok := groupReply.(*dto.MessageToCreate)
Expand Down Expand Up @@ -220,7 +220,7 @@ func HandleSendPrivateMsg(client callapi.Client, api openapi.OpenAPI, apiv2 open
//mylog.Println("singleItem:", singleItem)
msgseq := echo.GetMappingSeq(messageID)
echo.AddMappingSeq(messageID, msgseq+1)
groupReply := generateGroupMessage(messageID, singleItem, "", msgseq+1)
groupReply := generateGroupMessage(messageID, singleItem, "", msgseq+1, apiv2, message.Params.GroupID.(string))
// 进行类型断言
richMediaMessage, ok := groupReply.(*dto.RichMediaMessage)
if !ok {
Expand All @@ -233,7 +233,7 @@ func HandleSendPrivateMsg(client callapi.Client, api openapi.OpenAPI, apiv2 open
if config.GetSendError() { //把报错当作文本发出去
msgseq := echo.GetMappingSeq(messageID)
echo.AddMappingSeq(messageID, msgseq+1)
groupReply := generateGroupMessage(messageID, nil, err.Error(), msgseq+1)
groupReply := generateGroupMessage(messageID, nil, err.Error(), msgseq+1, apiv2, message.Params.GroupID.(string))
// 进行类型断言
groupMessage, ok := groupReply.(*dto.MessageToCreate)
if !ok {
Expand Down
Loading

0 comments on commit c928854

Please sign in to comment.