Skip to content

Commit cf8477d

Browse files
committed
breaking change - keyboard receives struct with buttons, not a map
1 parent b878ca3 commit cf8477d

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

keyboard.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ type Keyboard struct {
2020
btnsInRow int
2121
}
2222

23-
type KeyboardCommands map[BtnLabel]func(m *tb.Message)
23+
type KeyboardCmd struct {
24+
Label BtnLabel
25+
Handler func(m *tb.Message)
26+
}
27+
28+
type KeyboardCommands []KeyboardCmd
2429

2530
func NewKeyboard(b Boter, cmds KeyboardCommands, opts ...KbdOption) *Keyboard {
2631
kbd := &Keyboard{
@@ -40,10 +45,10 @@ func (k *Keyboard) Markup(lang string) *tb.ReplyMarkup {
4045

4146
p := Printer(lang, k.lang)
4247
var btns []tb.Btn
43-
for lbl, h := range k.cmds {
44-
btn := m.Text(p.Sprintf(string(lbl)))
48+
for _, kc := range k.cmds {
49+
btn := m.Text(p.Sprintf(string(kc.Label)))
4550
btns = append(btns, btn)
46-
k.b.Handle(&btn, h)
51+
k.b.Handle(&btn, kc.Handler)
4752
}
4853
m.Reply(organizeButtons(btns, k.btnsInRow)...)
4954
return m

0 commit comments

Comments
 (0)