Skip to content

Commit

Permalink
Merge 42b0e76 into 0c71e32
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoshinonyaruko authored Jun 28, 2024
2 parents 0c71e32 + 42b0e76 commit def8b9a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 23 deletions.
43 changes: 21 additions & 22 deletions Processor/ProcessGroupAddBot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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指令
Expand Down
26 changes: 25 additions & 1 deletion Processor/Processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit def8b9a

Please sign in to comment.