fix: 更新喜报和悲报的帮助信息,支持换行或多消息发送;修正图片文件路径的构建方式,使用动态路径替代静态路径

This commit is contained in:
lixiangwuxian 2025-03-18 19:20:57 +08:00
parent c0764036ab
commit c6fbedc859
2 changed files with 6 additions and 4 deletions

View File

@ -15,9 +15,9 @@ import (
func init() { func init() {
handler.RegisterHandler("喜报", xiBao, constants.LEVEL_USER) handler.RegisterHandler("喜报", xiBao, constants.LEVEL_USER)
handler.RegisterHelpInform("喜报 [内容]", "喜报/悲报", "生成喜报图片,支持换行") handler.RegisterHelpInform("喜报 [内容]", "喜报/悲报", "生成喜报图片,支持换行或多消息发送")
handler.RegisterHandler("悲报", beiBao, constants.LEVEL_USER) handler.RegisterHandler("悲报", beiBao, constants.LEVEL_USER)
handler.RegisterHelpInform("悲报 [内容]", "喜报/悲报", "生成悲报图片,支持换行") handler.RegisterHelpInform("悲报 [内容]", "喜报/悲报", "生成悲报图片,支持换行或多消息发送")
} }
func xiBao(msg model.Message) (reply model.Reply) { func xiBao(msg model.Message) (reply model.Reply) {
@ -37,7 +37,7 @@ func xiBao(msg model.Message) (reply model.Reply) {
imageMsg := message.ImageMessage{ imageMsg := message.ImageMessage{
Type: "image", Type: "image",
Data: message.ImageMessageData{ Data: message.ImageMessageData{
File: "file:///tmp/qqbot/" + fileName + ".png", File: "file://" + filePath,
}, },
} }
return model.Reply{ return model.Reply{
@ -55,7 +55,7 @@ func xiBaoTemp(msg model.Message) (reply model.Reply, isTrigger bool) {
imageMsg := message.ImageMessage{ imageMsg := message.ImageMessage{
Type: "image", Type: "image",
Data: message.ImageMessageData{ Data: message.ImageMessageData{
File: "file:///tmp/qqbot/" + fileName + ".png", File: "file://" + filePath,
}, },
} }
return model.Reply{ return model.Reply{

View File

@ -3,6 +3,7 @@ package message
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"log"
"net/url" "net/url"
"regexp" "regexp"
"strconv" "strconv"
@ -48,6 +49,7 @@ func (msg *ImageMessage) ToCQString() string {
} }
func (msg *ImageMessage) ParseMessage(data string) error { func (msg *ImageMessage) ParseMessage(data string) error {
log.Println("ParseMessage", data)
// 使用正则表达式提取各个字段 // 使用正则表达式提取各个字段
re := regexp.MustCompile(`\[CQ:image,file=(.*?),sub_type=(.*?),file_id=(.*?),url=(.*?),file_size=(\d+),file_unique=(.*?)\]`) re := regexp.MustCompile(`\[CQ:image,file=(.*?),sub_type=(.*?),file_id=(.*?),url=(.*?),file_size=(\d+),file_unique=(.*?)\]`)
matches := re.FindStringSubmatch(data) matches := re.FindStringSubmatch(data)