Skip to content

Commit

Permalink
fix: msg format
Browse files Browse the repository at this point in the history
  • Loading branch information
deanxv committed Feb 22, 2024
1 parent 39c5032 commit 7ba5b6a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions discord/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,20 +340,20 @@ func SendMessage(c *gin.Context, channelID, cozeBotId, message string) (*discord

//var sentMsg *discordgo.Message

content := fmt.Sprintf("%s <@%s>", message, cozeBotId)
content := fmt.Sprintf("%s \n <@%s>", message, cozeBotId)

if runeCount := len([]rune(content)); runeCount > 50000 {
common.LogError(ctx, fmt.Sprintf("prompt已超过限制,请分段发送 [%v] %s", runeCount, content))
return nil, fmt.Errorf("prompt已超过限制,请分段发送 [%v]", runeCount)
}

// 特殊处理
content = strings.ReplaceAll(content, "\\n", " \\n ")

for i, sendContent := range common.ReverseSegment(content, 2000) {
//sentMsg, err := Session.ChannelMessageSend(channelID, sendContent)
//sentMsgId := sentMsg.ID
// 4.0.0 版本下 用户端发送消息
sendContent = strings.ReplaceAll(sendContent, "\\n", " \n ")
sentMsgId, err := SendMsgByAuthorization(c, sendContent, channelID)
if err != nil {
common.LogError(ctx, fmt.Sprintf("error sending message: %s", err))
Expand Down
2 changes: 2 additions & 0 deletions discord/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import (
"io"
"net/http"
"net/url"
"strings"
)

// 用户端发送消息 注意 此为临时解决方案 后续会优化代码
func SendMsgByAuthorization(c *gin.Context, content, channelId string) (string, error) {
postUrl := "https://discord.com/api/v9/channels/%s/messages"
content = strings.Replace(content, `\u0026`, "&", -1)
// 构造请求体
requestBody, err := json.Marshal(map[string]interface{}{
"content": content,
Expand Down

0 comments on commit 7ba5b6a

Please sign in to comment.