refactor: 使用正则分割信息

This commit is contained in:
lixiangwuxian 2024-10-20 03:25:20 +08:00
parent 6f78e3e30d
commit 9cbcc3227f

View File

@ -2,7 +2,7 @@ package xibao
import (
"fmt"
"strings"
"regexp"
"git.lxtend.com/qqbot/constants"
"git.lxtend.com/qqbot/handler"
@ -21,7 +21,17 @@ func init() {
func xiBao(msg model.Message) (reply model.Reply) {
fileName := uuid.New().String()
filePath := "./tmp/" + fileName + ".png"
xibao.GenerateCongratulationImage(strings.Split(msg.RawMsg, " ")[1], "./resource/xibao_background.png", filePath, true)
re := regexp.MustCompile(`\s+`)
tokens := re.Split(msg.RawMsg, 2)
if len(tokens) < 2 {
return model.Reply{
ReplyMsg: "参数不足, 请使用\"喜报 [内容]\"生成喜报图片",
ReferOriginMsg: true,
FromMsg: msg,
}
}
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"),
ReferOriginMsg: true,
@ -32,7 +42,16 @@ func xiBao(msg model.Message) (reply model.Reply) {
func beiBao(msg model.Message) (reply model.Reply) {
fileName := uuid.New().String()
filePath := "./tmp/" + fileName + ".png"
xibao.GenerateCongratulationImage(strings.Split(msg.RawMsg, " ")[1], "./resource/beibao_background.png", filePath, false)
re := regexp.MustCompile(`\s+`)
tokens := re.Split(msg.RawMsg, 2)
if len(tokens) < 2 {
return model.Reply{
ReplyMsg: "参数不足, 请使用\"悲报 [内容]\"生成悲报图片",
ReferOriginMsg: true,
FromMsg: msg,
}
}
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"),
ReferOriginMsg: true,