lucky-tgbot/plugin/torf/main.go
sunyz b04e1fc72d
Some checks failed
Build and Push Docker Images / docker (push) Failing after 31s
[+] improve random function
Signed-off-by: sunyz <i@sunyz.net>
2025-01-24 16:17:44 +08:00

43 lines
894 B
Go

package torf
import (
"math/rand"
"strings"
tele "gopkg.in/telebot.v3"
)
func randResponse(saidType int, r *rand.Rand) string {
responsesMap := map[int][]string{
1: {"有", "没有"},
2: {"好", "不好"},
3: {"是", "不是"},
4: {"尊嘟", "假嘟"},
}
if responses, exists := responsesMap[saidType]; exists {
return responses[r.Intn(len(responses))]
}
return ""
}
func Execute(c tele.Context, r *rand.Rand) error {
inputText := c.Text()
var outputText string
if strings.Contains(inputText, "有没有") {
outputText = randResponse(1, r)
} else if strings.Contains(inputText, "好不好") {
outputText = randResponse(2, r)
} else if strings.Contains(inputText, "是不是") {
outputText = randResponse(3, r)
} else if strings.Contains(inputText, "尊嘟假嘟") {
outputText = randResponse(4, r)
} else {
return nil
}
return c.Reply(outputText)
}