2020-05-17 06:25:29 +00:00
|
|
|
package telegram
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/mattburchett/go_telegram/pkg/core/config"
|
|
|
|
"github.com/yanzay/tbot/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Bot contains all the necessary bot and callback information.
|
|
|
|
type Bot struct {
|
|
|
|
Client *tbot.Client
|
|
|
|
Config config.Config
|
|
|
|
Bot *tbot.Server
|
|
|
|
CallbackChatID string
|
|
|
|
CallbackMessageID int
|
|
|
|
}
|
|
|
|
|
2020-05-18 02:06:52 +00:00
|
|
|
// Stat middleware.
|
|
|
|
func stat(h tbot.UpdateHandler) tbot.UpdateHandler {
|
|
|
|
return func(u *tbot.Update) {
|
|
|
|
start := time.Now()
|
|
|
|
h(u)
|
|
|
|
log.Printf("Handle time: %v", time.Now().Sub(start))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-17 06:25:29 +00:00
|
|
|
// New creates an active telegram bot and loads the handlers.
|
|
|
|
func (tb *Bot) New(token string) {
|
|
|
|
tb.Bot = tbot.New(token)
|
|
|
|
tb.Bot.Use(stat)
|
|
|
|
tb.Client = tb.Bot.Client()
|
|
|
|
tb.Handler()
|
|
|
|
tb.Bot.Start()
|
|
|
|
|
|
|
|
}
|