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

View file

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

View file

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

View file

@ -15,6 +15,16 @@ type Button struct {
type ButtonMap map[string]*Button 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. // Represents the reply button row.
type ButtonRow []*Button type ButtonRow []*Button

View file

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