61 lines
1.8 KiB
Go
61 lines
1.8 KiB
Go
package xibao
|
|
|
|
import (
|
|
"fmt"
|
|
"regexp"
|
|
|
|
"git.lxtend.com/qqbot/constants"
|
|
"git.lxtend.com/qqbot/handler"
|
|
"git.lxtend.com/qqbot/model"
|
|
"git.lxtend.com/qqbot/service/xibao"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
func init() {
|
|
handler.RegisterHandler("喜报", xiBao, constants.LEVEL_USER)
|
|
handler.RegisterHelpInform("喜报", "喜报 [内容] 生成喜报图片,支持换行")
|
|
handler.RegisterHandler("悲报", beiBao, constants.LEVEL_USER)
|
|
handler.RegisterHelpInform("悲报", "悲报 [内容] 生成悲报图片,支持换行")
|
|
}
|
|
|
|
func xiBao(msg model.Message) (reply model.Reply) {
|
|
fileName := uuid.New().String()
|
|
filePath := "./tmp/" + fileName + ".png"
|
|
|
|
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,
|
|
FromMsg: msg,
|
|
}
|
|
}
|
|
|
|
func beiBao(msg model.Message) (reply model.Reply) {
|
|
fileName := uuid.New().String()
|
|
filePath := "./tmp/" + fileName + ".png"
|
|
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,
|
|
FromMsg: msg,
|
|
}
|
|
}
|