Fixed location button problems.

This commit is contained in:
Andrey Parhomenko 2023-09-19 15:21:33 +03:00
parent 5a590a3cd0
commit d99ea68198
5 changed files with 29 additions and 13 deletions

View file

@ -4,7 +4,7 @@ tmp_dir = "tmp"
[build]
args_bin = []
bin = "exe/test.exe"
bin = "exe/test"
cmd = "go build -o ./exe/ ./cmd/test"
delay = 0
@ -26,8 +26,8 @@ tmp_dir = "tmp"
poll_interval = 0
rerun = false
rerun_delay = 500
send_interrupt = true
stop_on_error = true
send_interrupt = false
stop_on_error = false
[color]
app = "red"

View file

@ -151,9 +151,9 @@ var beh = tg.NewBehaviour().
),
tg.NewScreen("start/send-location", tg.NewPage(
"Send your location and I will tell where you are!",
"",
).WithReply(
sendLocationKeyboard.Widget(""),
sendLocationKeyboard.Widget("Press the button to send your location!"),
).WithInline(
tg.NewKeyboard().Row(
tg.NewButton(

View file

@ -1,4 +1,4 @@
# got v0.1.0
# got v0.3.2
Go Telegram.

View file

@ -15,6 +15,16 @@ type Button struct {
type ButtonMap map[string]*Button
// Returns the only location button in the map.
func (btnMap ButtonMap) LocationButton() *Button {
for _, btn := range btnMap {
if btn.SendLocation {
return btn
}
}
return nil
}
// Represents the reply button row.
type ButtonRow []*Button

View file

@ -243,13 +243,23 @@ func (widget *ReplyKeyboardWidget) Filter(
if widget == nil {
return true
}
if u.Message == nil {
return true
}
_, ok := widget.ButtonMap()[u.Message.Text]
if !ok {
if u.Message.Location != nil {
locBtn := widget.ButtonMap().LocationButton()
if locBtn == nil {
return true
}
} else {
return true
}
}
return false
}
@ -261,15 +271,11 @@ func (widget *ReplyKeyboardWidget) Serve(
var btn *Button
text := u.Message.Text
btns := widget.ButtonMap()
btn, ok := btns[text]
if !ok {
if u.Message.Location != nil {
for _, b := range btns {
if b.SendLocation {
btn = b
ok = true
}
}
btn = btns.LocationButton()
}
}