golifehk/main.go

44 lines
1.1 KiB
Go

package main
import (
"log"
"os"
"strings"
mtrbus "github.com/tgckpg/golifehk/datasources/mtr/bus"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
)
func main() {
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 )
if strings.Contains( update.Message.Text, "@golifehkbot" ){
result := mtrbus.Query( "zh", strings.Replace( update.Message.Text, "@golifehkbot", "", -1 ) )
msg := tgbotapi.NewMessage( update.Message.Chat.ID, result.Message() )
msg.ParseMode = "Markdown"
msg.ReplyToMessageID = update.Message.MessageID
bot.Send( msg )
}
}
}