From 23d8742f0d95096b92f11729fb47f86ac3b68d43 Mon Sep 17 00:00:00 2001 From: Wim Date: Sat, 18 Jul 2020 17:27:41 +0200 Subject: Update dependencies for 1.18.0 release (#1175) --- .../telegram-bot-api/.travis.yml | 2 + .../go-telegram-bot-api/telegram-bot-api/README.md | 4 +- .../go-telegram-bot-api/telegram-bot-api/bot.go | 74 +++++++++--- .../telegram-bot-api/configs.go | 15 +++ .../go-telegram-bot-api/telegram-bot-api/go.mod | 5 + .../go-telegram-bot-api/telegram-bot-api/go.sum | 2 + .../telegram-bot-api/helpers.go | 17 ++- .../go-telegram-bot-api/telegram-bot-api/types.go | 124 +++++++++++++++++---- 8 files changed, 205 insertions(+), 38 deletions(-) create mode 100644 vendor/github.com/go-telegram-bot-api/telegram-bot-api/go.mod create mode 100644 vendor/github.com/go-telegram-bot-api/telegram-bot-api/go.sum (limited to 'vendor/github.com/go-telegram-bot-api') diff --git a/vendor/github.com/go-telegram-bot-api/telegram-bot-api/.travis.yml b/vendor/github.com/go-telegram-bot-api/telegram-bot-api/.travis.yml index 5769aa14..51865c84 100644 --- a/vendor/github.com/go-telegram-bot-api/telegram-bot-api/.travis.yml +++ b/vendor/github.com/go-telegram-bot-api/telegram-bot-api/.travis.yml @@ -3,4 +3,6 @@ language: go go: - '1.10' - '1.11' + - '1.12' + - '1.13' - tip diff --git a/vendor/github.com/go-telegram-bot-api/telegram-bot-api/README.md b/vendor/github.com/go-telegram-bot-api/telegram-bot-api/README.md index 93250611..43b33ed8 100644 --- a/vendor/github.com/go-telegram-bot-api/telegram-bot-api/README.md +++ b/vendor/github.com/go-telegram-bot-api/telegram-bot-api/README.md @@ -3,7 +3,7 @@ [![GoDoc](https://godoc.org/github.com/go-telegram-bot-api/telegram-bot-api?status.svg)](http://godoc.org/github.com/go-telegram-bot-api/telegram-bot-api) [![Travis](https://travis-ci.org/go-telegram-bot-api/telegram-bot-api.svg)](https://travis-ci.org/go-telegram-bot-api/telegram-bot-api) -All methods are fairly self explanatory, and reading the godoc page should +All methods are fairly self explanatory, and reading the [godoc](http://godoc.org/github.com/go-telegram-bot-api/telegram-bot-api) page should explain everything. If something isn't clear, open an issue or submit a pull request. @@ -63,7 +63,7 @@ func main() { ``` There are more examples on the [wiki](https://github.com/go-telegram-bot-api/telegram-bot-api/wiki) -with detailed information on how to do many differen kinds of things. +with detailed information on how to do many different kinds of things. It's a great place to get started on using keyboards, commands, or other kinds of reply markup. diff --git a/vendor/github.com/go-telegram-bot-api/telegram-bot-api/bot.go b/vendor/github.com/go-telegram-bot-api/telegram-bot-api/bot.go index 85e16c19..e6c2cc83 100644 --- a/vendor/github.com/go-telegram-bot-api/telegram-bot-api/bot.go +++ b/vendor/github.com/go-telegram-bot-api/telegram-bot-api/bot.go @@ -19,34 +19,50 @@ import ( "github.com/technoweenie/multipartstreamer" ) +type HttpClient interface { + Do(req *http.Request) (*http.Response, error) +} + // BotAPI allows you to interact with the Telegram Bot API. type BotAPI struct { Token string `json:"token"` Debug bool `json:"debug"` Buffer int `json:"buffer"` - Self User `json:"-"` - Client *http.Client `json:"-"` + Self User `json:"-"` + Client HttpClient `json:"-"` shutdownChannel chan interface{} + + apiEndpoint string } // NewBotAPI creates a new BotAPI instance. // // It requires a token, provided by @BotFather on Telegram. func NewBotAPI(token string) (*BotAPI, error) { - return NewBotAPIWithClient(token, &http.Client{}) + return NewBotAPIWithClient(token, APIEndpoint, &http.Client{}) +} + +// NewBotAPIWithAPIEndpoint creates a new BotAPI instance +// and allows you to pass API endpoint. +// +// It requires a token, provided by @BotFather on Telegram and API endpoint. +func NewBotAPIWithAPIEndpoint(token, apiEndpoint string) (*BotAPI, error) { + return NewBotAPIWithClient(token, apiEndpoint, &http.Client{}) } // NewBotAPIWithClient creates a new BotAPI instance // and allows you to pass a http.Client. // -// It requires a token, provided by @BotFather on Telegram. -func NewBotAPIWithClient(token string, client *http.Client) (*BotAPI, error) { +// It requires a token, provided by @BotFather on Telegram and API endpoint. +func NewBotAPIWithClient(token, apiEndpoint string, client HttpClient) (*BotAPI, error) { bot := &BotAPI{ - Token: token, - Client: client, - Buffer: 100, + Token: token, + Client: client, + Buffer: 100, shutdownChannel: make(chan interface{}), + + apiEndpoint: apiEndpoint, } self, err := bot.GetMe() @@ -59,11 +75,21 @@ func NewBotAPIWithClient(token string, client *http.Client) (*BotAPI, error) { return bot, nil } +func (b *BotAPI) SetAPIEndpoint(apiEndpoint string) { + b.apiEndpoint = apiEndpoint +} + // MakeRequest makes a request to a specific endpoint with our token. func (bot *BotAPI) MakeRequest(endpoint string, params url.Values) (APIResponse, error) { - method := fmt.Sprintf(APIEndpoint, bot.Token, endpoint) + method := fmt.Sprintf(bot.apiEndpoint, bot.Token, endpoint) - resp, err := bot.Client.PostForm(method, params) + req, err := http.NewRequest("POST", method, strings.NewReader(params.Encode())) + if err != nil { + return APIResponse{}, err + } + req.Header.Set("Content-Type", "application/x-www-form-urlencoded") + + resp, err := bot.Client.Do(req) if err != nil { return APIResponse{}, err } @@ -84,7 +110,7 @@ func (bot *BotAPI) MakeRequest(endpoint string, params url.Values) (APIResponse, if apiResp.Parameters != nil { parameters = *apiResp.Parameters } - return apiResp, Error{apiResp.Description, parameters} + return apiResp, &Error{Code: apiResp.ErrorCode, Message: apiResp.Description, ResponseParameters: parameters} } return apiResp, nil @@ -186,7 +212,7 @@ func (bot *BotAPI) UploadFile(endpoint string, params map[string]string, fieldna return APIResponse{}, errors.New(ErrBadFileType) } - method := fmt.Sprintf(APIEndpoint, bot.Token, endpoint) + method := fmt.Sprintf(bot.apiEndpoint, bot.Token, endpoint) req, err := http.NewRequest("POST", method, nil) if err != nil { @@ -430,7 +456,7 @@ func (bot *BotAPI) GetUpdates(config UpdateConfig) ([]Update, error) { // RemoveWebhook unsets the webhook. func (bot *BotAPI) RemoveWebhook() (APIResponse, error) { - return bot.MakeRequest("setWebhook", url.Values{}) + return bot.MakeRequest("deleteWebhook", url.Values{}) } // SetWebhook sets a webhook. @@ -487,10 +513,11 @@ func (bot *BotAPI) GetUpdatesChan(config UpdateConfig) (UpdatesChannel, error) { for { select { case <-bot.shutdownChannel: + close(ch) return default: } - + updates, err := bot.GetUpdates(config) if err != nil { log.Println(err) @@ -966,3 +993,22 @@ func (bot *BotAPI) DeleteChatPhoto(config DeleteChatPhotoConfig) (APIResponse, e return bot.MakeRequest(config.method(), v) } + +// GetStickerSet get a sticker set. +func (bot *BotAPI) GetStickerSet(config GetStickerSetConfig) (StickerSet, error) { + v, err := config.values() + if err != nil { + return StickerSet{}, err + } + bot.debugLog(config.method(), v, nil) + res, err := bot.MakeRequest(config.method(), v) + if err != nil { + return StickerSet{}, err + } + stickerSet := StickerSet{} + err = json.Unmarshal(res.Result, &stickerSet) + if err != nil { + return StickerSet{}, err + } + return stickerSet, nil +} diff --git a/vendor/github.com/go-telegram-bot-api/telegram-bot-api/configs.go b/vendor/github.com/go-telegram-bot-api/telegram-bot-api/configs.go index 181d4e43..a7052ddc 100644 --- a/vendor/github.com/go-telegram-bot-api/telegram-bot-api/configs.go +++ b/vendor/github.com/go-telegram-bot-api/telegram-bot-api/configs.go @@ -1262,3 +1262,18 @@ func (config DeleteChatPhotoConfig) values() (url.Values, error) { return v, nil } + +// GetStickerSetConfig contains information for get sticker set. +type GetStickerSetConfig struct { + Name string +} + +func (config GetStickerSetConfig) method() string { + return "getStickerSet" +} + +func (config GetStickerSetConfig) values() (url.Values, error) { + v := url.Values{} + v.Add("name", config.Name) + return v, nil +} diff --git a/vendor/github.com/go-telegram-bot-api/telegram-bot-api/go.mod b/vendor/github.com/go-telegram-bot-api/telegram-bot-api/go.mod new file mode 100644 index 00000000..7df46f4b --- /dev/null +++ b/vendor/github.com/go-telegram-bot-api/telegram-bot-api/go.mod @@ -0,0 +1,5 @@ +module github.com/go-telegram-bot-api/telegram-bot-api + +go 1.12 + +require github.com/technoweenie/multipartstreamer v1.0.1 diff --git a/vendor/github.com/go-telegram-bot-api/telegram-bot-api/go.sum b/vendor/github.com/go-telegram-bot-api/telegram-bot-api/go.sum new file mode 100644 index 00000000..86606006 --- /dev/null +++ b/vendor/github.com/go-telegram-bot-api/telegram-bot-api/go.sum @@ -0,0 +1,2 @@ +github.com/technoweenie/multipartstreamer v1.0.1 h1:XRztA5MXiR1TIRHxH2uNxXxaIkKQDeX7m2XsSOlQEnM= +github.com/technoweenie/multipartstreamer v1.0.1/go.mod h1:jNVxdtShOxzAsukZwTSw6MDx5eUJoiEBsSvzDU9uzog= diff --git a/vendor/github.com/go-telegram-bot-api/telegram-bot-api/helpers.go b/vendor/github.com/go-telegram-bot-api/telegram-bot-api/helpers.go index 3dabe11e..d2fb165a 100644 --- a/vendor/github.com/go-telegram-bot-api/telegram-bot-api/helpers.go +++ b/vendor/github.com/go-telegram-bot-api/telegram-bot-api/helpers.go @@ -29,7 +29,8 @@ func NewDeleteMessage(chatID int64, messageID int) DeleteMessageConfig { // NewMessageToChannel creates a new Message that is sent to a channel // by username. // -// username is the username of the channel, text is the message text. +// username is the username of the channel, text is the message text, +// and the username should be in the form of `@username`. func NewMessageToChannel(username string, text string) MessageConfig { return MessageConfig{ BaseChat: BaseChat{ @@ -604,6 +605,18 @@ func NewInlineQueryResultLocation(id, title string, latitude, longitude float64) } } +// NewInlineQueryResultVenue creates a new inline query venue. +func NewInlineQueryResultVenue(id, title, address string, latitude, longitude float64) InlineQueryResultVenue { + return InlineQueryResultVenue{ + Type: "venue", + ID: id, + Title: title, + Address: address, + Latitude: latitude, + Longitude: longitude, + } +} + // NewEditMessageText allows you to edit the text of a message. func NewEditMessageText(chatID int64, messageID int, text string) EditMessageTextConfig { return EditMessageTextConfig{ @@ -622,7 +635,7 @@ func NewEditMessageCaption(chatID int64, messageID int, caption string) EditMess ChatID: chatID, MessageID: messageID, }, - Caption: caption, + Caption: caption, } } diff --git a/vendor/github.com/go-telegram-bot-api/telegram-bot-api/types.go b/vendor/github.com/go-telegram-bot-api/telegram-bot-api/types.go index c6cd642f..6e295cab 100644 --- a/vendor/github.com/go-telegram-bot-api/telegram-bot-api/types.go +++ b/vendor/github.com/go-telegram-bot-api/telegram-bot-api/types.go @@ -64,6 +64,9 @@ type User struct { // It is normally a user's username, but falls back to a first/last // name as available. func (u *User) String() string { + if u == nil { + return "" + } if u.UserName != "" { return u.UserName } @@ -100,6 +103,7 @@ type Chat struct { Photo *ChatPhoto `json:"photo"` Description string `json:"description,omitempty"` // optional InviteLink string `json:"invite_link,omitempty"` // optional + PinnedMessage *Message `json:"pinned_message"` // optional } // IsPrivate returns if the Chat is a private conversation. @@ -142,6 +146,7 @@ type Message struct { EditDate int `json:"edit_date"` // optional Text string `json:"text"` // optional Entities *[]MessageEntity `json:"entities"` // optional + CaptionEntities *[]MessageEntity `json:"caption_entities"` // optional Audio *Audio `json:"audio"` // optional Document *Document `json:"document"` // optional Animation *ChatAnimation `json:"animation"` // optional @@ -183,7 +188,7 @@ func (m *Message) IsCommand() bool { } entity := (*m.Entities)[0] - return entity.Offset == 0 && entity.Type == "bot_command" + return entity.Offset == 0 && entity.IsCommand() } // Command checks if the message was a command and if it was, returns the @@ -249,12 +254,62 @@ type MessageEntity struct { } // ParseURL attempts to parse a URL contained within a MessageEntity. -func (entity MessageEntity) ParseURL() (*url.URL, error) { - if entity.URL == "" { +func (e MessageEntity) ParseURL() (*url.URL, error) { + if e.URL == "" { return nil, errors.New(ErrBadURL) } - return url.Parse(entity.URL) + return url.Parse(e.URL) +} + +// IsMention returns true if the type of the message entity is "mention" (@username). +func (e MessageEntity) IsMention() bool { + return e.Type == "mention" +} + +// IsHashtag returns true if the type of the message entity is "hashtag". +func (e MessageEntity) IsHashtag() bool { + return e.Type == "hashtag" +} + +// IsCommand returns true if the type of the message entity is "bot_command". +func (e MessageEntity) IsCommand() bool { + return e.Type == "bot_command" +} + +// IsUrl returns true if the type of the message entity is "url". +func (e MessageEntity) IsUrl() bool { + return e.Type == "url" +} + +// IsEmail returns true if the type of the message entity is "email". +func (e MessageEntity) IsEmail() bool { + return e.Type == "email" +} + +// IsBold returns true if the type of the message entity is "bold" (bold text). +func (e MessageEntity) IsBold() bool { + return e.Type == "bold" +} + +// IsItalic returns true if the type of the message entity is "italic" (italic text). +func (e MessageEntity) IsItalic() bool { + return e.Type == "italic" +} + +// IsCode returns true if the type of the message entity is "code" (monowidth string). +func (e MessageEntity) IsCode() bool { + return e.Type == "code" +} + +// IsPre returns true if the type of the message entity is "pre" (monowidth block). +func (e MessageEntity) IsPre() bool { + return e.Type == "pre" +} + +// IsTextLink returns true if the type of the message entity is "text_link" (clickable text URL). +func (e MessageEntity) IsTextLink() bool { + return e.Type == "text_link" } // PhotoSize contains information about photos. @@ -286,13 +341,23 @@ type Document struct { // Sticker contains information about a sticker. type Sticker struct { - FileID string `json:"file_id"` - Width int `json:"width"` - Height int `json:"height"` - Thumbnail *PhotoSize `json:"thumb"` // optional - Emoji string `json:"emoji"` // optional - FileSize int `json:"file_size"` // optional - SetName string `json:"set_name"` // optional + FileUniqueID string `json:"file_unique_id"` + FileID string `json:"file_id"` + Width int `json:"width"` + Height int `json:"height"` + Thumbnail *PhotoSize `json:"thumb"` // optional + Emoji string `json:"emoji"` // optional + FileSize int `json:"file_size"` // optional + SetName string `json:"set_name"` // optional + IsAnimated bool `json:"is_animated"` // optional +} + +type StickerSet struct { + Name string `json:"name"` + Title string `json:"title"` + IsAnimated bool `json:"is_animated"` + ContainsMasks bool `json:"contains_masks"` + Stickers []Sticker `json:"stickers"` } // ChatAnimation contains information about an animation. @@ -582,6 +647,7 @@ type InlineQueryResultPhoto struct { Title string `json:"title"` Description string `json:"description"` Caption string `json:"caption"` + ParseMode string `json:"parse_mode"` ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` InputMessageContent interface{} `json:"input_message_content,omitempty"` } @@ -601,15 +667,15 @@ type InlineQueryResultCachedPhoto struct { // InlineQueryResultGIF is an inline query response GIF. type InlineQueryResultGIF struct { - Type string `json:"type"` // required - ID string `json:"id"` // required - URL string `json:"gif_url"` // required - Width int `json:"gif_width"` - Height int `json:"gif_height"` - Duration int `json:"gif_duration"` - ThumbURL string `json:"thumb_url"` - Title string `json:"title"` - Caption string `json:"caption"` + Type string `json:"type"` // required + ID string `json:"id"` // required + URL string `json:"gif_url"` // required + ThumbURL string `json:"thumb_url"` // required + Width int `json:"gif_width,omitempty"` + Height int `json:"gif_height,omitempty"` + Duration int `json:"gif_duration,omitempty"` + Title string `json:"title,omitempty"` + Caption string `json:"caption,omitempty"` ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` InputMessageContent interface{} `json:"input_message_content,omitempty"` } @@ -775,6 +841,23 @@ type InlineQueryResultLocation struct { ThumbHeight int `json:"thumb_height"` } +// InlineQueryResultVenue is an inline query response venue. +type InlineQueryResultVenue struct { + Type string `json:"type"` // required + ID string `json:"id"` // required + Latitude float64 `json:"latitude"` // required + Longitude float64 `json:"longitude"` // required + Title string `json:"title"` // required + Address string `json:"address"` // required + FoursquareID string `json:"foursquare_id"` + FoursquareType string `json:"foursquare_type"` + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` + InputMessageContent interface{} `json:"input_message_content,omitempty"` + ThumbURL string `json:"thumb_url"` + ThumbWidth int `json:"thumb_width"` + ThumbHeight int `json:"thumb_height"` +} + // InlineQueryResultGame is an inline query response game. type InlineQueryResultGame struct { Type string `json:"type"` @@ -897,6 +980,7 @@ type PreCheckoutQuery struct { // Error is an error containing extra information returned by the Telegram API. type Error struct { + Code int Message string ResponseParameters } -- cgit v1.2.3