refactor: 使用正则分割信息
This commit is contained in:
parent
6f78e3e30d
commit
9cbcc3227f
@ -2,7 +2,7 @@ package xibao
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"regexp"
|
||||||
|
|
||||||
"git.lxtend.com/qqbot/constants"
|
"git.lxtend.com/qqbot/constants"
|
||||||
"git.lxtend.com/qqbot/handler"
|
"git.lxtend.com/qqbot/handler"
|
||||||
@ -21,7 +21,17 @@ func init() {
|
|||||||
func xiBao(msg model.Message) (reply model.Reply) {
|
func xiBao(msg model.Message) (reply model.Reply) {
|
||||||
fileName := uuid.New().String()
|
fileName := uuid.New().String()
|
||||||
filePath := "./tmp/" + fileName + ".png"
|
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{
|
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/tmp/%s]", fileName+".png"),
|
||||||
ReferOriginMsg: true,
|
ReferOriginMsg: true,
|
||||||
@ -32,7 +42,16 @@ func xiBao(msg model.Message) (reply model.Reply) {
|
|||||||
func beiBao(msg model.Message) (reply model.Reply) {
|
func beiBao(msg model.Message) (reply model.Reply) {
|
||||||
fileName := uuid.New().String()
|
fileName := uuid.New().String()
|
||||||
filePath := "./tmp/" + fileName + ".png"
|
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{
|
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/tmp/%s]", fileName+".png"),
|
||||||
ReferOriginMsg: true,
|
ReferOriginMsg: true,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user