fix: 修改多个处理函数的返回类型为指针类型,以提高内存使用效率并避免不必要的拷贝

This commit is contained in:
lixiangwuxian
2025-04-09 23:28:39 +08:00
parent 144034939c
commit 7f0560b56e
32 changed files with 211 additions and 210 deletions

View File

@@ -18,10 +18,10 @@ func init() {
userGameMap = make(map[string]*core.BackJackGame)
}
func blackJack(msg model.Message) model.Reply {
func blackJack(msg model.Message) *model.Reply {
tokens := util.SplitN(msg.RawMsg, 2)
if len(tokens) < 2 {
return model.Reply{
return &model.Reply{
ReplyMsg: "Invalid command",
ReferOriginMsg: true,
FromMsg: msg,
@@ -30,7 +30,7 @@ func blackJack(msg model.Message) model.Reply {
if tokens[1] == "exit" {
delete(userGameMap, util.From(msg.GroupInfo.GroupId, msg.UserId))
return model.Reply{
return &model.Reply{
ReplyMsg: "Bye",
ReferOriginMsg: false,
FromMsg: msg,
@@ -41,7 +41,7 @@ func blackJack(msg model.Message) model.Reply {
userGameMap[util.From(msg.GroupInfo.GroupId, msg.UserId)] = core.NewBlackJackGame(controller.NewBlackJackSimulator(), view.NewLiteralViewer(controller.NewBlackJackSimulator()))
}
if _, ok := userGameMap[util.From(msg.GroupInfo.GroupId, msg.UserId)]; !ok {
return model.Reply{
return &model.Reply{
ReplyMsg: "Please start a game first",
ReferOriginMsg: true,
FromMsg: msg,
@@ -52,18 +52,18 @@ func blackJack(msg model.Message) model.Reply {
if response[len(response)-1:] == "\n" {
response = response[:len(response)-1]
}
return model.Reply{
return &model.Reply{
ReplyMsg: response,
ReferOriginMsg: false,
FromMsg: msg,
}
}
func blackJackWithNoBj(msg model.Message) (model.Reply, bool) {
func blackJackWithNoBj(msg model.Message) (reply *model.Reply, ok bool) {
if msg.RawMsg == "exit" {
delete(userGameMap, util.From(msg.GroupInfo.GroupId, msg.UserId))
handler.UnRegisterLiveHandler(msg.GroupInfo.GroupId, msg.UserId)
return model.Reply{
return &model.Reply{
ReplyMsg: "Bye",
ReferOriginMsg: false,
FromMsg: msg,
@@ -75,7 +75,7 @@ func blackJackWithNoBj(msg model.Message) (model.Reply, bool) {
}
if _, ok := userGameMap[util.From(msg.GroupInfo.GroupId, msg.UserId)]; !ok {
return model.Reply{
return &model.Reply{
ReplyMsg: "Please start a game first",
ReferOriginMsg: true,
FromMsg: msg,
@@ -84,7 +84,7 @@ func blackJackWithNoBj(msg model.Message) (model.Reply, bool) {
response, err := userGameMap[util.From(msg.GroupInfo.GroupId, msg.UserId)].AddCommand(msg.RawMsg)
if err != nil {
if err.Error() == "invalid command" {
return model.Reply{
return &model.Reply{
ReplyMsg: "",
ReferOriginMsg: false,
FromMsg: msg,
@@ -97,7 +97,7 @@ func blackJackWithNoBj(msg model.Message) (model.Reply, bool) {
if len(response) > 1 && response[len(response)-1:] == "\n" {
response = response[:len(response)-1]
}
return model.Reply{
return &model.Reply{
ReplyMsg: response,
ReferOriginMsg: false,
FromMsg: msg,