feat: 添加关键词回复

This commit is contained in:
lixiangwuxian
2024-10-20 15:47:00 +08:00
parent 003c9b6f90
commit 5a56f6fdc7
9 changed files with 340 additions and 32 deletions

7
util/random_fail.go Normal file
View File

@@ -0,0 +1,7 @@
package util
import "math/rand/v2"
func Fail(chance float64) bool {
return rand.Float64() < chance
}

View File

@@ -4,12 +4,8 @@ import (
"regexp"
)
func SplitN(text string, n int) ([]string, int) {
if n == 0 {
return []string{text}, 1
}
func SplitN(text string, n int) []string {
re := regexp.MustCompile(`\s+`)
tokens := re.Split(text, n)
return tokens, len(tokens)
return tokens
}