feat: added Update function to the MessageCompo.

This commit is contained in:
Andrey Parhomenko 2023-10-13 23:27:20 +03:00
parent 0a6e1d4d70
commit 32ec32e8c9
4 changed files with 34 additions and 1 deletions

View file

@ -184,6 +184,7 @@ WithInitFunc(func(c *tg.Context) {
"inc-dec", tg.RenderFunc(func(c *tg.Context) tg.UI { "inc-dec", tg.RenderFunc(func(c *tg.Context) tg.UI {
var ( var (
kbd *tg.InlineCompo kbd *tg.InlineCompo
//cntMsg *tg.MessageCompo
inline, std, onlyInc, onlyDec *tg.Inline inline, std, onlyInc, onlyDec *tg.Inline
) )
@ -226,6 +227,7 @@ WithInitFunc(func(c *tg.Context) {
inline = std inline = std
} }
kbd = tg.NewMessage( kbd = tg.NewMessage(
fmt.Sprintf(format, d.Counter), fmt.Sprintf(format, d.Counter),
).Inline(inline) ).Inline(inline)
@ -316,6 +318,9 @@ WithUsage(tg.Func(func(c *tg.Context){
), ),
) )
})), })),
tg.NewCommand("invoice", "invoice check").
WithAction(tg.Func(func(c *tg.Context){
})),
)) ))
func main() { func main() {
log.Println(beh.Screens) log.Println(beh.Screens)

View file

@ -46,7 +46,8 @@ func (compo *InlineCompo) Update(c *Context) {
compo.Text, compo.Text,
compo.Inline.ToApi(), compo.Inline.ToApi(),
) )
c.Bot.Api.Send(edit) msg, _ := c.Bot.Api.Send(edit)
compo.Message = &msg
} }
// Implementing the Filterer interface. // Implementing the Filterer interface.

17
tg/invoice.go Normal file
View file

@ -0,0 +1,17 @@
package tg
import (
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
)
type InvoiceCompo struct {
*MessageCompo
tgbotapi.InvoiceConfig
}
func (compo *InvoiceCompo) SendConfig(
sid SessionId, bot *Bot,
) (*SendConfig) {
return nil
}

View file

@ -25,6 +25,16 @@ func Escape2(str string) string {
return string(escapeRe.ReplaceAll([]byte(str), []byte("\\$1"))) return string(escapeRe.ReplaceAll([]byte(str), []byte("\\$1")))
} }
func (compo *MessageCompo) Update(c *Context) {
edit := tgbotapi.NewEditMessageText(
c.Session.Id.ToApi(),
compo.Message.MessageID,
compo.Text,
)
msg, _ := c.Bot.Api.Send(edit)
compo.Message = &msg
}
// Is only implemented to make it sendable and so we can put it // Is only implemented to make it sendable and so we can put it
// return of rendering functions. // return of rendering functions.
func (compo *MessageCompo) SetMessage(msg *Message) { func (compo *MessageCompo) SetMessage(msg *Message) {