Added more low level functions from tgbotapi.

This commit is contained in:
Andrey Parhomenko 2023-10-07 13:20:49 +03:00
parent 61cc2d1df1
commit 966f8ad752
3 changed files with 23 additions and 5 deletions

View file

@ -26,13 +26,23 @@ func (kbd *Keyboard) Row(btns ...*Button) *Keyboard {
if len(btns) < 1 {
return kbd
}
kbd.Rows = append(kbd.Rows, btns)
retBtns := []*Button{}
for _, btn := range btns {
if btn == nil {
continue
}
retBtns = append(retBtns, btn)
}
kbd.Rows = append(kbd.Rows, retBtns)
return kbd
}
// Adds buttons as one column list.
func (kbd *Keyboard) List(btns ...*Button) *Keyboard {
for _, btn := range btns {
if btn == nil {
continue
}
kbd.Rows = append(kbd.Rows, ButtonRow{btn})
}
return kbd
@ -78,6 +88,8 @@ func (kbd *Keyboard) Inline() *Inline {
func (kbd *Keyboard) Reply() *Reply {
ret := &Reply{}
ret.Keyboard = kbd
// it is used more often than not once.
ret.OneTime = true
return ret
}

View file

@ -7,7 +7,7 @@ import (
)
type Message = tgbotapi.Message
// Simple text message type.
// Simple text message component type.
type MessageCompo struct {
Message *Message
ParseMode string
@ -16,6 +16,7 @@ type MessageCompo struct {
var (
escapeRe = re.MustCompile(`([_*\[\]()~`+"`"+`>#+-=|{}.!])`)
NewRawMessage = tgbotapi.NewMessage
)
// Escape special characters in Markdown 2 and return the
@ -24,6 +25,8 @@ func Escape2(str string) string {
return string(escapeRe.ReplaceAll([]byte(str), []byte("\\$1")))
}
// Is only implemented to make it sendable and so we can put it
// return of rendering functions.
func (compo *MessageCompo) SetMessage(msg *Message) {
compo.Message = msg
}
@ -36,6 +39,7 @@ func NewMessage(text string) *MessageCompo {
return ret
}
// Return message with the specified parse mode.
func (msg *MessageCompo) withParseMode(mode string) *MessageCompo {
msg.ParseMode = mode
return msg
@ -97,9 +101,9 @@ func (config *MessageCompo) SendConfig(
}
// Empty serving to use messages in rendering.
func (compo *MessageCompo) Serve(c *Context) {
}
func (compo *MessageCompo) Serve(c *Context) {}
// Filter that skips everything. Messages cannot do anything with updates.
func (compo *MessageCompo) Filter(_ *Update) bool {
// Skip everything
return true

View file

@ -10,9 +10,11 @@ const (
ChannelSessionScope
)
type ChatId int64
// Represents unique value to identify chats.
// In fact is simply ID of the chat.
type SessionId int64
type SessionId = ChatId
// Convert the SessionId to Telegram API's type.
func (si SessionId) ToApi() int64 {