From b7ed658f5f6d4137b899ec013fefbf86cd8b7586 Mon Sep 17 00:00:00 2001 From: SanaeFox <36219542+Hoshinonyaruko@users.noreply.github.com> Date: Tue, 9 Jul 2024 18:16:08 +0800 Subject: [PATCH] Beta456 (#456) * beta447 * beta448 * beta449 * beta450 * beta451 * beta452 * beta453 * beta454 * beta455 * btea455 * beta456 --- Processor/ProcessGuildATMessage.go | 2 + handlers/send_guild_channel_msg.go | 74 +++++++++++++++++++++++++++++- 2 files changed, 74 insertions(+), 2 deletions(-) diff --git a/Processor/ProcessGuildATMessage.go b/Processor/ProcessGuildATMessage.go index 82163320..266923fb 100644 --- a/Processor/ProcessGuildATMessage.go +++ b/Processor/ProcessGuildATMessage.go @@ -296,6 +296,8 @@ func (p *Processors) ProcessGuildATMessage(data *dto.WSATMessageData) error { echo.AddMsgType(AppIDString, ChannelID64, "guild") //懒message_id池 echo.AddLazyMessageId(strconv.FormatInt(ChannelID64, 10), data.ID, time.Now()) + //测试 + echo.AddLazyMessageId(data.ChannelID, data.ID, time.Now()) //懒message_id池 //echo.AddLazyMessageId(strconv.FormatInt(userid64, 10), data.ID, time.Now()) //echo.AddLazyMessageIdv2(strconv.FormatInt(ChannelID64, 10), strconv.FormatInt(userid64, 10), data.ID, time.Now()) diff --git a/handlers/send_guild_channel_msg.go b/handlers/send_guild_channel_msg.go index 5975b293..4f475595 100644 --- a/handlers/send_guild_channel_msg.go +++ b/handlers/send_guild_channel_msg.go @@ -18,6 +18,7 @@ import ( "github.com/hoshinonyaruko/gensokyo/echo" "github.com/tencent-connect/botgo/dto" + "github.com/tencent-connect/botgo/dto/keyboard" "github.com/tencent-connect/botgo/openapi" ) @@ -163,10 +164,33 @@ func HandleSendGuildChannelMsg(client callapi.Client, api openapi.OpenAPI, apiv2 MsgType: 0, } newMessage.Timestamp = time.Now().Unix() // 设置时间戳 + var transmd bool + var md *dto.Markdown + var kb *keyboard.MessageKeyboard + //判断是否需要自动转换md + if config.GetTwoWayEcho() { + // 初始化 RichMediaMessage 结构体指针 + var richMediaMessage *dto.RichMediaMessage = &dto.RichMediaMessage{} + richMediaMessage.Content = messageText + richMediaMessage.URL = Reply.Image + md, kb, transmd = auto_md(message, messageText, richMediaMessage) + } - if _, err = api.PostMessage(context.TODO(), channelID.(string), newMessage); err != nil { - mylog.Printf("发送图文混合信息失败: %v", err) + if transmd { + newMessage.Content = "" + newMessage.Image = "" + newMessage.Markdown = md + newMessage.Keyboard = kb + newMessage.MsgType = 2 //md信息 + if _, err = api.PostMessage(context.TODO(), channelID.(string), newMessage); err != nil { + mylog.Printf("发送图文混合信息失败: %v", err) + } + } else { + if _, err = api.PostMessage(context.TODO(), channelID.(string), newMessage); err != nil { + mylog.Printf("发送图文混合信息失败: %v", err) + } } + // 检查是否是 40003 错误 if err != nil && strings.Contains(err.Error(), `"code":40003`) && len(newMessage.Image) > 0 { // 从 newMessage.Image 中提取图片地址 @@ -439,6 +463,52 @@ func GenerateReplyMessage(id string, foundItems map[string][]string, messageText MsgType: 0, // Default type for text } isBase64 = true + } 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, false + } + if markdown != nil { + msgtocreate := &dto.MessageToCreate{ + MsgID: id, + MsgSeq: msgseq, + Markdown: markdown, + Keyboard: keyboard, + MsgType: 2, + } + return msgtocreate, false + } else { + msgtocreate := &dto.MessageToCreate{ + MsgID: id, + MsgSeq: msgseq, + Keyboard: keyboard, + MsgType: 2, + } + return msgtocreate, false + } + } else if mdContent, ok := foundItems["markdown"]; ok && len(mdContent) > 0 { + // 解码base64 markdown数据 + mdData, err := base64.StdEncoding.DecodeString(mdContent[0]) + if err != nil { + mylog.Printf("failed to decode base64 md: %v", err) + return nil, false + } + markdown, keyboard, err := parseMDData(mdData) + if err != nil { + mylog.Printf("failed to parseMDData: %v", err) + return nil, false + } + msgtocreate := &dto.MessageToCreate{ + MsgID: id, + MsgSeq: msgseq, + Markdown: markdown, + Keyboard: keyboard, + MsgType: 2, + } + return msgtocreate, false } else { // 发文本信息 reply = dto.MessageToCreate{