diff --git a/Processor/ProcessGroupAddBot.go b/Processor/ProcessGroupAddBot.go index 912b0ed8..70f0fa73 100644 --- a/Processor/ProcessGroupAddBot.go +++ b/Processor/ProcessGroupAddBot.go @@ -150,28 +150,27 @@ func (p *Processors) ProcessGroupAddBot(data *dto.GroupAddBotEvent) error { } } - if len(validIntros) == 0 { - return nil - } - - // 从validIntros中随机选择一个 - selectedIntro := validIntros[rand.Intn(len(validIntros))] - - // 创建 ActionMessage 实例 - message := callapi.ActionMessage{ - Action: "send_group_msg_group", - Params: callapi.ParamsContent{ - GroupID: strconv.FormatInt(GroupID64, 10), // 转换 GroupID 类型 - UserID: strconv.FormatInt(userid64, 10), - Message: selectedIntro, - }, - } - // clinet是发回值用的 这里相当于和http一样 不发回值所以建立一个假的client - client := &SelfIntroduceClient{} - // 调用处理函数 - _, err = handlers.HandleSendGroupMsg(client, p.Api, p.Apiv2, message) - if err != nil { - mylog.Printf("自我介绍发送失败%v", err) + // 如果设置了自我介绍 + if len(validIntros) != 0 { + // 从validIntros中随机选择一个 + selectedIntro := validIntros[rand.Intn(len(validIntros))] + + // 创建 ActionMessage 实例 + message := callapi.ActionMessage{ + Action: "send_group_msg_group", + Params: callapi.ParamsContent{ + GroupID: strconv.FormatInt(GroupID64, 10), // 转换 GroupID 类型 + UserID: strconv.FormatInt(userid64, 10), + Message: selectedIntro, + }, + } + // clinet是发回值用的 这里相当于和http一样 不发回值所以建立一个假的client + client := &SelfIntroduceClient{} + // 调用处理函数 + _, err = handlers.HandleSendGroupMsg(client, p.Api, p.Apiv2, message) + if err != nil { + mylog.Printf("自我介绍发送失败%v", err) + } } //link指令 diff --git a/Processor/Processor.go b/Processor/Processor.go index 33dc5de8..229d676a 100644 --- a/Processor/Processor.go +++ b/Processor/Processor.go @@ -1228,7 +1228,31 @@ func generateMdByConfig() (md *dto.Markdown, kb *keyboard.MessageKeyboard) { return md, kb } -func getRandomSelection(slice []string, max int) []string { +// getRandomSelection 处理bots数组,分类选择随机bots +func getRandomSelection(bots []string, max int) []string { + threePartBots := []string{} + twoPartBots := []string{} + + // 分类 + for _, bot := range bots { + parts := strings.SplitN(bot, "-", 3) + if len(parts) == 3 { + threePartBots = append(threePartBots, bot) + } else if len(parts) == 2 { + twoPartBots = append(twoPartBots, bot) + } + } + + // 对每个分类应用随机选择 + selectedThreePartBots := selectRandomItems(threePartBots, max) + selectedTwoPartBots := selectRandomItems(twoPartBots, max) + + // 合并结果 + return append(selectedThreePartBots, selectedTwoPartBots...) +} + +// selectRandomItems 从给定slice中随机选择最多max个元素 +func selectRandomItems(slice []string, max int) []string { if len(slice) <= max { return slice }