2024-03-29 14:30:48 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-05-15 20:41:53 +03:00
|
|
|
"surdeus.su/core/tg"
|
2024-03-29 14:30:48 +03:00
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2024-07-21 16:02:47 +03:00
|
|
|
// A simple example widget to show
|
|
|
|
// how to store and get session data values
|
|
|
|
// and working with dynamic panels.
|
2024-03-29 14:30:48 +03:00
|
|
|
var IncDecWidget = tg.RenderFunc(func(c tg.Context) tg.UI {
|
|
|
|
var (
|
|
|
|
kbd *tg.InlineCompo
|
|
|
|
//cntMsg *tg.MessageCompo
|
|
|
|
inline, std, onlyInc, onlyDec tg.Inline
|
|
|
|
)
|
|
|
|
|
|
|
|
d := ExtractSessionData(c)
|
|
|
|
format := "Press the buttons to increment and decrement.\n" +
|
|
|
|
"Current counter value = %d"
|
|
|
|
|
|
|
|
incBtn := tg.Buttonf("+").WithAction(tg.Func(func(c tg.Context) {
|
|
|
|
d.Counter++
|
|
|
|
kbd.Text = fmt.Sprintf(format, d.Counter)
|
|
|
|
if d.Counter == 5 {
|
|
|
|
kbd.Inline = onlyDec
|
|
|
|
} else {
|
|
|
|
kbd.Inline = std
|
|
|
|
}
|
|
|
|
kbd.Update(c)
|
|
|
|
}))
|
|
|
|
decBtn := tg.Buttonf("-").WithAction(tg.Func(func(c tg.Context) {
|
|
|
|
d.Counter--
|
|
|
|
kbd.Text = fmt.Sprintf(format, d.Counter)
|
|
|
|
if d.Counter == -5 {
|
|
|
|
kbd.Inline = onlyInc
|
|
|
|
} else {
|
|
|
|
kbd.Inline = std
|
|
|
|
}
|
|
|
|
kbd.Update(c)
|
|
|
|
//c.Sendf("%d", d.Counter)
|
|
|
|
}))
|
|
|
|
|
|
|
|
onlyInc = tg.NewKeyboard().Row(incBtn).Inline()
|
|
|
|
onlyDec = tg.NewKeyboard().Row(decBtn).Inline()
|
|
|
|
std = tg.NewKeyboard().Row(incBtn, decBtn).Inline()
|
|
|
|
|
|
|
|
if d.Counter == 5 {
|
|
|
|
inline = onlyDec
|
|
|
|
} else if d.Counter == -5 {
|
|
|
|
inline = onlyInc
|
|
|
|
} else {
|
|
|
|
inline = std
|
|
|
|
}
|
|
|
|
|
|
|
|
kbd = tg.Messagef(format, d.Counter).Inline(inline)
|
|
|
|
|
|
|
|
return tg.UI{
|
|
|
|
kbd,
|
|
|
|
tg.Messagef("Use the reply keyboard to get back").Reply(
|
|
|
|
BackKeyboard.Reply(),
|
|
|
|
),
|
|
|
|
}
|
|
|
|
})
|