nignoggobot/main.go

41 lines
807 B
Go

package main
import (
"log"
"os"
"nignoggobot/commands"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
_ "nignoggobot/commands" // ensure init() is called
)
func main() {
bot, err := tgbotapi.NewBotAPI(os.Getenv("TELEGRAM_TOKEN"))
log.Println(os.Getenv("TELEGRAM_TOKEN"))
if err != nil {
log.Fatal(err)
}
log.Printf("Authorized on account %s", bot.Self.UserName)
u := tgbotapi.NewUpdate(0)
u.Timeout = 60
updates := bot.GetUpdatesChan(u)
for update := range updates {
if update.Message == nil || !update.Message.IsCommand() {
continue
}
cmdName := update.Message.Command()
if cmd, ok := commands.All()[cmdName]; ok {
cmd.Execute(update, bot)
} else {
msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Unknown command.")
bot.Send(msg)
}
}
}