refactor: centralize temporary file path generation and update file references

This commit is contained in:
lixiangwuxian 2025-02-22 18:40:26 +08:00
parent 388cfdf377
commit 38940fa07f
7 changed files with 25 additions and 14 deletions

View File

@ -158,7 +158,7 @@ func getMyRecentScore(msg model.Message) (reply model.Reply) {
func screenShotBL(msg model.Message) (reply model.Reply) {
return model.Reply{
ReplyMsg: "[CQ:image,file=file:///root/qqbot/tmp/" + beatleader.GetBLPicture(strconv.Itoa(int(msg.UserId))) + "]",
ReplyMsg: "[CQ:image,file=file:///root/qqbot/" + beatleader.GetBLPicture(strconv.Itoa(int(msg.UserId))) + "]",
ReferOriginMsg: true,
FromMsg: msg,
}

View File

@ -16,7 +16,8 @@ func getweb(msg model.Message) (reply model.Reply) {
}
url := msg.RawMsg[len("上网 "):]
url = formatURL(url)
if err := util.ScreenshotURL(url, "./tmp/getweb/url.png", 1620, 1960, 0, 0, 0, 0, ""); err != nil {
// if err := util.ScreenshotURL(url, "./tmp/getweb/url.png", 1620, 1960, 0, 0, 0, 0, ""); err != nil {
if err := util.ScreenshotURL(url, util.GenTempFilePath("getweb/url.png"), 1620, 1960, 0, 0, 0, 0, ""); err != nil {
return model.Reply{
ReplyMsg: err.Error(),
ReferOriginMsg: true,
@ -24,7 +25,7 @@ func getweb(msg model.Message) (reply model.Reply) {
}
}
return model.Reply{
ReplyMsg: "[CQ:image,file=file:///root/qqbot/tmp/getweb/url.png]",
ReplyMsg: "[CQ:image,file=file:///root/qqbot/getweb/url.png]",
ReferOriginMsg: true,
FromMsg: msg,
}

View File

@ -176,7 +176,7 @@ func getMyRecentScore(msg model.Message) (reply model.Reply) {
func screenshotSS(msg model.Message) (reply model.Reply) {
return model.Reply{
ReplyMsg: "[CQ:image,file=file:///root/qqbot/tmp/" + scoresaber.GetSSPicture(strconv.Itoa(int(msg.UserId))) + "]",
ReplyMsg: "[CQ:image,file=file:///root/qqbot/" + scoresaber.GetSSPicture(strconv.Itoa(int(msg.UserId))) + "]",
ReferOriginMsg: true,
FromMsg: msg,
}

View File

@ -8,6 +8,7 @@ import (
"git.lxtend.com/qqbot/handler"
"git.lxtend.com/qqbot/model"
"git.lxtend.com/qqbot/service/xibao"
"git.lxtend.com/qqbot/util"
"github.com/google/uuid"
)
@ -20,7 +21,7 @@ func init() {
func xiBao(msg model.Message) (reply model.Reply) {
fileName := uuid.New().String()
filePath := "./tmp/" + fileName + ".png"
filePath := util.GenTempFilePath(fmt.Sprintf("%s.png", fileName))
re := regexp.MustCompile(`\s+`)
tokens := re.Split(msg.RawMsg, 2)
if len(tokens) < 2 {
@ -33,7 +34,7 @@ func xiBao(msg model.Message) (reply model.Reply) {
}
xibao.GenerateCongratulationImage(tokens[1], "./resource/xibao_background.png", filePath, true)
return model.Reply{
ReplyMsg: fmt.Sprintf("[CQ:image,file=file:///root/qqbot/tmp/%s]", fileName+".png"),
ReplyMsg: fmt.Sprintf("[CQ:image,file=file:///root/qqbot/%s]", fileName+".png"),
ReferOriginMsg: true,
FromMsg: msg,
}
@ -42,10 +43,10 @@ func xiBao(msg model.Message) (reply model.Reply) {
func xiBaoTemp(msg model.Message) (reply model.Reply, isTrigger bool) {
handler.UnRegisterLiveHandler(msg.GroupInfo.GroupId, msg.UserId)
fileName := uuid.New().String()
filePath := "./tmp/" + fileName + ".png"
filePath := util.GenTempFilePath(fmt.Sprintf("%s.png", fileName))
xibao.GenerateCongratulationImage(msg.RawMsg, "./resource/xibao_background.png", filePath, true)
return model.Reply{
ReplyMsg: fmt.Sprintf("[CQ:image,file=file:///root/qqbot/tmp/%s]", fileName+".png"),
ReplyMsg: fmt.Sprintf("[CQ:image,file=file:///root/qqbot/%s]", fileName+".png"),
ReferOriginMsg: true,
FromMsg: msg,
}, true
@ -53,7 +54,7 @@ func xiBaoTemp(msg model.Message) (reply model.Reply, isTrigger bool) {
func beiBao(msg model.Message) (reply model.Reply) {
fileName := uuid.New().String()
filePath := "./tmp/" + fileName + ".png"
filePath := util.GenTempFilePath(fmt.Sprintf("%s.png", fileName))
re := regexp.MustCompile(`\s+`)
tokens := re.Split(msg.RawMsg, 2)
if len(tokens) < 2 {
@ -66,7 +67,7 @@ func beiBao(msg model.Message) (reply model.Reply) {
}
xibao.GenerateCongratulationImage(tokens[1], "./resource/beibao_background.png", filePath, false)
return model.Reply{
ReplyMsg: fmt.Sprintf("[CQ:image,file=file:///root/qqbot/tmp/%s]", fileName+".png"),
ReplyMsg: fmt.Sprintf("[CQ:image,file=file:///root/qqbot/%s]", fileName+".png"),
ReferOriginMsg: true,
FromMsg: msg,
}
@ -75,10 +76,10 @@ func beiBao(msg model.Message) (reply model.Reply) {
func beiBaoTemp(msg model.Message) (reply model.Reply, isTrigger bool) {
handler.UnRegisterLiveHandler(msg.GroupInfo.GroupId, msg.UserId)
fileName := uuid.New().String()
filePath := "./tmp/" + fileName + ".png"
filePath := util.GenTempFilePath(fmt.Sprintf("%s.png", fileName))
xibao.GenerateCongratulationImage(msg.RawMsg, "./resource/beibao_background.png", filePath, false)
return model.Reply{
ReplyMsg: fmt.Sprintf("[CQ:image,file=file:///root/qqbot/tmp/%s]", fileName+".png"),
ReplyMsg: fmt.Sprintf("[CQ:image,file=file:///root/qqbot/%s]", fileName+".png"),
ReferOriginMsg: true,
FromMsg: msg,
}, true

View File

@ -12,7 +12,8 @@ func GetBLPicture(qqId string) (outputImgName string) {
return ""
}
url := fmt.Sprintf("https://beatleader.xyz/u/%s", blId)
outputImgPath := fmt.Sprintf("./tmp/beatleader_%s.png", blId)
// outputImgPath := fmt.Sprintf("./tmp/beatleader_%s.png", blId)
outputImgPath := util.GenTempFilePath(fmt.Sprintf("beatleader_%s.png", blId))
outputImgName = fmt.Sprintf("beatleader_%s.png", blId)
if err := util.ScreenshotURL(url, outputImgPath, 1420, 2280, 70, 50, 160, 140, "chartjs"); err != nil {
fmt.Println(err)

View File

@ -12,7 +12,8 @@ func GetSSPicture(qqId string) (outputImgName string) {
return ""
}
url := fmt.Sprintf("https://scoresaber.com/u/%s", ssId)
outputImgPath := fmt.Sprintf("./tmp/scoresaber_%s.png", ssId)
// outputImgPath := fmt.Sprintf("./tmp/scoresaber_%s.png", ssId)
outputImgPath := util.GenTempFilePath(fmt.Sprintf("scoresaber_%s.png", ssId))
outputImgName = fmt.Sprintf("scoresaber_%s.png", ssId)
if err := util.ScreenshotURL(url, outputImgPath, 1420, 2080, 50, 400, 150, 150, ""); err != nil {
fmt.Println(err)

View File

@ -0,0 +1,7 @@
package util
import "fmt"
func GenTempFilePath(fileName string) string {
return fmt.Sprintf("/tmp/napcat/%s", fileName)
}