112 lines
3.3 KiB
Go
112 lines
3.3 KiB
Go
package xibao
|
|
|
|
import (
|
|
"fmt"
|
|
"regexp"
|
|
|
|
"git.lxtend.com/qqbot/constants"
|
|
"git.lxtend.com/qqbot/handler"
|
|
"git.lxtend.com/qqbot/message"
|
|
"git.lxtend.com/qqbot/model"
|
|
"git.lxtend.com/qqbot/service/xibao"
|
|
"git.lxtend.com/qqbot/util"
|
|
"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 := util.GenTempFilePath(fmt.Sprintf("%s.png", fileName))
|
|
re := regexp.MustCompile(`\s+`)
|
|
tokens := re.Split(msg.RawMsg, 2)
|
|
if len(tokens) < 2 {
|
|
handler.RegisterLiveHandler(msg.GroupInfo.GroupId, msg.UserId, xiBaoTemp)
|
|
return model.Reply{
|
|
ReplyMsg: "",
|
|
ReferOriginMsg: false,
|
|
FromMsg: msg,
|
|
}
|
|
}
|
|
xibao.GenerateCongratulationImage(tokens[1], "./resource/xibao_background.png", filePath, true)
|
|
imageMsg := message.ImageMessage{
|
|
Type: "image",
|
|
Data: message.ImageMessageData{
|
|
File: "file://" + filePath,
|
|
},
|
|
}
|
|
return model.Reply{
|
|
ReplyMsg: imageMsg.ToCQString(),
|
|
ReferOriginMsg: true,
|
|
FromMsg: msg,
|
|
}
|
|
}
|
|
|
|
func xiBaoTemp(msg model.Message) (reply model.Reply, isTrigger bool) {
|
|
handler.UnRegisterLiveHandler(msg.GroupInfo.GroupId, msg.UserId)
|
|
fileName := uuid.New().String()
|
|
filePath := util.GenTempFilePath(fmt.Sprintf("%s.png", fileName))
|
|
xibao.GenerateCongratulationImage(msg.RawMsg, "./resource/xibao_background.png", filePath, true)
|
|
imageMsg := message.ImageMessage{
|
|
Type: "image",
|
|
Data: message.ImageMessageData{
|
|
File: "file://" + filePath,
|
|
},
|
|
}
|
|
return model.Reply{
|
|
ReplyMsg: imageMsg.ToCQString(),
|
|
ReferOriginMsg: true,
|
|
FromMsg: msg,
|
|
}, true
|
|
}
|
|
|
|
func beiBao(msg model.Message) (reply model.Reply) {
|
|
fileName := uuid.New().String()
|
|
filePath := util.GenTempFilePath(fmt.Sprintf("%s.png", fileName))
|
|
re := regexp.MustCompile(`\s+`)
|
|
tokens := re.Split(msg.RawMsg, 2)
|
|
if len(tokens) < 2 {
|
|
handler.RegisterLiveHandler(msg.GroupInfo.GroupId, msg.UserId, beiBaoTemp)
|
|
return model.Reply{
|
|
ReplyMsg: "",
|
|
ReferOriginMsg: false,
|
|
FromMsg: msg,
|
|
}
|
|
}
|
|
xibao.GenerateCongratulationImage(tokens[1], "./resource/beibao_background.png", filePath, false)
|
|
imageMsg := message.ImageMessage{
|
|
Type: "image",
|
|
Data: message.ImageMessageData{
|
|
File: "file:///tmp/qqbot/" + fileName + ".png",
|
|
},
|
|
}
|
|
return model.Reply{
|
|
ReplyMsg: imageMsg.ToCQString(),
|
|
ReferOriginMsg: true,
|
|
FromMsg: msg,
|
|
}
|
|
}
|
|
|
|
func beiBaoTemp(msg model.Message) (reply model.Reply, isTrigger bool) {
|
|
handler.UnRegisterLiveHandler(msg.GroupInfo.GroupId, msg.UserId)
|
|
fileName := uuid.New().String()
|
|
filePath := util.GenTempFilePath(fmt.Sprintf("%s.png", fileName))
|
|
xibao.GenerateCongratulationImage(msg.RawMsg, "./resource/beibao_background.png", filePath, false)
|
|
imageMsg := message.ImageMessage{
|
|
Type: "image",
|
|
Data: message.ImageMessageData{
|
|
File: "file:///tmp/qqbot/" + fileName + ".png",
|
|
},
|
|
}
|
|
return model.Reply{
|
|
ReplyMsg: imageMsg.ToCQString(),
|
|
ReferOriginMsg: true,
|
|
FromMsg: msg,
|
|
}, true
|
|
}
|