diff --git a/handler/xibao/xibao.go b/handler/xibao/xibao.go index 3ecec18..14bcc50 100644 --- a/handler/xibao/xibao.go +++ b/handler/xibao/xibao.go @@ -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,