fix: 修改多个处理函数的返回类型为指针类型,以提高内存使用效率并避免不必要的拷贝
This commit is contained in:
@@ -30,7 +30,7 @@ func init() {
|
||||
handler.RegisterHandler("jbl", screenShotBL, constants.LEVEL_USER)
|
||||
}
|
||||
|
||||
func getMyBL(msg model.Message) (reply model.Reply) {
|
||||
func getMyBL(msg model.Message) (reply *model.Reply) {
|
||||
var (
|
||||
resultStr string
|
||||
err error
|
||||
@@ -53,43 +53,43 @@ func getMyBL(msg model.Message) (reply model.Reply) {
|
||||
resultStr = "获取您的分数时出现问题,请稍后重试。"
|
||||
}
|
||||
|
||||
return model.Reply{
|
||||
return &model.Reply{
|
||||
ReplyMsg: resultStr,
|
||||
ReferOriginMsg: true,
|
||||
FromMsg: msg,
|
||||
}
|
||||
}
|
||||
func bindBL(msg model.Message) (reply model.Reply) {
|
||||
func bindBL(msg model.Message) (reply *model.Reply) {
|
||||
if len(msg.RawMsg) <= len("绑定bl ") {
|
||||
return model.Reply{
|
||||
return &model.Reply{
|
||||
ReplyMsg: "请输入绑定的beatleader账号",
|
||||
ReferOriginMsg: true,
|
||||
FromMsg: msg,
|
||||
}
|
||||
}
|
||||
return model.Reply{
|
||||
return &model.Reply{
|
||||
ReplyMsg: beatleader.BLQuery.BindBL(strconv.Itoa(int(msg.UserId)), msg.RawMsg[len("绑定bl "):]),
|
||||
ReferOriginMsg: true,
|
||||
FromMsg: msg,
|
||||
}
|
||||
}
|
||||
|
||||
func unbindBL(msg model.Message) (reply model.Reply) {
|
||||
return model.Reply{
|
||||
func unbindBL(msg model.Message) (reply *model.Reply) {
|
||||
return &model.Reply{
|
||||
ReplyMsg: beatleader.BLQuery.UnbindBL(strconv.Itoa(int(msg.UserId))),
|
||||
ReferOriginMsg: true,
|
||||
FromMsg: msg,
|
||||
}
|
||||
}
|
||||
|
||||
func getMyRecentScore(msg model.Message) (reply model.Reply) {
|
||||
func getMyRecentScore(msg model.Message) (reply *model.Reply) {
|
||||
count := 1
|
||||
scoreMsg := ""
|
||||
if len(msg.RawMsg) > len("最新bl ") {
|
||||
var err error
|
||||
count, err = strconv.Atoi(msg.RawMsg[len("最新bl "):])
|
||||
if err != nil || count <= 0 {
|
||||
return model.Reply{
|
||||
return &model.Reply{
|
||||
ReplyMsg: "",
|
||||
ReferOriginMsg: true,
|
||||
FromMsg: msg,
|
||||
@@ -103,7 +103,7 @@ func getMyRecentScore(msg model.Message) (reply model.Reply) {
|
||||
recordCount := 0
|
||||
records, err := beatleader.BLQuery.GetRecentScores(count, strconv.Itoa(int(msg.UserId)))
|
||||
if err != nil {
|
||||
return model.Reply{
|
||||
return &model.Reply{
|
||||
ReplyMsg: err.Error(),
|
||||
ReferOriginMsg: true,
|
||||
FromMsg: msg,
|
||||
@@ -145,27 +145,27 @@ func getMyRecentScore(msg model.Message) (reply model.Reply) {
|
||||
if len(scoreMsg) > 0 {
|
||||
scoreMsg = scoreMsg[:len(scoreMsg)-len("\n")] //去掉最后一个换行符
|
||||
} else {
|
||||
return model.Reply{
|
||||
return &model.Reply{
|
||||
ReplyMsg: "无最近游戏记录",
|
||||
ReferOriginMsg: true,
|
||||
FromMsg: msg,
|
||||
}
|
||||
}
|
||||
return model.Reply{
|
||||
return &model.Reply{
|
||||
ReplyMsg: "玩家 " + userName + " 的" + strconv.Itoa(recordCount) + "条最近记录为:\n" + scoreMsg,
|
||||
ReferOriginMsg: true,
|
||||
FromMsg: msg,
|
||||
}
|
||||
}
|
||||
|
||||
func screenShotBL(msg model.Message) (reply model.Reply) {
|
||||
func screenShotBL(msg model.Message) (reply *model.Reply) {
|
||||
imageMsg := message.ImageMessage{
|
||||
Type: "image",
|
||||
Data: message.ImageMessageData{
|
||||
File: "file:///tmp/qqbot/" + beatleader.GetBLPicture(strconv.Itoa(int(msg.UserId))),
|
||||
},
|
||||
}
|
||||
return model.Reply{
|
||||
return &model.Reply{
|
||||
ReplyMsg: imageMsg.ToCQString(),
|
||||
ReferOriginMsg: true,
|
||||
FromMsg: msg,
|
||||
|
||||
Reference in New Issue
Block a user