Medchem command
This commit is contained in:
45
main.go
45
main.go
@ -5,6 +5,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"nignoggobot/commands"
|
||||
@ -31,6 +32,37 @@ func notifyShutdown(reason string) {
|
||||
bot.Send(msg)
|
||||
}
|
||||
|
||||
func handleCallbackQuery(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
|
||||
query := update.CallbackQuery
|
||||
|
||||
// Answer the callback query to remove the loading state
|
||||
callback := tgbotapi.NewCallback(query.ID, "")
|
||||
bot.Request(callback)
|
||||
|
||||
// Parse callback data format: "command:param1:param2:..."
|
||||
parts := strings.Split(query.Data, ":")
|
||||
if len(parts) < 2 {
|
||||
log.Printf("Invalid callback data format: %s", query.Data)
|
||||
return
|
||||
}
|
||||
|
||||
commandName := parts[0]
|
||||
|
||||
switch commandName {
|
||||
case "medchem":
|
||||
// Get the medchem command and handle callback
|
||||
if cmd, ok := commands.All()["medchem"]; ok {
|
||||
if medchemCmd, ok := cmd.(interface {
|
||||
HandleCallback(tgbotapi.Update, *tgbotapi.BotAPI, []string)
|
||||
}); ok {
|
||||
medchemCmd.HandleCallback(update, bot, parts[1:])
|
||||
}
|
||||
}
|
||||
default:
|
||||
log.Printf("Unknown callback command: %s", commandName)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
// Signal handling for SIGINT/SIGTERM
|
||||
sigs := make(chan os.Signal, 1)
|
||||
@ -63,11 +95,18 @@ func main() {
|
||||
updates := bot.GetUpdatesChan(u)
|
||||
|
||||
for update := range updates {
|
||||
// Handle callback queries (inline keyboard button presses)
|
||||
if update.CallbackQuery != nil {
|
||||
log.Printf("Received callback query: %s from user %d", update.CallbackQuery.Data, update.CallbackQuery.From.ID)
|
||||
handleCallbackQuery(update, bot)
|
||||
continue
|
||||
}
|
||||
|
||||
if update.Message == nil || !update.Message.IsCommand() {
|
||||
continue
|
||||
}
|
||||
|
||||
log.Printf("Received command: %s from chat %d (user %d)", update.Message.Command(), update.Message.Chat.ID, update.Message.From.ID)
|
||||
log.Printf("Received command: %s with args %s from chat %d (user %d)", update.Message.Command(), update.Message.CommandArguments(), update.Message.Chat.ID, update.Message.From.ID)
|
||||
|
||||
cmdName := update.Message.Command()
|
||||
isGroup := update.Message.Chat.IsGroup() || update.Message.Chat.IsSuperGroup()
|
||||
@ -79,8 +118,8 @@ func main() {
|
||||
cmd.Execute(update, bot)
|
||||
} else {
|
||||
log.Printf("Unknown command: %s", cmdName)
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Unknown command.")
|
||||
bot.Send(msg)
|
||||
// msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Unknown command.")
|
||||
// bot.Send(msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user