1
0

🐛 Fixed some bugs in helpers

This commit is contained in:
Maxim Lebedev 2017-10-09 10:55:33 +05:00
parent eee3982525
commit 2f41d11dff
No known key found for this signature in database
GPG Key ID: F8978F46FF0FFA4F

View File

@ -1,8 +1,11 @@
package telegram package telegram
import ( import (
"io/ioutil"
"log" "log"
"time" "time"
json "github.com/pquerna/ffjson/ffjson"
) )
func NewAnswerCallback(id string) *AnswerCallbackQueryParameters { func NewAnswerCallback(id string) *AnswerCallbackQueryParameters {
@ -48,61 +51,69 @@ func NewReplyKeyboard(rows ...[]KeyboardButton) *ReplyKeyboardMarkup {
return &ReplyKeyboardMarkup{Keyboard: keyboard, ResizeKeyboard: true} return &ReplyKeyboardMarkup{Keyboard: keyboard, ResizeKeyboard: true}
} }
func NewKeyboardButtonsRow(buttons ...KeyboardButton) []KeyboardButton { func NewReplyKeyboardRow(buttons ...KeyboardButton) []KeyboardButton {
var row []KeyboardButton var row []KeyboardButton
row = append(row, buttons...) row = append(row, buttons...)
return row return row
} }
func NewKeyboardButton(text string) *KeyboardButton { func NewReplyKeyboardButton(text string) KeyboardButton {
return &KeyboardButton{Text: text} return KeyboardButton{Text: text}
} }
func NewKeyboardButtonContact(text string) *KeyboardButton { func NewReplyKeyboardButtonContact(text string) KeyboardButton {
return &KeyboardButton{Text: text, RequestContact: true} return KeyboardButton{Text: text, RequestContact: true}
} }
func NewKeyboardButtonLocation(text string) *KeyboardButton { func NewReplyKeyboardButtonLocation(text string) KeyboardButton {
return &KeyboardButton{Text: text, RequestLocation: true} return KeyboardButton{Text: text, RequestLocation: true}
} }
func NewInlineKeyboard(buttons ...InlineKeyboardButton) []InlineKeyboardButton { func NewInlineKeyboard(rows ...[]InlineKeyboardButton) [][]InlineKeyboardButton {
var keyboard [][]InlineKeyboardButton
keyboard = append(keyboard, rows...)
return keyboard
}
func NewInlineKeyboardRow(buttons ...InlineKeyboardButton) []InlineKeyboardButton {
var row []InlineKeyboardButton var row []InlineKeyboardButton
row = append(row, buttons...) row = append(row, buttons...)
return row return row
} }
func NewInlineKeyboardButtonsRow(rows ...[]InlineKeyboardButton) *InlineKeyboardMarkup { func NewInlineKeyboardButton(text, data string) InlineKeyboardButton {
var keyboard [][]InlineKeyboardButton return InlineKeyboardButton{Text: text, CallbackData: data}
keyboard = append(keyboard, rows...)
return &InlineKeyboardMarkup{InlineKeyboard: keyboard}
} }
func NewInlineKeyboardButton(text, data string) *InlineKeyboardButton { func NewInlineKeyboardButtonURL(text, url string) InlineKeyboardButton {
return &InlineKeyboardButton{Text: text, CallbackData: data} return InlineKeyboardButton{Text: text, URL: url}
} }
func NewInlineKeyboardButtonURL(text, url string) *InlineKeyboardButton { func NewInlineKeyboardButtonSwitch(text, query string) InlineKeyboardButton {
return &InlineKeyboardButton{Text: text, URL: url} return InlineKeyboardButton{Text: text, SwitchInlineQuery: query}
} }
func NewInlineKeyboardButtonSwitch(text, query string) *InlineKeyboardButton { func NewInlineKeyboardButtonSwitchSelf(text, query string) InlineKeyboardButton {
return &InlineKeyboardButton{Text: text, SwitchInlineQuery: query} return InlineKeyboardButton{Text: text, SwitchInlineQueryCurrentChat: query}
} }
func NewInlineKeyboardButtonSwitchSelf(text, query string) *InlineKeyboardButton { func NewInlineKeyboardButtonGame(text string) InlineKeyboardButton {
return &InlineKeyboardButton{Text: text, SwitchInlineQueryCurrentChat: query} return InlineKeyboardButton{Text: text, CallbackGame: &CallbackGame{}}
} }
func NewInlineKeyboardButtonGame(text string) *InlineKeyboardButton { func NewInlineKeyboardButtonPay(text string) InlineKeyboardButton {
return &InlineKeyboardButton{Text: text, CallbackGame: &CallbackGame{}} return InlineKeyboardButton{Text: text, Pay: true}
}
func NewWebhook(url string, file *InputFile) *SetWebhookParameters {
return &SetWebhookParameters{URL: url, Certificate: file}
} }
func NewInlineKeyboardButtonPay(text string) *InlineKeyboardButton { func NewInlineKeyboardButtonPay(text string) *InlineKeyboardButton {
return &InlineKeyboardButton{Text: text, Pay: true} return &InlineKeyboardButton{Text: text, Pay: true}
} }
func (bot *Bot) NewUpdatesChannel(params *GetUpdatesParameters) chan *Update { func (bot *Bot) NewLongPollingChannel(params *GetUpdatesParameters) UpdatesChannel {
if params == nil { if params == nil {
params = &GetUpdatesParameters{ params = &GetUpdatesParameters{
Limit: 100, Limit: 100,