fix: 修改多个处理函数的返回类型为指针类型,以提高内存使用效率并避免不必要的拷贝
This commit is contained in:
@@ -32,10 +32,10 @@ func initKw() {
|
||||
}
|
||||
}
|
||||
|
||||
func setKw(msg model.Message) (reply model.Reply) {
|
||||
func setKw(msg model.Message) (reply *model.Reply) {
|
||||
tokens := util.SplitN(msg.RawMsg, 3)
|
||||
if len(tokens) < 2 {
|
||||
return model.Reply{
|
||||
return &model.Reply{
|
||||
ReplyMsg: "参数不足, 请使用\"kw [关键词] [回复内容]\"添加关键词回复",
|
||||
ReferOriginMsg: true,
|
||||
FromMsg: msg,
|
||||
@@ -43,62 +43,62 @@ func setKw(msg model.Message) (reply model.Reply) {
|
||||
}
|
||||
|
||||
if _, err := kw.AddKW(tokens[1], tokens[2], strconv.Itoa(int(msg.GroupInfo.GroupId)), strconv.Itoa(int(msg.UserId))); err != nil {
|
||||
return model.Reply{
|
||||
return &model.Reply{
|
||||
ReplyMsg: "添加失败",
|
||||
ReferOriginMsg: true,
|
||||
FromMsg: msg,
|
||||
}
|
||||
}
|
||||
regKw(tokens[1], msg.GroupInfo.GroupId)
|
||||
return model.Reply{
|
||||
return &model.Reply{
|
||||
ReplyMsg: "记下了",
|
||||
ReferOriginMsg: true,
|
||||
FromMsg: msg,
|
||||
}
|
||||
}
|
||||
|
||||
func deleteKw(msg model.Message) (reply model.Reply) {
|
||||
func deleteKw(msg model.Message) (reply *model.Reply) {
|
||||
tokens := util.SplitN(msg.RawMsg, 3)
|
||||
if len(tokens) == 2 {
|
||||
if err := kw.DeleteKW(tokens[1], strconv.Itoa(int(msg.GroupInfo.GroupId))); err != nil {
|
||||
return model.Reply{
|
||||
return &model.Reply{
|
||||
ReplyMsg: "删除失败",
|
||||
ReferOriginMsg: true,
|
||||
FromMsg: msg,
|
||||
}
|
||||
}
|
||||
unRegKw(tokens[1], msg.GroupInfo.GroupId)
|
||||
return model.Reply{
|
||||
return &model.Reply{
|
||||
ReplyMsg: "清空了",
|
||||
ReferOriginMsg: true,
|
||||
FromMsg: msg,
|
||||
}
|
||||
}
|
||||
if len(tokens) < 2 {
|
||||
return model.Reply{
|
||||
return &model.Reply{
|
||||
ReplyMsg: "参数不足, 请使用\"kwd [关键词] [回复内容]\"删除对应的关键词回复",
|
||||
ReferOriginMsg: true,
|
||||
FromMsg: msg,
|
||||
}
|
||||
}
|
||||
if err := kw.DeleteKWReply(tokens[1], tokens[2], strconv.Itoa(int(msg.GroupInfo.GroupId))); err != nil {
|
||||
return model.Reply{
|
||||
return &model.Reply{
|
||||
ReplyMsg: "删除失败",
|
||||
ReferOriginMsg: true,
|
||||
FromMsg: msg,
|
||||
}
|
||||
}
|
||||
return model.Reply{
|
||||
return &model.Reply{
|
||||
ReplyMsg: "删除了",
|
||||
ReferOriginMsg: true,
|
||||
FromMsg: msg,
|
||||
}
|
||||
}
|
||||
|
||||
func getGroupAllKW(msg model.Message) (reply model.Reply) {
|
||||
func getGroupAllKW(msg model.Message) (reply *model.Reply) {
|
||||
kwList, err := kw.GetGroupAllKW(strconv.Itoa(int(msg.GroupInfo.GroupId)))
|
||||
if err != nil {
|
||||
return model.Reply{
|
||||
return &model.Reply{
|
||||
ReplyMsg: "获取失败",
|
||||
ReferOriginMsg: true,
|
||||
FromMsg: msg,
|
||||
@@ -111,7 +111,7 @@ func getGroupAllKW(msg model.Message) (reply model.Reply) {
|
||||
kws += "\n"
|
||||
}
|
||||
}
|
||||
return model.Reply{
|
||||
return &model.Reply{
|
||||
ReplyMsg: kws,
|
||||
ReferOriginMsg: true,
|
||||
FromMsg: msg,
|
||||
@@ -126,10 +126,10 @@ func unRegKw(keyword string, groupId int64) {
|
||||
handler.UnRegisterGroupHandler(groupId, keyword)
|
||||
}
|
||||
|
||||
func kwReply(msg model.Message) (reply model.Reply) {
|
||||
func kwReply(msg model.Message) (reply *model.Reply) {
|
||||
w, err := kw.GetKW(msg.RawMsg, strconv.Itoa(int(msg.GroupInfo.GroupId)))
|
||||
if err != nil {
|
||||
return model.Reply{
|
||||
return &model.Reply{
|
||||
ReplyMsg: "",
|
||||
ReferOriginMsg: false,
|
||||
FromMsg: msg,
|
||||
@@ -140,7 +140,7 @@ func kwReply(msg model.Message) (reply model.Reply) {
|
||||
wlist = append(wlist, v.Reply)
|
||||
}
|
||||
pick := rand.IntN(len(wlist))
|
||||
return model.Reply{
|
||||
return &model.Reply{
|
||||
ReplyMsg: wlist[pick],
|
||||
ReferOriginMsg: false,
|
||||
FromMsg: msg,
|
||||
|
||||
Reference in New Issue
Block a user