fix: 修改多个处理函数的返回类型为指针类型,以提高内存使用效率并避免不必要的拷贝
This commit is contained in:
@@ -32,7 +32,7 @@ func init() {
|
||||
// handler.RegisterHandler("jss", screenshotSS, constants.LEVEL_USER)
|
||||
}
|
||||
|
||||
func ssPlusN(msg model.Message) (reply model.Reply) {
|
||||
func ssPlusN(msg model.Message) (reply *model.Reply) {
|
||||
var (
|
||||
resultStr strings.Builder
|
||||
err error
|
||||
@@ -43,7 +43,7 @@ func ssPlusN(msg model.Message) (reply model.Reply) {
|
||||
if len(msg.RawMsg) > len("ss+") {
|
||||
N, err = strconv.Atoi(msg.RawMsg[len("ss+"):])
|
||||
if err != nil || N <= 0 {
|
||||
return model.Reply{
|
||||
return &model.Reply{
|
||||
ReplyMsg: "请输入一个正整数",
|
||||
ReferOriginMsg: true,
|
||||
FromMsg: msg,
|
||||
@@ -54,7 +54,7 @@ func ssPlusN(msg model.Message) (reply model.Reply) {
|
||||
userIdStr := strconv.Itoa(int(msg.UserId))
|
||||
userSSID, err := scoresaber.GetSSID(userIdStr)
|
||||
if err != nil {
|
||||
return model.Reply{
|
||||
return &model.Reply{
|
||||
ReplyMsg: err.Error(),
|
||||
ReferOriginMsg: true,
|
||||
FromMsg: msg,
|
||||
@@ -70,7 +70,7 @@ func ssPlusN(msg model.Message) (reply model.Reply) {
|
||||
attempts++
|
||||
}
|
||||
if err != nil {
|
||||
return model.Reply{
|
||||
return &model.Reply{
|
||||
ReplyMsg: "获取您的分数时出现问题,请稍后重试。" + err.Error(),
|
||||
ReferOriginMsg: true,
|
||||
FromMsg: msg,
|
||||
@@ -80,7 +80,7 @@ func ssPlusN(msg model.Message) (reply model.Reply) {
|
||||
// 获取当前用户所在区对应+N位的玩家列表
|
||||
leaderboard, err := scoresaber.FetchCountryLeaderboard(userInfo.Country, userInfo.CountryRank-N, userInfo.ID)
|
||||
if err != nil {
|
||||
return model.Reply{
|
||||
return &model.Reply{
|
||||
ReplyMsg: "获取您的分数时出现问题,请稍后重试。" + err.Error(),
|
||||
ReferOriginMsg: true,
|
||||
FromMsg: msg,
|
||||
@@ -102,14 +102,14 @@ func ssPlusN(msg model.Message) (reply model.Reply) {
|
||||
}
|
||||
}
|
||||
resultStr.WriteString(fmt.Sprintf("您只需要再打出%.2fpp就能达到%s区第%d名。", targetPlayer.PP-userInfo.PP, userInfo.Country, targetPlayer.CountryRank))
|
||||
return model.Reply{
|
||||
return &model.Reply{
|
||||
ReplyMsg: resultStr.String(),
|
||||
ReferOriginMsg: true,
|
||||
FromMsg: msg,
|
||||
}
|
||||
}
|
||||
|
||||
func getSSProfile(msg model.Message) (reply model.Reply) {
|
||||
func getSSProfile(msg model.Message) (reply *model.Reply) {
|
||||
var (
|
||||
resultStr string
|
||||
err error
|
||||
@@ -130,7 +130,7 @@ func getSSProfile(msg model.Message) (reply model.Reply) {
|
||||
ssId, err = scoresaber.GetSSID(userIdStr)
|
||||
}
|
||||
if err != nil {
|
||||
return model.Reply{
|
||||
return &model.Reply{
|
||||
ReplyMsg: "您未绑定ss账号,输入\"绑定ss [ssId]\"绑定(ssId为您的scoresaber主页链接中的数字部分)",
|
||||
ReferOriginMsg: true,
|
||||
FromMsg: msg,
|
||||
@@ -153,37 +153,37 @@ func getSSProfile(msg model.Message) (reply model.Reply) {
|
||||
resultStr = "获取您的分数时出现问题,请稍后重试。" + err.Error()
|
||||
}
|
||||
|
||||
return model.Reply{
|
||||
return &model.Reply{
|
||||
ReplyMsg: resultStr,
|
||||
ReferOriginMsg: true,
|
||||
FromMsg: msg,
|
||||
}
|
||||
}
|
||||
|
||||
func bindSS(msg model.Message) (reply model.Reply) {
|
||||
return model.Reply{
|
||||
func bindSS(msg model.Message) (reply *model.Reply) {
|
||||
return &model.Reply{
|
||||
ReplyMsg: scoresaber.SSQuery.BindSS(strconv.Itoa(int(msg.UserId)), msg.RawMsg[len("绑定ss "):]),
|
||||
ReferOriginMsg: true,
|
||||
FromMsg: msg,
|
||||
}
|
||||
}
|
||||
|
||||
func unbindSS(msg model.Message) (reply model.Reply) {
|
||||
return model.Reply{
|
||||
func unbindSS(msg model.Message) (reply *model.Reply) {
|
||||
return &model.Reply{
|
||||
ReplyMsg: scoresaber.SSQuery.UnbindSS(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("最新ss ") {
|
||||
var err error
|
||||
count, err = strconv.Atoi(msg.RawMsg[len("最新ss "):])
|
||||
if err != nil || count <= 0 {
|
||||
return model.Reply{
|
||||
return &model.Reply{
|
||||
ReplyMsg: "",
|
||||
ReferOriginMsg: true,
|
||||
FromMsg: msg,
|
||||
@@ -197,7 +197,7 @@ func getMyRecentScore(msg model.Message) (reply model.Reply) {
|
||||
recordCount := 0
|
||||
records, err := scoresaber.SSQuery.GetRecentScores(count, strconv.Itoa(int(msg.UserId)))
|
||||
if err != nil {
|
||||
return model.Reply{
|
||||
return &model.Reply{
|
||||
ReplyMsg: err.Error(),
|
||||
ReferOriginMsg: true,
|
||||
FromMsg: msg,
|
||||
@@ -238,21 +238,21 @@ 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 screenshotSS(msg model.Message) (reply model.Reply) {
|
||||
return model.Reply{
|
||||
func screenshotSS(msg model.Message) (reply *model.Reply) {
|
||||
return &model.Reply{
|
||||
ReplyMsg: "[CQ:image,file=file:///tmp/qqbot/" + scoresaber.GetSSPicture(strconv.Itoa(int(msg.UserId))) + "]",
|
||||
ReferOriginMsg: true,
|
||||
FromMsg: msg,
|
||||
|
||||
Reference in New Issue
Block a user