Constructors for keyboard and options, CallbackHandler
This commit is contained in:
parent
b7f1e3e9ed
commit
dd0307e382
6
bot.go
6
bot.go
|
@ -36,5 +36,11 @@ func (b *bot) Update(u *echo.Update) {
|
|||
|
||||
b.lock.Lock()
|
||||
defer b.lock.Unlock()
|
||||
// defer func() {
|
||||
// if r := recover(); r != nil {
|
||||
// log.Printf("[%s] Recovered. Error: %s\n", upd.UpdateID.String(), r)
|
||||
// }
|
||||
// }()
|
||||
|
||||
b.handler(upd)
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package nechotron
|
|||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/NicoNex/echotron/v3"
|
||||
)
|
||||
|
||||
type UpdateHandler func(u *Update) error
|
||||
|
@ -52,6 +54,22 @@ func (d *Dispatcher) HandleFilter(filter FilterFn, handler UpdateHandler) *Dispa
|
|||
return d
|
||||
}
|
||||
|
||||
func (d *Dispatcher) HandleCallback(callback string, handler UpdateHandler) *Dispatcher {
|
||||
newHandler := func(u *Update) (bool, error) {
|
||||
if !u.IsCallback() {
|
||||
return false, nil
|
||||
}
|
||||
defer u.Bot.AnswerCallbackQuery(u.CallbackQuery.ID, &echotron.CallbackQueryOptions{})
|
||||
if u.CallbackQuery.Data != callback {
|
||||
return false, nil
|
||||
}
|
||||
err := handler(u)
|
||||
return true, err
|
||||
}
|
||||
d.handlers = append(d.handlers, newHandler)
|
||||
return d
|
||||
}
|
||||
|
||||
func (d *Dispatcher) HandleReply(handler UpdateHandler) *Dispatcher {
|
||||
newHandler := func(u *Update) (bool, error) {
|
||||
if !u.IsMessage() {
|
||||
|
|
|
@ -6,6 +6,10 @@ type InKeyboard struct {
|
|||
Buttons [][]echotron.InlineKeyboardButton
|
||||
}
|
||||
|
||||
func NewInlineKeyboard() *InKeyboard {
|
||||
return &InKeyboard{}
|
||||
}
|
||||
|
||||
func (i *InKeyboard) Row(buttons ...echotron.InlineKeyboardButton) *InKeyboard {
|
||||
i.Buttons = append(i.Buttons, buttons)
|
||||
return i
|
||||
|
|
|
@ -16,6 +16,10 @@ type OptionsBuilder struct {
|
|||
hasSpoiler bool
|
||||
}
|
||||
|
||||
func NewOptions() *OptionsBuilder {
|
||||
return &OptionsBuilder{}
|
||||
}
|
||||
|
||||
func (o *OptionsBuilder) Caption(text string) *OptionsBuilder {
|
||||
o.caption = text
|
||||
return o
|
||||
|
|
Loading…
Reference in New Issue