From d05a04ff4b7c24609cb7d35ed8cc234978a0db60 Mon Sep 17 00:00:00 2001 From: bdnugget Date: Wed, 28 May 2025 12:34:09 +0200 Subject: [PATCH] Add kek command --- commands/kek.go | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 commands/kek.go diff --git a/commands/kek.go b/commands/kek.go new file mode 100644 index 0000000..a54b68e --- /dev/null +++ b/commands/kek.go @@ -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{}) +}