golifehk/main.go

40 lines
900 B
Go
Raw Normal View History

2022-09-13 13:42:51 +00:00
package main
import (
"log"
2022-09-14 14:54:51 +00:00
"os"
mtrbus "github.com/tgckpg/golifehk/datasources/mtr/bus"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
2022-09-13 13:42:51 +00:00
)
func main() {
2022-09-14 14:54:51 +00:00
bot, err := tgbotapi.NewBotAPI( os.Getenv( "TELEGRAM_API_TOKEN" ) )
if err != nil {
log.Panic( err )
}
bot.Debug = true
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 {
continue
}
log.Printf( "[%s] %s", update.Message.From.UserName, update.Message.Text )
result := mtrbus.Query( "zh", update.Message.Text )
msg := tgbotapi.NewMessage( update.Message.Chat.ID, result.Message() )
msg.ReplyToMessageID = update.Message.MessageID
bot.Send( msg )
}
2022-09-13 13:42:51 +00:00
}