Add kek command

This commit is contained in:
bdnugget 2025-05-28 12:34:09 +02:00
parent e2a090b702
commit d05a04ff4b

51
commands/kek.go Normal file
View File

@ -0,0 +1,51 @@
package commands
import (
"encoding/json"
"math/rand"
"os"
"sync"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
)
type KekCommand struct{}
var (
kekJokes []string
kekJokesOnce sync.Once
)
func loadKekJokes() {
file, err := os.Open("json/jokes.json")
if err != nil {
kekJokes = []string{"Failed to load jokes."}
return
}
defer file.Close()
json.NewDecoder(file).Decode(&kekJokes)
}
func (k KekCommand) Name() string {
return "kek"
}
func (k KekCommand) Help() string {
return "Get niggerkeks"
}
func (k KekCommand) Execute(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
kekJokesOnce.Do(loadKekJokes)
if len(kekJokes) == 0 {
msg := tgbotapi.NewMessage(update.Message.Chat.ID, "No jokes available.")
bot.Send(msg)
return
}
joke := kekJokes[rand.Intn(len(kekJokes))]
msg := tgbotapi.NewMessage(update.Message.Chat.ID, joke)
bot.Send(msg)
}
func init() {
Register(KekCommand{})
}