From 0471ea91c75bb9b8914d7279726010d662f0c963 Mon Sep 17 00:00:00 2001 From: surdeus Date: Mon, 2 Oct 2023 21:45:21 +0300 Subject: [PATCH] Fixed string reading issues. --- tg/context.go | 12 ++++++++++-- tg/keyboard.go | 8 ++++++++ tg/message.go | 3 +++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/tg/context.go b/tg/context.go index 4a2a4d6..9003ae0 100644 --- a/tg/context.go +++ b/tg/context.go @@ -170,6 +170,9 @@ func (af ActionFunc) Act(c *Context) { // Changes screen of user to the Id one. func (c *Context) Go(pth Path, args ...any) error { + if pth == "-" { + pth = c.PrevPath() + } // Getting the screen and changing to // then executing its widget. if !pth.IsAbs() { @@ -244,7 +247,7 @@ func (c *Context) RunWidget(widget Widget, args ...any) *UpdateChan { } chns := make([]*UpdateChan, len(compos)) for i, compo := range compos { - chns[i] = c.RunCompo(compo) + chns[i] = c.RunCompo(compo, args...) } ret := NewUpdateChan() @@ -283,8 +286,13 @@ func (c *Context) RunWidget(widget Widget, args ...any) *UpdateChan { // Simple way to read strings for widgets. func (c *Context) ReadString(pref string, args ...any) string { var text string - c.Sendf(pref, args...) + if pref != "" { + c.Sendf(pref, args...) + } for u := range c.Input() { + if u == nil { + break + } if u.Message == nil { continue } diff --git a/tg/keyboard.go b/tg/keyboard.go index 21e50c5..ceb0282 100644 --- a/tg/keyboard.go +++ b/tg/keyboard.go @@ -30,6 +30,14 @@ func (kbd *Keyboard) Row(btns ...*Button) *Keyboard { return kbd } +// Adds buttons as one column list. +func (kbd *Keyboard) List(btns ...*Button) *Keyboard { + for _, btn := range btns { + kbd.Rows = append(kbd.Rows, ButtonRow{btn}) + } + return kbd +} + // Set the default action when no button provides // key to the data we got. func (kbd *Keyboard) WithAction(a Action) *Keyboard { diff --git a/tg/message.go b/tg/message.go index 3340634..4197ecd 100644 --- a/tg/message.go +++ b/tg/message.go @@ -2,6 +2,7 @@ package tg import ( tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" + //"strings" ) type Message = tgbotapi.Message @@ -75,6 +76,8 @@ func (config *MessageCompo) SendConfig( text = config.Text } + //text = strings.ReplaceAll(text, "-", "\\-") + msg := tgbotapi.NewMessage(c.Session.Id.ToApi(), text) ret.Message = &msg ret.Message.ParseMode = config.ParseMode