Some renames

This commit is contained in:
2021-12-03 14:30:10 +03:00
parent 9744337c99
commit 8e06d4c1c9
4 changed files with 11 additions and 11 deletions

16
kicker/handlers.go Normal file
View File

@ -0,0 +1,16 @@
package kicker
import (
tb "gopkg.in/tucnak/telebot.v3"
)
var HandlersV1 = []Handler{
{
Endpoint: tb.OnText,
Handler: func(c tb.Context) error {
m := c.Message()
c.Bot().Send(m.Sender, m.Text)
return nil
},
},
}

45
kicker/kicker.go Normal file
View File

@ -0,0 +1,45 @@
package kicker
import (
"errors"
"log"
"time"
tb "gopkg.in/tucnak/telebot.v3"
)
type Handler struct {
Endpoint interface{}
Handler tb.HandlerFunc
}
/// Базовая структура для бота
type Kicker struct {
Bot *tb.Bot
Token string
}
/// Initialize bot with token
func (b *Kicker) Init() error {
bot, err := tb.NewBot(tb.Settings{
Token: b.Token,
Poller: &tb.LongPoller{Timeout: 10 * time.Second},
})
if err != nil {
log.Print(err)
return err
}
b.Bot = bot
return nil
}
// Add handler methods to the bot
func (b *Kicker) AddHandlers(handlers []Handler) error {
if len(handlers) != 0 {
for i := range handlers {
b.Bot.Handle(handlers[i].Endpoint, handlers[i].Handler)
}
return nil
}
return errors.New("no handlers are declared")
}