From 2472a84f034de0515be88db7542c1cfb0e6785a0 Mon Sep 17 00:00:00 2001 From: cosmo Date: Tue, 6 Feb 2024 19:46:29 +0800 Subject: [PATCH 1/5] beta318 --- handlers/message_parser.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/handlers/message_parser.go b/handlers/message_parser.go index 4552fa2d..8dd45395 100644 --- a/handlers/message_parser.go +++ b/handlers/message_parser.go @@ -240,13 +240,13 @@ func parseMessageContent(paramsMessage callapi.ParamsContent, message callapi.Ac } else { localRecordPattern = regexp.MustCompile(`\[CQ:record,file=file://([^\]]+?)\]`) } - httpUrlImagePattern := regexp.MustCompile(`\[CQ:image,file=http://(.+)\]`) - httpsUrlImagePattern := regexp.MustCompile(`\[CQ:image,file=https://(.+)\]`) - base64ImagePattern := regexp.MustCompile(`\[CQ:image,file=base64://(.+)\]`) - base64RecordPattern := regexp.MustCompile(`\[CQ:record,file=base64://(.+)\]`) - httpUrlRecordPattern := regexp.MustCompile(`\[CQ:record,file=http://(.+)\]`) - httpsUrlRecordPattern := regexp.MustCompile(`\[CQ:record,file=https://(.+)\]`) - mdPattern := regexp.MustCompile(`\[CQ:markdown,data=base64://(.+)\]`) + httpUrlImagePattern := regexp.MustCompile(`\[CQ:image,file=http://(.+?)\]`) + httpsUrlImagePattern := regexp.MustCompile(`\[CQ:image,file=https://(.+?)\]`) + base64ImagePattern := regexp.MustCompile(`\[CQ:image,file=base64://(.+?)\]`) + base64RecordPattern := regexp.MustCompile(`\[CQ:record,file=base64://(.+?)\]`) + httpUrlRecordPattern := regexp.MustCompile(`\[CQ:record,file=http://(.+?)\]`) + httpsUrlRecordPattern := regexp.MustCompile(`\[CQ:record,file=https://(.+?)\]`) + mdPattern := regexp.MustCompile(`\[CQ:markdown,data=base64://(.+?)\]`) patterns := []struct { key string From d2b1df9d500de1e9330509e36aed1806a727d98f Mon Sep 17 00:00:00 2001 From: cosmo Date: Sun, 11 Feb 2024 16:34:20 +0800 Subject: [PATCH 2/5] beta319 --- handlers/message_parser.go | 169 +++++++++++++++++++++++++++++++++++++ handlers/send_group_msg.go | 28 +++++- 2 files changed, 196 insertions(+), 1 deletion(-) diff --git a/handlers/message_parser.go b/handlers/message_parser.go index 8dd45395..bfba8065 100644 --- a/handlers/message_parser.go +++ b/handlers/message_parser.go @@ -6,8 +6,10 @@ import ( "encoding/json" "errors" "fmt" + "io" "log" "net" + "net/http" "path/filepath" "regexp" "runtime" @@ -19,12 +21,14 @@ import ( "github.com/hoshinonyaruko/gensokyo/config" "github.com/hoshinonyaruko/gensokyo/echo" "github.com/hoshinonyaruko/gensokyo/idmap" + "github.com/hoshinonyaruko/gensokyo/images" "github.com/hoshinonyaruko/gensokyo/mylog" "github.com/hoshinonyaruko/gensokyo/url" "github.com/skip2/go-qrcode" "github.com/tencent-connect/botgo/dto" "github.com/tencent-connect/botgo/dto/keyboard" "github.com/tencent-connect/botgo/openapi" + "github.com/tidwall/gjson" "mvdan.cc/xurls" //xurls是一个从文本提取url的库 适用于多种场景 ) @@ -247,6 +251,7 @@ func parseMessageContent(paramsMessage callapi.ParamsContent, message callapi.Ac httpUrlRecordPattern := regexp.MustCompile(`\[CQ:record,file=http://(.+?)\]`) httpsUrlRecordPattern := regexp.MustCompile(`\[CQ:record,file=https://(.+?)\]`) mdPattern := regexp.MustCompile(`\[CQ:markdown,data=base64://(.+?)\]`) + qqMusicPattern := regexp.MustCompile(`\[CQ:music,type=qq,id=(\d+)\]`) patterns := []struct { key string @@ -261,6 +266,7 @@ func parseMessageContent(paramsMessage callapi.ParamsContent, message callapi.Ac {"url_record", httpUrlRecordPattern}, {"url_records", httpsUrlRecordPattern}, {"markdown", mdPattern}, + {"qqmusic", qqMusicPattern}, } foundItems := make(map[string][]string) @@ -1015,3 +1021,166 @@ func parseMDData(mdData []byte) (*dto.Markdown, *keyboard.MessageKeyboard, error return md, kb, nil } + +func parseQQMuiscMDData(musicid string) (*dto.Markdown, *keyboard.MessageKeyboard, error) { + info, err := QQMusicSongInfo(musicid) + if err != nil { + return nil, nil, err + } + if !info.Get("track_info").Exists() { + return nil, nil, errors.New("song not found") + } + albumMid := info.Get("track_info.album.mid").String() + 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() + + //专辑图片 + PictureUrl := "https://y.gtimg.cn/music/photo_new/T002R180x180M000" + albumMid + ".jpg" + //专辑文字 + musicContent := info.Get("track_info.name").Str + "\r" + content + // 处理 Markdown + var md *dto.Markdown + var CustomTemplateID string + //组合 mdParams + var mdParams []*dto.MarkdownParams + CustomTemplateID = config.GetCustomTemplateID() + if CustomTemplateID != "" { + if PictureUrl != "" { + height, width, err := images.GetImageDimensions(PictureUrl) + if err != nil { + mylog.Printf("获取图片宽高出错") + } + imgDesc := fmt.Sprintf("图片 #%dpx #%dpx", width, height) + // 创建 MarkdownParams 的实例 + mdParams = []*dto.MarkdownParams{ + {Key: "img_dec", Values: []string{imgDesc}}, + {Key: "img_url", Values: []string{PictureUrl}}, + {Key: "text_end", Values: []string{"\r" + musicContent}}, + } + } else { + mdParams = []*dto.MarkdownParams{ + {Key: "text_end", Values: []string{"\r" + musicContent}}, + } + } + } + // 组合模板 Markdown + md = &dto.Markdown{ + CustomTemplateID: CustomTemplateID, + Params: mdParams, + } + // 使用gjson获取musicUrl + musicUrl := gjson.Get(pinfo, "url_mid.data.midurlinfo.0.purl").String() + // 处理 Keyboard + kb := createMusicKeyboard(jumpURL, musicUrl) + + return md, kb, nil +} + +// QQMusicSongInfo 通过给定id在QQ音乐上查找曲目信息 +func QQMusicSongInfo(id string) (gjson.Result, error) { + d, err := FetchSongDetail(id) + if err != nil { + return gjson.Result{}, err + } + return gjson.Get(d, "songinfo.data"), nil +} + +func createMusicKeyboard(jumpURL string, musicURL string) *keyboard.MessageKeyboard { + // 初始化自定义键盘 + customKeyboard := &keyboard.CustomKeyboard{} + currentRow := &keyboard.Row{} // 创建一个新行 + + // 创建歌曲页面跳转按钮 + songPageButton := &keyboard.Button{ + RenderData: &keyboard.RenderData{ + Label: "立刻播放", + VisitedLabel: "已播放", + Style: 1, // 蓝色边缘 + }, + Action: &keyboard.Action{ + Type: 0, // 链接类型 + Permission: &keyboard.Permission{Type: 2}, // 所有人可操作 + Data: jumpURL, + UnsupportTips: "请升级新版手机QQ", + }, + } + + //这个链接是音乐直链 musicURL 还没有适合能力调用 + + // // 创建立即播放按钮 + // playNowButton := &keyboard.Button{ + // RenderData: &keyboard.RenderData{ + // Label: "立刻播放", + // VisitedLabel: "立刻播放", + // Style: 1, // 蓝色边缘 + // }, + // Action: &keyboard.Action{ + // Type: 0, // 链接类型 + // Permission: &keyboard.Permission{Type: 2}, // 所有人可操作 + // Data: musicURL, + // UnsupportTips: "请升级新版手机QQ", + // }, + // } + + // 将按钮添加到当前行 + // currentRow.Buttons = append(currentRow.Buttons, songPageButton, playNowButton) + currentRow.Buttons = append(currentRow.Buttons, songPageButton) + + // 将当前行添加到自定义键盘 + customKeyboard.Rows = append(customKeyboard.Rows, currentRow) + + // 创建 MessageKeyboard 并设置其 Content + kb := &keyboard.MessageKeyboard{ + Content: customKeyboard, + } + + return kb +} + +// FetchTrackInfo 用于根据trackMid获取QQ音乐的track信息 +func FetchTrackInfo(trackMid string) (string, error) { + urlTemplate := "https://u.y.qq.com/cgi-bin/musicu.fcg?g_tk=2034008533&uin=0&format=json&data={\"comm\":{\"ct\":23,\"cv\":0},\"url_mid\":{\"module\":\"vkey.GetVkeyServer\",\"method\":\"CgiGetVkey\",\"param\":{\"guid\":\"4311206557\",\"songmid\":[\"%s\"],\"songtype\":[0],\"uin\":\"0\",\"loginflag\":1,\"platform\":\"23\"}}}&_=1599039471576" + url := fmt.Sprintf(urlTemplate, trackMid) + + // 发送HTTP GET请求 + resp, err := http.Get(url) + if err != nil { + return "", fmt.Errorf("error making request: %v", err) + } + defer resp.Body.Close() + + // 读取并解析响应体 + body, err := io.ReadAll(resp.Body) + if err != nil { + return "", fmt.Errorf("error reading response body: %v", err) + } + + var result interface{} // 使用interface{}来接收任意的JSON对象 + if err := json.Unmarshal(body, &result); err != nil { + return "", fmt.Errorf("error parsing JSON: %v", err) + } + + return string(body), nil +} + +// FetchSongDetail 发送请求到QQ音乐API并获取歌曲详情 +func FetchSongDetail(songID string) (string, error) { + // 构建请求URL + url := fmt.Sprintf("https://u.y.qq.com/cgi-bin/musicu.fcg?format=json&inCharset=utf8&outCharset=utf-8¬ice=0&platform=yqq.json&needNewCode=0&data={\"comm\":{\"ct\":24,\"cv\":0},\"songinfo\":{\"method\":\"get_song_detail_yqq\",\"param\":{\"song_type\":0,\"song_mid\":\"\",\"song_id\":%s},\"module\":\"music.pf_song_detail_svr\"}}", songID) + + // 发送GET请求 + resp, err := http.Get(url) + if err != nil { + return "", fmt.Errorf("error making request: %v", err) + } + defer resp.Body.Close() + + // 读取响应体 + body, err := io.ReadAll(resp.Body) + if err != nil { + return "", fmt.Errorf("error reading response body: %v", err) + } + + return string(body), nil +} diff --git a/handlers/send_group_msg.go b/handlers/send_group_msg.go index f6af9e52..113c0caf 100644 --- a/handlers/send_group_msg.go +++ b/handlers/send_group_msg.go @@ -323,7 +323,7 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap richMediaMessage, ok := groupReply.(*dto.RichMediaMessage) if !ok { mylog.Printf("Error: Expected RichMediaMessage type for key %s.", key) - if key == "markdown" { + if key == "markdown" || key == "qqmusic" { // 进行类型断言 groupMessage, ok := groupReply.(*dto.MessageToCreate) if !ok { @@ -914,6 +914,32 @@ func generateGroupMessage(id string, foundItems map[string][]string, messageText Keyboard: keyboard, MsgType: 2, } + } else if qqmusic, ok := foundItems["qqmusic"]; ok && len(qqmusic) > 0 { + // 转换qq音乐id到一个md + music_id := qqmusic[0] + markdown, keyboard, err := parseQQMuiscMDData(music_id) + if err != nil { + mylog.Printf("failed to parseMDData: %v", err) + return nil + } + if markdown != nil { + return &dto.MessageToCreate{ + Content: "markdown", + MsgID: id, + MsgSeq: msgseq, + Markdown: markdown, + Keyboard: keyboard, + MsgType: 2, + } + } else { + return &dto.MessageToCreate{ + Content: "markdown", + MsgID: id, + MsgSeq: msgseq, + Keyboard: keyboard, + MsgType: 2, + } + } } else { // 返回文本信息 return &dto.MessageToCreate{ From 4773df20f2fcb742734d1a0ad1965d1d6f321526 Mon Sep 17 00:00:00 2001 From: cosmo Date: Mon, 12 Feb 2024 17:44:46 +0800 Subject: [PATCH 3/5] beta320 --- config/config.go | 13 +++++++++++++ handlers/message_parser.go | 20 +++++++++++++++++-- handlers/send_group_msg.go | 38 ++++++++++++++++++------------------- template/config_template.go | 1 + 4 files changed, 50 insertions(+), 22 deletions(-) diff --git a/config/config.go b/config/config.go index dfeb04b6..8b6f6128 100644 --- a/config/config.go +++ b/config/config.go @@ -140,6 +140,7 @@ type Settings struct { LinkBots []string `yaml:"link_bots"` LinkText string `yaml:"link_text"` LinkPic string `yaml:"link_pic"` + MusicPrefix string `yaml:"music_prefix"` } // LoadConfig 从文件中加载配置并初始化单例配置 @@ -1763,3 +1764,15 @@ func GetLinkPic() string { } return instance.Settings.LinkPic } + +// 获取 GetMusicPrefix +func GetMusicPrefix() string { + mu.Lock() + defer mu.Unlock() + + if instance == nil { + mylog.Println("Warning: instance is nil when trying to get MusicPrefix.") + return "" + } + return instance.Settings.MusicPrefix +} diff --git a/handlers/message_parser.go b/handlers/message_parser.go index bfba8065..19c02690 100644 --- a/handlers/message_parser.go +++ b/handlers/message_parser.go @@ -1123,9 +1123,25 @@ func createMusicKeyboard(jumpURL string, musicURL string) *keyboard.MessageKeybo // }, // } + //自传播按钮 + musicPrefix := config.GetMusicPrefix() + playNowButton := &keyboard.Button{ + RenderData: &keyboard.RenderData{ + Label: "我也要点歌", + VisitedLabel: "再次点歌", + Style: 1, // 蓝色边缘 + }, + Action: &keyboard.Action{ + Type: 2, // 链接类型 + Permission: &keyboard.Permission{Type: 2}, // 所有人可操作 + Data: musicPrefix + " ", + UnsupportTips: "请升级新版手机QQ", + }, + } + // 将按钮添加到当前行 - // currentRow.Buttons = append(currentRow.Buttons, songPageButton, playNowButton) - currentRow.Buttons = append(currentRow.Buttons, songPageButton) + currentRow.Buttons = append(currentRow.Buttons, songPageButton, playNowButton) + //currentRow.Buttons = append(currentRow.Buttons, songPageButton) // 将当前行添加到自定义键盘 customKeyboard.Rows = append(customKeyboard.Rows, currentRow) diff --git a/handlers/send_group_msg.go b/handlers/send_group_msg.go index 113c0caf..b48077bc 100644 --- a/handlers/send_group_msg.go +++ b/handlers/send_group_msg.go @@ -51,7 +51,6 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap mylog.Printf("send_group_msg获取到信息类型:%v", msgType) var idInt64 int64 var err error - var ret *dto.GroupMessageResponse var retmsg string if message.Params.GroupID != "" { @@ -149,7 +148,7 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap if SSM { //mylog.Printf("正在使用Msgid:%v 补发之前失败的主动信息,请注意AtoP不要设置超过3,否则可能会影响正常信息发送", messageID) //mylog.Printf("originalGroupID:%v ", originalGroupID) - SendStackMessages(apiv2, messageID, originalGroupID) + SendStackMessages(apiv2, messageID, message.Params.GroupID.(string)) } mylog.Println("群组发信息messageText:", messageText) //mylog.Println("foundItems:", foundItems) @@ -260,12 +259,12 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap } // 发送组合消息 - ret, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage) + _, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage) if err != nil { mylog.Printf("发送组合消息失败: %v", err) return "", nil // 或其他错误处理 } - if ret != nil && ret.Message.Ret == 22009 { + if err != nil && strings.Contains(err.Error(), `"code":22009`) { mylog.Printf("信息发送失败,加入到队列中,下次被动信息进行发送") var pair echo.MessageGroupPair pair.Group = message.Params.GroupID.(string) @@ -295,11 +294,11 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap groupMessage.Timestamp = time.Now().Unix() // 设置时间戳 //重新为err赋值 - ret, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage) + _, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage) if err != nil { mylog.Printf("发送文本群组信息失败: %v", err) } - if ret != nil && ret.Message.Ret == 22009 { + if err != nil && strings.Contains(err.Error(), `"code":22009`) { mylog.Printf("信息发送失败,加入到队列中,下次被动信息进行发送") var pair echo.MessageGroupPair pair.Group = message.Params.GroupID.(string) @@ -331,11 +330,11 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap return "", nil // 或其他错误处理 } //重新为err赋值 - ret, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage) + _, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage) if err != nil { mylog.Printf("发送md信息失败: %v", err) } - if ret != nil && ret.Message.Ret == 22009 { + if err != nil && strings.Contains(err.Error(), `"code":22009`) { mylog.Printf("信息发送失败,加入到队列中,下次被动信息进行发送") var pair echo.MessageGroupPair pair.Group = message.Params.GroupID.(string) @@ -362,11 +361,11 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap } groupMessage.Timestamp = time.Now().Unix() // 设置时间戳 //重新为err赋值 - ret, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage) + _, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage) if err != nil { mylog.Printf("发送文本报错信息失败: %v", err) } - if ret != nil && ret.Message.Ret == 22009 { + if err != nil && strings.Contains(err.Error(), `"code":22009`) { mylog.Printf("信息发送失败,加入到队列中,下次被动信息进行发送") var pair echo.MessageGroupPair pair.Group = message.Params.GroupID.(string) @@ -390,11 +389,11 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap } groupMessage.Timestamp = time.Now().Unix() // 设置时间戳 //重新为err赋值 - ret, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage) + _, err = apiv2.PostGroupMessage(context.TODO(), message.Params.GroupID.(string), groupMessage) if err != nil { mylog.Printf("发送图片失败: %v", err) } - if ret != nil && ret.Message.Ret == 22009 { + if err != nil && strings.Contains(err.Error(), `"code":22009`) { mylog.Printf("信息发送失败,加入到队列中,下次被动信息进行发送") var pair echo.MessageGroupPair pair.Group = message.Params.GroupID.(string) @@ -1053,20 +1052,19 @@ func uploadMedia(ctx context.Context, groupID string, richMediaMessage *dto.Rich } // 发送栈中的消息 -func SendStackMessages(apiv2 openapi.OpenAPI, messageid string, originalGroupID string) { +func SendStackMessages(apiv2 openapi.OpenAPI, messageid string, GroupID string) { count := config.GetAtoPCount() mylog.Printf("取出数量: %v", count) pairs := echo.PopGlobalStackMulti(count) for i, pair := range pairs { - mylog.Printf("%v: %v", pair.Group, originalGroupID) - if pair.Group == originalGroupID { + mylog.Printf("%v: %v", pair.Group, GroupID) + if pair.Group == GroupID { // 发送消息 - messageID := pair.GroupMessage.MsgID - msgseq := echo.GetMappingSeq(messageID) - echo.AddMappingSeq(messageID, msgseq+1) + msgseq := echo.GetMappingSeq(messageid) + echo.AddMappingSeq(messageid, msgseq+1) pair.GroupMessage.MsgSeq = msgseq + 1 pair.GroupMessage.MsgID = messageid - ret, err := apiv2.PostGroupMessage(context.TODO(), pair.Group, pair.GroupMessage) + _, err := apiv2.PostGroupMessage(context.TODO(), pair.Group, pair.GroupMessage) if err != nil { mylog.Printf("发送组合消息失败: %v", err) continue @@ -1075,7 +1073,7 @@ func SendStackMessages(apiv2 openapi.OpenAPI, messageid string, originalGroupID } // 检查错误码 - if ret != nil && ret.Message.Ret == 22009 { + if err != nil && strings.Contains(err.Error(), `"code":22009`) { mylog.Printf("信息再次发送失败,加入到队列中,下次被动信息进行发送") echo.PushGlobalStack(pair) } diff --git a/template/config_template.go b/template/config_template.go index d41bbde2..9c07b5c5 100644 --- a/template/config_template.go +++ b/template/config_template.go @@ -145,6 +145,7 @@ settings: me_prefix : "/me" #需设置 #增强配置项 master_id 可触发 unlock_prefix : "/unlock" #频道私信卡住了? gsk可以帮到你 在任意子频道发送unlock 你会收到来自机器人的频道私信 link_prefix : "/link" #友情链接配置 配置custom_template_id后可用(https://www.yuque.com/km57bt/hlhnxg/tzbr84y59dbz6pib) + music_prefix : "点歌" #[CQ:music,type=qq,id=123] 在消息文本组合qq音乐歌曲id,可以发送点歌,这是歌曲按钮第二个按钮的填充内容,应为你的机器人点歌插件的指令. link_bots : ["",""] #发送友情链接时 下方按钮携带的机器人 格式 "appid-qq-name","appid-qq-name" link_text : "" #友情链接文本 不可为空! link_pic : "" #友情链接图片 可为空 需url图片 可带端口 不填可能会有显示错误 From 34727726cb52783cc04a7a7130a07288c98b1d50 Mon Sep 17 00:00:00 2001 From: cosmo Date: Tue, 13 Feb 2024 11:36:00 +0800 Subject: [PATCH 4/5] beata321 --- config/config.go | 13 +++++++++++++ handlers/send_group_msg.go | 5 ++--- httpapi/httpapi.go | 27 +++++++++++++++++++++++++++ main.go | 4 +++- template/config_template.go | 1 + 5 files changed, 46 insertions(+), 4 deletions(-) diff --git a/config/config.go b/config/config.go index 8b6f6128..c57764b0 100644 --- a/config/config.go +++ b/config/config.go @@ -141,6 +141,7 @@ type Settings struct { LinkText string `yaml:"link_text"` LinkPic string `yaml:"link_pic"` MusicPrefix string `yaml:"music_prefix"` + DisableWebui bool `yaml:"disable_webui"` } // LoadConfig 从文件中加载配置并初始化单例配置 @@ -1776,3 +1777,15 @@ func GetMusicPrefix() string { } return instance.Settings.MusicPrefix } + +// 获取 GetDisableWebui 的值 +func GetDisableWebui() bool { + mu.Lock() + defer mu.Unlock() + + if instance == nil { + mylog.Println("Warning: instance is nil when trying to GetDisableWebui value.") + return false + } + return instance.Settings.DisableWebui +} diff --git a/handlers/send_group_msg.go b/handlers/send_group_msg.go index b48077bc..0d4d3e0d 100644 --- a/handlers/send_group_msg.go +++ b/handlers/send_group_msg.go @@ -1057,21 +1057,20 @@ func SendStackMessages(apiv2 openapi.OpenAPI, messageid string, GroupID string) mylog.Printf("取出数量: %v", count) pairs := echo.PopGlobalStackMulti(count) for i, pair := range pairs { - mylog.Printf("%v: %v", pair.Group, GroupID) + mylog.Printf("发送栈中的消息匹配 %v: %v", pair.Group, GroupID) if pair.Group == GroupID { // 发送消息 msgseq := echo.GetMappingSeq(messageid) echo.AddMappingSeq(messageid, msgseq+1) pair.GroupMessage.MsgSeq = msgseq + 1 pair.GroupMessage.MsgID = messageid + mylog.Printf("发送栈中的消息 使用MsgSeq[%v]使用MsgID[%v]", pair.GroupMessage.MsgSeq, pair.GroupMessage.MsgID) _, err := apiv2.PostGroupMessage(context.TODO(), pair.Group, pair.GroupMessage) if err != nil { mylog.Printf("发送组合消息失败: %v", err) - continue } else { echo.RemoveFromGlobalStack(i) } - // 检查错误码 if err != nil && strings.Contains(err.Error(), `"code":22009`) { mylog.Printf("信息再次发送失败,加入到队列中,下次被动信息进行发送") diff --git a/httpapi/httpapi.go b/httpapi/httpapi.go index 12960a39..8f2656f0 100644 --- a/httpapi/httpapi.go +++ b/httpapi/httpapi.go @@ -26,6 +26,10 @@ func CombinedMiddleware(api openapi.OpenAPI, apiV2 openapi.OpenAPI) gin.HandlerF handleSendGuildChannelMessage(c, api, apiV2) return } + if c.Request.URL.Path == "/get_group_list" { + handleGetGroupList(c, api, apiV2) + return + } // 调用c.Next()以继续处理请求链 c.Next() @@ -197,3 +201,26 @@ func (c *HttpAPIClient) SendMessage(message map[string]interface{}) error { // 返回nil占位符 return nil } + +// handleGetGroupList 处理获取群列表 +func handleGetGroupList(c *gin.Context, api openapi.OpenAPI, apiV2 openapi.OpenAPI) { + var retmsg string + + // 使用解析后的参数处理请求 + client := &HttpAPIClient{} + // 创建 ActionMessage 实例 + message := callapi.ActionMessage{ + Action: "get_group_list", + } + + // 调用处理函数 + retmsg, err := handlers.GetGroupList(client, api, apiV2, message) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) + return + } + + // 返回处理结果 + c.Header("Content-Type", "application/json") + c.String(http.StatusOK, retmsg) +} diff --git a/main.go b/main.go index b2ca9fdd..26776507 100644 --- a/main.go +++ b/main.go @@ -298,7 +298,7 @@ func main() { r.POST("/uploadpic", server.UploadBase64ImageHandler(rateLimiter)) r.POST("/uploadrecord", server.UploadBase64RecordHandler(rateLimiter)) r.Static("/channel_temp", "./channel_temp") - if config.GetFrpPort() == "0" { + if config.GetFrpPort() == "0" && !config.GetDisableWebui() { //webui和它的api webuiGroup := r.Group("/webui") { @@ -308,6 +308,8 @@ func main() { webuiGroup.DELETE("/*filepath", webui.CombinedMiddleware(api, apiV2)) webuiGroup.PATCH("/*filepath", webui.CombinedMiddleware(api, apiV2)) } + } else { + mylog.Println("Either FRP port is set to '0' or WebUI is disabled.") } //正向http api http_api_address := config.GetHttpAddress() diff --git a/template/config_template.go b/template/config_template.go index 9c07b5c5..fb921d46 100644 --- a/template/config_template.go +++ b/template/config_template.go @@ -126,6 +126,7 @@ settings: url_pic_transfer : false #把图片url(任意来源图链)变成你备案的白名单url 需要较高上下行+ssl+自备案域名+设置白名单域名(暂时不需要) idmap_pro : false #需开启hash_id配合,高级id转换增强,可以多个真实值bind到同一个虚拟值,对于每个用户,每个群\私聊\判断私聊\频道,都会产生新的虚拟值,但可以多次bind,bind到同一个数字.数据库负担会变大. send_delay : 300 #单位 毫秒 默认300ms 可以视情况减少到100或者50 + disable_webui: false #禁用webui title : "Gensokyo © 2023 - Hoshinonyaruko" #程序的标题 如果多个机器人 可根据标题区分 custom_bot_name : "Gensokyo全域机器人" #自定义机器人名字,会在api调用中返回,默认Gensokyo全域机器人 From 123ca2f4188b59e5fcb0486b6c7740701abda7c0 Mon Sep 17 00:00:00 2001 From: cosmo Date: Wed, 14 Feb 2024 19:45:03 +0800 Subject: [PATCH 5/5] beta322 --- handlers/message_parser.go | 4 ++++ handlers/send_group_msg.go | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/handlers/message_parser.go b/handlers/message_parser.go index 19c02690..160526af 100644 --- a/handlers/message_parser.go +++ b/handlers/message_parser.go @@ -250,6 +250,8 @@ func parseMessageContent(paramsMessage callapi.ParamsContent, message callapi.Ac base64RecordPattern := regexp.MustCompile(`\[CQ:record,file=base64://(.+?)\]`) httpUrlRecordPattern := regexp.MustCompile(`\[CQ:record,file=http://(.+?)\]`) httpsUrlRecordPattern := regexp.MustCompile(`\[CQ:record,file=https://(.+?)\]`) + httpUrlVideoPattern := regexp.MustCompile(`\[CQ:video,file=http://(.+?)\]`) + httpsUrlVideoPattern := regexp.MustCompile(`\[CQ:video,file=https://(.+?)\]`) mdPattern := regexp.MustCompile(`\[CQ:markdown,data=base64://(.+?)\]`) qqMusicPattern := regexp.MustCompile(`\[CQ:music,type=qq,id=(\d+)\]`) @@ -267,6 +269,8 @@ func parseMessageContent(paramsMessage callapi.ParamsContent, message callapi.Ac {"url_records", httpsUrlRecordPattern}, {"markdown", mdPattern}, {"qqmusic", qqMusicPattern}, + {"url_video", httpUrlVideoPattern}, + {"url_videos", httpsUrlVideoPattern}, } foundItems := make(map[string][]string) diff --git a/handlers/send_group_msg.go b/handlers/send_group_msg.go index 0d4d3e0d..8f22ed32 100644 --- a/handlers/send_group_msg.go +++ b/handlers/send_group_msg.go @@ -939,6 +939,26 @@ func generateGroupMessage(id string, foundItems map[string][]string, messageText MsgType: 2, } } + } else if videoURL, ok := foundItems["url_video"]; ok && len(videoURL) > 0 { + newvideolink := "http://" + videoURL[0] + // 发链接视频 http + return &dto.RichMediaMessage{ + EventID: id, + FileType: 2, // 2代表视频 + URL: newvideolink, // 新图片链接 + Content: "", // 这个字段文档没有了 + SrvSendMsg: false, + } + } else if videoURLs, ok := foundItems["url_videos"]; ok && len(videoURLs) > 0 { + newvideolink := "https://" + videoURLs[0] + // 发链接视频 https + return &dto.RichMediaMessage{ + EventID: id, + FileType: 2, // 2代表视频 + URL: newvideolink, // 新图片链接 + Content: "", // 这个字段文档没有了 + SrvSendMsg: false, + } } else { // 返回文本信息 return &dto.MessageToCreate{