From cbc3d68c952dea04a3295818610ac91c3d03820a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Rudowicz?= Date: Thu, 9 Jan 2025 21:53:58 +0100 Subject: [PATCH] Initial stub of command support --- command_handler.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 command_handler.go diff --git a/command_handler.go b/command_handler.go new file mode 100644 index 0000000..7c72a14 --- /dev/null +++ b/command_handler.go @@ -0,0 +1,42 @@ +package main + +import ( + "log" + + tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" +) + +func getCurrentStatus(dataStore *DataStore) string { + return "" +} + +func HandleTelegramCommands(bot tgbotapi.BotAPI, logger *log.Logger, dataStore *DataStore) { + u := tgbotapi.NewUpdate(0) + u.Timeout = 60 + + updates := bot.GetUpdatesChan(u) + + for update := range updates { + if update.Message == nil { // ignore any non-Message updates + continue + } + + if !update.Message.IsCommand() { // ignore any non-command Messages + continue + } + + // Create a new MessageConfig. We don't have text yet, + // so we leave it empty. + msg := tgbotapi.NewMessage(update.Message.Chat.ID, "") + + // Extract the command from the Message. + switch update.Message.Command() { + case "status": + msg.Text = getCurrentStatus(dataStore) + } + + if _, err := bot.Send(msg); err != nil { + logger.Print(err) + } + } +}