options: complete keyboard constructors

pull/300/head
Demian 4 years ago
parent c626aaabd5
commit 0b3082a091

@ -946,6 +946,7 @@ func (b *Bot) Notify(to Recipient, action ChatAction) error {
// requesting an address and the parameter is_flexible was specified.
//
// Usage:
//
// b.Ship(query) // OK
// b.Ship(query, opts...) // OK with options
// b.Ship(query, "Oops!") // Error message

@ -3,6 +3,7 @@ package telebot
import (
"encoding/json"
"fmt"
"strings"
)
// Option is a shortcut flag type for certain message features
@ -203,36 +204,45 @@ func (r *ReplyMarkup) Reply(rows ...row) {
r.ReplyKeyboard = replyKeys
}
func (r *ReplyMarkup) Text(unique, text string) Btn {
return Btn{Unique: unique, Text: text}
func (r *ReplyMarkup) Text(text string) Btn {
return Btn{Text: text}
}
func (r *ReplyMarkup) URL(unique, text, url string) Btn {
return Btn{Unique: unique, Text: text, URL: url}
func (r *ReplyMarkup) Contact(text string) Btn {
return Btn{Contact: true, Text: text}
}
func (r *ReplyMarkup) Query(unique string, text, query string) Btn {
return Btn{Unique: unique, Text: text, InlineQuery: query}
func (r *ReplyMarkup) Location(text string) Btn {
return Btn{Location: true, Text: text}
}
func (r *ReplyMarkup) QueryChat(unique string, text, query string) Btn {
return Btn{Unique: unique, Text: text, InlineQueryChat: query}
func (r *ReplyMarkup) Poll(text string, poll PollType) Btn {
return Btn{Poll: poll, Text: text}
}
func (r *ReplyMarkup) Login(unique, text string, login *Login) Btn {
return Btn{Unique: unique, Login: login, Text: text}
func (r *ReplyMarkup) Data(text, unique string, data ...string) Btn {
return Btn{
Unique: unique,
Text: text,
Data: strings.Join(data, "|"),
}
}
func (r *ReplyMarkup) Contact(text string) Btn {
return Btn{Contact: true, Text: text}
func (r *ReplyMarkup) URL(text, url string) Btn {
return Btn{Text: text, URL: url}
}
func (r *ReplyMarkup) Location(text string) Btn {
return Btn{Location: true, Text: text}
func (r *ReplyMarkup) Query(text, query string) Btn {
return Btn{Text: text, InlineQuery: query}
}
func (r *ReplyMarkup) QueryChat(text, query string) Btn {
return Btn{Text: text, InlineQueryChat: query}
}
func (r *ReplyMarkup) Poll(poll PollType) Btn {
return Btn{Poll: poll}
func (r *ReplyMarkup) Login(text string, login *Login) Btn {
return Btn{Login: login, Text: text}
}
// Btn is a constructor button, which will later become either a reply, or an inline button.
@ -250,10 +260,6 @@ type Btn struct {
}
func (b Btn) Inline() *InlineButton {
if b.Unique == "" {
return nil
}
return &InlineButton{
Unique: b.Unique,
Text: b.Text,
@ -261,7 +267,7 @@ func (b Btn) Inline() *InlineButton {
Data: b.Data,
InlineQuery: b.InlineQuery,
InlineQueryChat: b.InlineQueryChat,
Login: nil,
Login: b.Login,
}
}

Loading…
Cancel
Save