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

View file

@ -7,7 +7,7 @@ import (
) )
type Message = tgbotapi.Message type Message = tgbotapi.Message
// Simple text message type. // Simple text message component type.
type MessageCompo struct { type MessageCompo struct {
Message *Message Message *Message
ParseMode string ParseMode string
@ -16,6 +16,7 @@ type MessageCompo struct {
var ( var (
escapeRe = re.MustCompile(`([_*\[\]()~`+"`"+`>#+-=|{}.!])`) escapeRe = re.MustCompile(`([_*\[\]()~`+"`"+`>#+-=|{}.!])`)
NewRawMessage = tgbotapi.NewMessage
) )
// Escape special characters in Markdown 2 and return the // 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"))) 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) { func (compo *MessageCompo) SetMessage(msg *Message) {
compo.Message = msg compo.Message = msg
} }
@ -36,6 +39,7 @@ func NewMessage(text string) *MessageCompo {
return ret return ret
} }
// Return message with the specified parse mode.
func (msg *MessageCompo) withParseMode(mode string) *MessageCompo { func (msg *MessageCompo) withParseMode(mode string) *MessageCompo {
msg.ParseMode = mode msg.ParseMode = mode
return msg return msg
@ -97,9 +101,9 @@ func (config *MessageCompo) SendConfig(
} }
// Empty serving to use messages in rendering. // 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 { func (compo *MessageCompo) Filter(_ *Update) bool {
// Skip everything // Skip everything
return true return true

View file

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