Skip to content

Commit

Permalink
Beta456 (#456)
Browse files Browse the repository at this point in the history
* beta447

* beta448

* beta449

* beta450

* beta451

* beta452

* beta453

* beta454

* beta455

* btea455

* beta456
  • Loading branch information
Hoshinonyaruko authored Jul 9, 2024
1 parent a417243 commit b7ed658
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Processor/ProcessGuildATMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
74 changes: 72 additions & 2 deletions handlers/send_guild_channel_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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 中提取图片地址
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit b7ed658

Please sign in to comment.