From 273b48a8b409126e14f8beb23cee4255d1f08a2c Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Fri, 19 Oct 2018 06:24:23 -0700 Subject: GOPROXY means we can avoid vendoring --- .../telegram-bot-api/.gitignore | 2 - .../telegram-bot-api/.travis.yml | 5 - .../telegram-bot-api/LICENSE.txt | 21 - .../go-telegram-bot-api/telegram-bot-api/README.md | 118 -- .../go-telegram-bot-api/telegram-bot-api/bot.go | 952 ---------------- .../telegram-bot-api/configs.go | 1145 -------------------- .../telegram-bot-api/helpers.go | 686 ------------ .../go-telegram-bot-api/telegram-bot-api/types.go | 783 ------------- 8 files changed, 3712 deletions(-) delete mode 100644 vendor/github.com/go-telegram-bot-api/telegram-bot-api/.gitignore delete mode 100644 vendor/github.com/go-telegram-bot-api/telegram-bot-api/.travis.yml delete mode 100644 vendor/github.com/go-telegram-bot-api/telegram-bot-api/LICENSE.txt delete mode 100644 vendor/github.com/go-telegram-bot-api/telegram-bot-api/README.md delete mode 100644 vendor/github.com/go-telegram-bot-api/telegram-bot-api/bot.go delete mode 100644 vendor/github.com/go-telegram-bot-api/telegram-bot-api/configs.go delete mode 100644 vendor/github.com/go-telegram-bot-api/telegram-bot-api/helpers.go delete mode 100644 vendor/github.com/go-telegram-bot-api/telegram-bot-api/types.go (limited to 'vendor/github.com/go-telegram-bot-api/telegram-bot-api') diff --git a/vendor/github.com/go-telegram-bot-api/telegram-bot-api/.gitignore b/vendor/github.com/go-telegram-bot-api/telegram-bot-api/.gitignore deleted file mode 100644 index aa7ac80..0000000 --- a/vendor/github.com/go-telegram-bot-api/telegram-bot-api/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -.idea/ -coverage.out 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 deleted file mode 100644 index 8408fb7..0000000 --- a/vendor/github.com/go-telegram-bot-api/telegram-bot-api/.travis.yml +++ /dev/null @@ -1,5 +0,0 @@ -language: go - -go: - - 1.4 - - tip \ No newline at end of file diff --git a/vendor/github.com/go-telegram-bot-api/telegram-bot-api/LICENSE.txt b/vendor/github.com/go-telegram-bot-api/telegram-bot-api/LICENSE.txt deleted file mode 100644 index b1fef93..0000000 --- a/vendor/github.com/go-telegram-bot-api/telegram-bot-api/LICENSE.txt +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2015 Syfaro - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. 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 deleted file mode 100644 index d9a6873..0000000 --- a/vendor/github.com/go-telegram-bot-api/telegram-bot-api/README.md +++ /dev/null @@ -1,118 +0,0 @@ -# Golang bindings for the Telegram Bot API - -[![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 have been added, and all features should be available. -If you want a feature that hasn't been added yet or something is broken, -open an issue and I'll see what I can do. - -All methods are fairly self explanatory, and reading the godoc page should -explain everything. If something isn't clear, open an issue or submit -a pull request. - -The scope of this project is just to provide a wrapper around the API -without any additional features. There are other projects for creating -something with plugins and command handlers without having to design -all that yourself. - -Use `github.com/go-telegram-bot-api/telegram-bot-api` for the latest -version, or use `gopkg.in/telegram-bot-api.v4` for the stable build. - -Join [the development group](https://telegram.me/go_telegram_bot_api) if -you want to ask questions or discuss development. - -## Example - -This is a very simple bot that just displays any gotten updates, -then replies it to that chat. - -```go -package main - -import ( - "log" - "gopkg.in/telegram-bot-api.v4" -) - -func main() { - bot, err := tgbotapi.NewBotAPI("MyAwesomeBotToken") - if err != nil { - log.Panic(err) - } - - bot.Debug = true - - log.Printf("Authorized on account %s", bot.Self.UserName) - - u := tgbotapi.NewUpdate(0) - u.Timeout = 60 - - updates, err := bot.GetUpdatesChan(u) - - for update := range updates { - if update.Message == nil { - continue - } - - log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text) - - msg := tgbotapi.NewMessage(update.Message.Chat.ID, update.Message.Text) - msg.ReplyToMessageID = update.Message.MessageID - - bot.Send(msg) - } -} -``` - -If you need to use webhooks (if you wish to run on Google App Engine), -you may use a slightly different method. - -```go -package main - -import ( - "gopkg.in/telegram-bot-api.v4" - "log" - "net/http" -) - -func main() { - bot, err := tgbotapi.NewBotAPI("MyAwesomeBotToken") - if err != nil { - log.Fatal(err) - } - - bot.Debug = true - - log.Printf("Authorized on account %s", bot.Self.UserName) - - _, err = bot.SetWebhook(tgbotapi.NewWebhookWithCert("https://www.google.com:8443/"+bot.Token, "cert.pem")) - if err != nil { - log.Fatal(err) - } - info, err := bot.GetWebhookInfo() - if err != nil { - log.Fatal(err) - } - if info.LastErrorDate != 0 { - log.Printf("[Telegram callback failed]%s", info.LastErrorMessage) - } - updates := bot.ListenForWebhook("/" + bot.Token) - go http.ListenAndServeTLS("0.0.0.0:8443", "cert.pem", "key.pem", nil) - - for update := range updates { - log.Printf("%+v\n", update) - } -} -``` - -If you need, you may generate a self signed certficate, as this requires -HTTPS / TLS. The above example tells Telegram that this is your -certificate and that it should be trusted, even though it is not -properly signed. - - openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 3560 -subj "//O=Org\CN=Test" -nodes - -Now that [Let's Encrypt](https://letsencrypt.org) has entered public beta, -you may wish to generate your free TLS certificate there. 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 deleted file mode 100644 index 8fb6200..0000000 --- a/vendor/github.com/go-telegram-bot-api/telegram-bot-api/bot.go +++ /dev/null @@ -1,952 +0,0 @@ -// Package tgbotapi has functions and types used for interacting with -// the Telegram Bot API. -package tgbotapi - -import ( - "bytes" - "encoding/json" - "errors" - "fmt" - "io" - "io/ioutil" - "log" - "net/http" - "net/url" - "os" - "strconv" - "strings" - "time" - - "github.com/technoweenie/multipartstreamer" -) - -// 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:"-"` -} - -// 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{}) -} - -// 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) { - bot := &BotAPI{ - Token: token, - Client: client, - Buffer: 100, - } - - self, err := bot.GetMe() - if err != nil { - return nil, err - } - - bot.Self = self - - return bot, nil -} - -// 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) - - resp, err := bot.Client.PostForm(method, params) - if err != nil { - return APIResponse{}, err - } - defer resp.Body.Close() - - var apiResp APIResponse - bytes, err := bot.decodeAPIResponse(resp.Body, &apiResp) - if err != nil { - return apiResp, err - } - - if bot.Debug { - log.Printf("%s resp: %s", endpoint, bytes) - } - - if !apiResp.Ok { - parameters := ResponseParameters{} - if apiResp.Parameters != nil { - parameters = *apiResp.Parameters - } - return apiResp, Error{apiResp.Description, parameters} - } - - return apiResp, nil -} - -// decodeAPIResponse decode response and return slice of bytes if debug enabled. -// If debug disabled, just decode http.Response.Body stream to APIResponse struct -// for efficient memory usage -func (bot *BotAPI) decodeAPIResponse(responseBody io.Reader, resp *APIResponse) (_ []byte, err error) { - if !bot.Debug { - dec := json.NewDecoder(responseBody) - err = dec.Decode(resp) - return - } - - // if debug, read reponse body - data, err := ioutil.ReadAll(responseBody) - if err != nil { - return - } - - err = json.Unmarshal(data, resp) - if err != nil { - return - } - - return data, nil -} - -// makeMessageRequest makes a request to a method that returns a Message. -func (bot *BotAPI) makeMessageRequest(endpoint string, params url.Values) (Message, error) { - resp, err := bot.MakeRequest(endpoint, params) - if err != nil { - return Message{}, err - } - - var message Message - json.Unmarshal(resp.Result, &message) - - bot.debugLog(endpoint, params, message) - - return message, nil -} - -// UploadFile makes a request to the API with a file. -// -// Requires the parameter to hold the file not be in the params. -// File should be a string to a file path, a FileBytes struct, -// a FileReader struct, or a url.URL. -// -// Note that if your FileReader has a size set to -1, it will read -// the file into memory to calculate a size. -func (bot *BotAPI) UploadFile(endpoint string, params map[string]string, fieldname string, file interface{}) (APIResponse, error) { - ms := multipartstreamer.New() - - switch f := file.(type) { - case string: - ms.WriteFields(params) - - fileHandle, err := os.Open(f) - if err != nil { - return APIResponse{}, err - } - defer fileHandle.Close() - - fi, err := os.Stat(f) - if err != nil { - return APIResponse{}, err - } - - ms.WriteReader(fieldname, fileHandle.Name(), fi.Size(), fileHandle) - case FileBytes: - ms.WriteFields(params) - - buf := bytes.NewBuffer(f.Bytes) - ms.WriteReader(fieldname, f.Name, int64(len(f.Bytes)), buf) - case FileReader: - ms.WriteFields(params) - - if f.Size != -1 { - ms.WriteReader(fieldname, f.Name, f.Size, f.Reader) - - break - } - - data, err := ioutil.ReadAll(f.Reader) - if err != nil { - return APIResponse{}, err - } - - buf := bytes.NewBuffer(data) - - ms.WriteReader(fieldname, f.Name, int64(len(data)), buf) - case url.URL: - params[fieldname] = f.String() - - ms.WriteFields(params) - default: - return APIResponse{}, errors.New(ErrBadFileType) - } - - method := fmt.Sprintf(APIEndpoint, bot.Token, endpoint) - - req, err := http.NewRequest("POST", method, nil) - if err != nil { - return APIResponse{}, err - } - - ms.SetupRequest(req) - - res, err := bot.Client.Do(req) - if err != nil { - return APIResponse{}, err - } - defer res.Body.Close() - - bytes, err := ioutil.ReadAll(res.Body) - if err != nil { - return APIResponse{}, err - } - - if bot.Debug { - log.Println(string(bytes)) - } - - var apiResp APIResponse - - err = json.Unmarshal(bytes, &apiResp) - if err != nil { - return APIResponse{}, err - } - - if !apiResp.Ok { - return APIResponse{}, errors.New(apiResp.Description) - } - - return apiResp, nil -} - -// GetFileDirectURL returns direct URL to file -// -// It requires the FileID. -func (bot *BotAPI) GetFileDirectURL(fileID string) (string, error) { - file, err := bot.GetFile(FileConfig{fileID}) - - if err != nil { - return "", err - } - - return file.Link(bot.Token), nil -} - -// GetMe fetches the currently authenticated bot. -// -// This method is called upon creation to validate the token, -// and so you may get this data from BotAPI.Self without the need for -// another request. -func (bot *BotAPI) GetMe() (User, error) { - resp, err := bot.MakeRequest("getMe", nil) - if err != nil { - return User{}, err - } - - var user User - json.Unmarshal(resp.Result, &user) - - bot.debugLog("getMe", nil, user) - - return user, nil -} - -// IsMessageToMe returns true if message directed to this bot. -// -// It requires the Message. -func (bot *BotAPI) IsMessageToMe(message Message) bool { - return strings.Contains(message.Text, "@"+bot.Self.UserName) -} - -// Send will send a Chattable item to Telegram. -// -// It requires the Chattable to send. -func (bot *BotAPI) Send(c Chattable) (Message, error) { - switch c.(type) { - case Fileable: - return bot.sendFile(c.(Fileable)) - default: - return bot.sendChattable(c) - } -} - -// debugLog checks if the bot is currently running in debug mode, and if -// so will display information about the request and response in the -// debug log. -func (bot *BotAPI) debugLog(context string, v url.Values, message interface{}) { - if bot.Debug { - log.Printf("%s req : %+v\n", context, v) - log.Printf("%s resp: %+v\n", context, message) - } -} - -// sendExisting will send a Message with an existing file to Telegram. -func (bot *BotAPI) sendExisting(method string, config Fileable) (Message, error) { - v, err := config.values() - - if err != nil { - return Message{}, err - } - - message, err := bot.makeMessageRequest(method, v) - if err != nil { - return Message{}, err - } - - return message, nil -} - -// uploadAndSend will send a Message with a new file to Telegram. -func (bot *BotAPI) uploadAndSend(method string, config Fileable) (Message, error) { - params, err := config.params() - if err != nil { - return Message{}, err - } - - file := config.getFile() - - resp, err := bot.UploadFile(method, params, config.name(), file) - if err != nil { - return Message{}, err - } - - var message Message - json.Unmarshal(resp.Result, &message) - - bot.debugLog(method, nil, message) - - return message, nil -} - -// sendFile determines if the file is using an existing file or uploading -// a new file, then sends it as needed. -func (bot *BotAPI) sendFile(config Fileable) (Message, error) { - if config.useExistingFile() { - return bot.sendExisting(config.method(), config) - } - - return bot.uploadAndSend(config.method(), config) -} - -// sendChattable sends a Chattable. -func (bot *BotAPI) sendChattable(config Chattable) (Message, error) { - v, err := config.values() - if err != nil { - return Message{}, err - } - - message, err := bot.makeMessageRequest(config.method(), v) - - if err != nil { - return Message{}, err - } - - return message, nil -} - -// GetUserProfilePhotos gets a user's profile photos. -// -// It requires UserID. -// Offset and Limit are optional. -func (bot *BotAPI) GetUserProfilePhotos(config UserProfilePhotosConfig) (UserProfilePhotos, error) { - v := url.Values{} - v.Add("user_id", strconv.Itoa(config.UserID)) - if config.Offset != 0 { - v.Add("offset", strconv.Itoa(config.Offset)) - } - if config.Limit != 0 { - v.Add("limit", strconv.Itoa(config.Limit)) - } - - resp, err := bot.MakeRequest("getUserProfilePhotos", v) - if err != nil { - return UserProfilePhotos{}, err - } - - var profilePhotos UserProfilePhotos - json.Unmarshal(resp.Result, &profilePhotos) - - bot.debugLog("GetUserProfilePhoto", v, profilePhotos) - - return profilePhotos, nil -} - -// GetFile returns a File which can download a file from Telegram. -// -// Requires FileID. -func (bot *BotAPI) GetFile(config FileConfig) (File, error) { - v := url.Values{} - v.Add("file_id", config.FileID) - - resp, err := bot.MakeRequest("getFile", v) - if err != nil { - return File{}, err - } - - var file File - json.Unmarshal(resp.Result, &file) - - bot.debugLog("GetFile", v, file) - - return file, nil -} - -// GetUpdates fetches updates. -// If a WebHook is set, this will not return any data! -// -// Offset, Limit, and Timeout are optional. -// To avoid stale items, set Offset to one higher than the previous item. -// Set Timeout to a large number to reduce requests so you can get updates -// instantly instead of having to wait between requests. -func (bot *BotAPI) GetUpdates(config UpdateConfig) ([]Update, error) { - v := url.Values{} - if config.Offset != 0 { - v.Add("offset", strconv.Itoa(config.Offset)) - } - if config.Limit > 0 { - v.Add("limit", strconv.Itoa(config.Limit)) - } - if config.Timeout > 0 { - v.Add("timeout", strconv.Itoa(config.Timeout)) - } - - resp, err := bot.MakeRequest("getUpdates", v) - if err != nil { - return []Update{}, err - } - - var updates []Update - json.Unmarshal(resp.Result, &updates) - - bot.debugLog("getUpdates", v, updates) - - return updates, nil -} - -// RemoveWebhook unsets the webhook. -func (bot *BotAPI) RemoveWebhook() (APIResponse, error) { - return bot.MakeRequest("setWebhook", url.Values{}) -} - -// SetWebhook sets a webhook. -// -// If this is set, GetUpdates will not get any data! -// -// If you do not have a legitimate TLS certificate, you need to include -// your self signed certificate with the config. -func (bot *BotAPI) SetWebhook(config WebhookConfig) (APIResponse, error) { - - if config.Certificate == nil { - v := url.Values{} - v.Add("url", config.URL.String()) - if config.MaxConnections != 0 { - v.Add("max_connections", strconv.Itoa(config.MaxConnections)) - } - - return bot.MakeRequest("setWebhook", v) - } - - params := make(map[string]string) - params["url"] = config.URL.String() - if config.MaxConnections != 0 { - params["max_connections"] = strconv.Itoa(config.MaxConnections) - } - - resp, err := bot.UploadFile("setWebhook", params, "certificate", config.Certificate) - if err != nil { - return APIResponse{}, err - } - - return resp, nil -} - -// GetWebhookInfo allows you to fetch information about a webhook and if -// one currently is set, along with pending update count and error messages. -func (bot *BotAPI) GetWebhookInfo() (WebhookInfo, error) { - resp, err := bot.MakeRequest("getWebhookInfo", url.Values{}) - if err != nil { - return WebhookInfo{}, err - } - - var info WebhookInfo - err = json.Unmarshal(resp.Result, &info) - - return info, err -} - -// GetUpdatesChan starts and returns a channel for getting updates. -func (bot *BotAPI) GetUpdatesChan(config UpdateConfig) (UpdatesChannel, error) { - ch := make(chan Update, bot.Buffer) - - go func() { - for { - updates, err := bot.GetUpdates(config) - if err != nil { - log.Println(err) - log.Println("Failed to get updates, retrying in 3 seconds...") - time.Sleep(time.Second * 3) - - continue - } - - for _, update := range updates { - if update.UpdateID >= config.Offset { - config.Offset = update.UpdateID + 1 - ch <- update - } - } - } - }() - - return ch, nil -} - -// ListenForWebhook registers a http handler for a webhook. -func (bot *BotAPI) ListenForWebhook(pattern string) UpdatesChannel { - ch := make(chan Update, bot.Buffer) - - http.HandleFunc(pattern, func(w http.ResponseWriter, r *http.Request) { - bytes, _ := ioutil.ReadAll(r.Body) - - var update Update - json.Unmarshal(bytes, &update) - - ch <- update - }) - - return ch -} - -// AnswerInlineQuery sends a response to an inline query. -// -// Note that you must respond to an inline query within 30 seconds. -func (bot *BotAPI) AnswerInlineQuery(config InlineConfig) (APIResponse, error) { - v := url.Values{} - - v.Add("inline_query_id", config.InlineQueryID) - v.Add("cache_time", strconv.Itoa(config.CacheTime)) - v.Add("is_personal", strconv.FormatBool(config.IsPersonal)) - v.Add("next_offset", config.NextOffset) - data, err := json.Marshal(config.Results) - if err != nil { - return APIResponse{}, err - } - v.Add("results", string(data)) - v.Add("switch_pm_text", config.SwitchPMText) - v.Add("switch_pm_parameter", config.SwitchPMParameter) - - bot.debugLog("answerInlineQuery", v, nil) - - return bot.MakeRequest("answerInlineQuery", v) -} - -// AnswerCallbackQuery sends a response to an inline query callback. -func (bot *BotAPI) AnswerCallbackQuery(config CallbackConfig) (APIResponse, error) { - v := url.Values{} - - v.Add("callback_query_id", config.CallbackQueryID) - if config.Text != "" { - v.Add("text", config.Text) - } - v.Add("show_alert", strconv.FormatBool(config.ShowAlert)) - if config.URL != "" { - v.Add("url", config.URL) - } - v.Add("cache_time", strconv.Itoa(config.CacheTime)) - - bot.debugLog("answerCallbackQuery", v, nil) - - return bot.MakeRequest("answerCallbackQuery", v) -} - -// KickChatMember kicks a user from a chat. Note that this only will work -// in supergroups, and requires the bot to be an admin. Also note they -// will be unable to rejoin until they are unbanned. -func (bot *BotAPI) KickChatMember(config KickChatMemberConfig) (APIResponse, error) { - v := url.Values{} - - if config.SuperGroupUsername == "" { - v.Add("chat_id", strconv.FormatInt(config.ChatID, 10)) - } else { - v.Add("chat_id", config.SuperGroupUsername) - } - v.Add("user_id", strconv.Itoa(config.UserID)) - - if config.UntilDate != 0 { - v.Add("until_date", strconv.FormatInt(config.UntilDate, 10)) - } - - bot.debugLog("kickChatMember", v, nil) - - return bot.MakeRequest("kickChatMember", v) -} - -// LeaveChat makes the bot leave the chat. -func (bot *BotAPI) LeaveChat(config ChatConfig) (APIResponse, error) { - v := url.Values{} - - if config.SuperGroupUsername == "" { - v.Add("chat_id", strconv.FormatInt(config.ChatID, 10)) - } else { - v.Add("chat_id", config.SuperGroupUsername) - } - - bot.debugLog("leaveChat", v, nil) - - return bot.MakeRequest("leaveChat", v) -} - -// GetChat gets information about a chat. -func (bot *BotAPI) GetChat(config ChatConfig) (Chat, error) { - v := url.Values{} - - if config.SuperGroupUsername == "" { - v.Add("chat_id", strconv.FormatInt(config.ChatID, 10)) - } else { - v.Add("chat_id", config.SuperGroupUsername) - } - - resp, err := bot.MakeRequest("getChat", v) - if err != nil { - return Chat{}, err - } - - var chat Chat - err = json.Unmarshal(resp.Result, &chat) - - bot.debugLog("getChat", v, chat) - - return chat, err -} - -// GetChatAdministrators gets a list of administrators in the chat. -// -// If none have been appointed, only the creator will be returned. -// Bots are not shown, even if they are an administrator. -func (bot *BotAPI) GetChatAdministrators(config ChatConfig) ([]ChatMember, error) { - v := url.Values{} - - if config.SuperGroupUsername == "" { - v.Add("chat_id", strconv.FormatInt(config.ChatID, 10)) - } else { - v.Add("chat_id", config.SuperGroupUsername) - } - - resp, err := bot.MakeRequest("getChatAdministrators", v) - if err != nil { - return []ChatMember{}, err - } - - var members []ChatMember - err = json.Unmarshal(resp.Result, &members) - - bot.debugLog("getChatAdministrators", v, members) - - return members, err -} - -// GetChatMembersCount gets the number of users in a chat. -func (bot *BotAPI) GetChatMembersCount(config ChatConfig) (int, error) { - v := url.Values{} - - if config.SuperGroupUsername == "" { - v.Add("chat_id", strconv.FormatInt(config.ChatID, 10)) - } else { - v.Add("chat_id", config.SuperGroupUsername) - } - - resp, err := bot.MakeRequest("getChatMembersCount", v) - if err != nil { - return -1, err - } - - var count int - err = json.Unmarshal(resp.Result, &count) - - bot.debugLog("getChatMembersCount", v, count) - - return count, err -} - -// GetChatMember gets a specific chat member. -func (bot *BotAPI) GetChatMember(config ChatConfigWithUser) (ChatMember, error) { - v := url.Values{} - - if config.SuperGroupUsername == "" { - v.Add("chat_id", strconv.FormatInt(config.ChatID, 10)) - } else { - v.Add("chat_id", config.SuperGroupUsername) - } - v.Add("user_id", strconv.Itoa(config.UserID)) - - resp, err := bot.MakeRequest("getChatMember", v) - if err != nil { - return ChatMember{}, err - } - - var member ChatMember - err = json.Unmarshal(resp.Result, &member) - - bot.debugLog("getChatMember", v, member) - - return member, err -} - -// UnbanChatMember unbans a user from a chat. Note that this only will work -// in supergroups and channels, and requires the bot to be an admin. -func (bot *BotAPI) UnbanChatMember(config ChatMemberConfig) (APIResponse, error) { - v := url.Values{} - - if config.SuperGroupUsername != "" { - v.Add("chat_id", config.SuperGroupUsername) - } else if config.ChannelUsername != "" { - v.Add("chat_id", config.ChannelUsername) - } else { - v.Add("chat_id", strconv.FormatInt(config.ChatID, 10)) - } - v.Add("user_id", strconv.Itoa(config.UserID)) - - bot.debugLog("unbanChatMember", v, nil) - - return bot.MakeRequest("unbanChatMember", v) -} - -// RestrictChatMember to restrict a user in a supergroup. The bot must be an -//administrator in the supergroup for this to work and must have the -//appropriate admin rights. Pass True for all boolean parameters to lift -//restrictions from a user. Returns True on success. -func (bot *BotAPI) RestrictChatMember(config RestrictChatMemberConfig) (APIResponse, error) { - v := url.Values{} - - if config.SuperGroupUsername != "" { - v.Add("chat_id", config.SuperGroupUsername) - } else if config.ChannelUsername != "" { - v.Add("chat_id", config.ChannelUsername) - } else { - v.Add("chat_id", strconv.FormatInt(config.ChatID, 10)) - } - v.Add("user_id", strconv.Itoa(config.UserID)) - - if config.CanSendMessages != nil { - v.Add("can_send_messages", strconv.FormatBool(*config.CanSendMessages)) - } - if config.CanSendMediaMessages != nil { - v.Add("can_send_media_messages", strconv.FormatBool(*config.CanSendMediaMessages)) - } - if config.CanSendOtherMessages != nil { - v.Add("can_send_other_messages", strconv.FormatBool(*config.CanSendOtherMessages)) - } - if config.CanAddWebPagePreviews != nil { - v.Add("can_add_web_page_previews", strconv.FormatBool(*config.CanAddWebPagePreviews)) - } - if config.UntilDate != 0 { - v.Add("until_date", strconv.FormatInt(config.UntilDate, 10)) - } - - bot.debugLog("restrictChatMember", v, nil) - - return bot.MakeRequest("restrictChatMember", v) -} - -// PromoteChatMember add admin rights to user -func (bot *BotAPI) PromoteChatMember(config PromoteChatMemberConfig) (APIResponse, error) { - v := url.Values{} - - if config.SuperGroupUsername != "" { - v.Add("chat_id", config.SuperGroupUsername) - } else if config.ChannelUsername != "" { - v.Add("chat_id", config.ChannelUsername) - } else { - v.Add("chat_id", strconv.FormatInt(config.ChatID, 10)) - } - v.Add("user_id", strconv.Itoa(config.UserID)) - - if config.CanChangeInfo != nil { - v.Add("can_change_info", strconv.FormatBool(*config.CanChangeInfo)) - } - if config.CanPostMessages != nil { - v.Add("can_post_messages", strconv.FormatBool(*config.CanPostMessages)) - } - if config.CanEditMessages != nil { - v.Add("can_edit_messages", strconv.FormatBool(*config.CanEditMessages)) - } - if config.CanDeleteMessages != nil { - v.Add("can_delete_messages", strconv.FormatBool(*config.CanDeleteMessages)) - } - if config.CanInviteUsers != nil { - v.Add("can_invite_users", strconv.FormatBool(*config.CanInviteUsers)) - } - if config.CanRestrictMembers != nil { - v.Add("can_restrict_members", strconv.FormatBool(*config.CanRestrictMembers)) - } - if config.CanPinMessages != nil { - v.Add("can_pin_messages", strconv.FormatBool(*config.CanPinMessages)) - } - if config.CanPromoteMembers != nil { - v.Add("can_promote_members", strconv.FormatBool(*config.CanPromoteMembers)) - } - - bot.debugLog("promoteChatMember", v, nil) - - return bot.MakeRequest("promoteChatMember", v) -} - -// GetGameHighScores allows you to get the high scores for a game. -func (bot *BotAPI) GetGameHighScores(config GetGameHighScoresConfig) ([]GameHighScore, error) { - v, _ := config.values() - - resp, err := bot.MakeRequest(config.method(), v) - if err != nil { - return []GameHighScore{}, err - } - - var highScores []GameHighScore - err = json.Unmarshal(resp.Result, &highScores) - - return highScores, err -} - -// AnswerShippingQuery allows you to reply to Update with shipping_query parameter. -func (bot *BotAPI) AnswerShippingQuery(config ShippingConfig) (APIResponse, error) { - v := url.Values{} - - v.Add("shipping_query_id", config.ShippingQueryID) - v.Add("ok", strconv.FormatBool(config.OK)) - if config.OK == true { - data, err := json.Marshal(config.ShippingOptions) - if err != nil { - return APIResponse{}, err - } - v.Add("shipping_options", string(data)) - } else { - v.Add("error_message", config.ErrorMessage) - } - - bot.debugLog("answerShippingQuery", v, nil) - - return bot.MakeRequest("answerShippingQuery", v) -} - -// AnswerPreCheckoutQuery allows you to reply to Update with pre_checkout_query. -func (bot *BotAPI) AnswerPreCheckoutQuery(config PreCheckoutConfig) (APIResponse, error) { - v := url.Values{} - - v.Add("pre_checkout_query_id", config.PreCheckoutQueryID) - v.Add("ok", strconv.FormatBool(config.OK)) - if config.OK != true { - v.Add("error", config.ErrorMessage) - } - - bot.debugLog("answerPreCheckoutQuery", v, nil) - - return bot.MakeRequest("answerPreCheckoutQuery", v) -} - -// DeleteMessage deletes a message in a chat -func (bot *BotAPI) DeleteMessage(config DeleteMessageConfig) (APIResponse, error) { - v, err := config.values() - if err != nil { - return APIResponse{}, err - } - - bot.debugLog(config.method(), v, nil) - - return bot.MakeRequest(config.method(), v) -} - -// GetInviteLink get InviteLink for a chat -func (bot *BotAPI) GetInviteLink(config ChatConfig) (string, error) { - v := url.Values{} - - if config.SuperGroupUsername == "" { - v.Add("chat_id", strconv.FormatInt(config.ChatID, 10)) - } else { - v.Add("chat_id", config.SuperGroupUsername) - } - - resp, err := bot.MakeRequest("exportChatInviteLink", v) - if err != nil { - return "", err - } - - var inviteLink string - err = json.Unmarshal(resp.Result, &inviteLink) - - return inviteLink, err -} - -// PinChatMessage pin message in supergroup -func (bot *BotAPI) PinChatMessage(config PinChatMessageConfig) (APIResponse, error) { - v, err := config.values() - if err != nil { - return APIResponse{}, err - } - - bot.debugLog(config.method(), v, nil) - - return bot.MakeRequest(config.method(), v) -} - -// UnpinChatMessage unpin message in supergroup -func (bot *BotAPI) UnpinChatMessage(config UnpinChatMessageConfig) (APIResponse, error) { - v, err := config.values() - if err != nil { - return APIResponse{}, err - } - - bot.debugLog(config.method(), v, nil) - - return bot.MakeRequest(config.method(), v) -} - -// SetChatTitle change title of chat. -func (bot *BotAPI) SetChatTitle(config SetChatTitleConfig) (APIResponse, error) { - v, err := config.values() - if err != nil { - return APIResponse{}, err - } - - bot.debugLog(config.method(), v, nil) - - return bot.MakeRequest(config.method(), v) -} - -// SetChatDescription change description of chat. -func (bot *BotAPI) SetChatDescription(config SetChatDescriptionConfig) (APIResponse, error) { - v, err := config.values() - if err != nil { - return APIResponse{}, err - } - - bot.debugLog(config.method(), v, nil) - - return bot.MakeRequest(config.method(), v) -} - -// SetChatPhoto change photo of chat. -func (bot *BotAPI) SetChatPhoto(config SetChatPhotoConfig) (APIResponse, error) { - params, err := config.params() - if err != nil { - return APIResponse{}, err - } - - file := config.getFile() - - return bot.UploadFile(config.method(), params, config.name(), file) -} - -// DeleteChatPhoto delete photo of chat. -func (bot *BotAPI) DeleteChatPhoto(config DeleteChatPhotoConfig) (APIResponse, error) { - v, err := config.values() - if err != nil { - return APIResponse{}, err - } - - bot.debugLog(config.method(), v, nil) - - return bot.MakeRequest(config.method(), v) -} 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 deleted file mode 100644 index 574b3dd..0000000 --- a/vendor/github.com/go-telegram-bot-api/telegram-bot-api/configs.go +++ /dev/null @@ -1,1145 +0,0 @@ -package tgbotapi - -import ( - "encoding/json" - "io" - "net/url" - "strconv" -) - -// Telegram constants -const ( - // APIEndpoint is the endpoint for all API methods, - // with formatting for Sprintf. - APIEndpoint = "https://api.telegram.org/bot%s/%s" - // FileEndpoint is the endpoint for downloading a file from Telegram. - FileEndpoint = "https://api.telegram.org/file/bot%s/%s" -) - -// Constant values for ChatActions -const ( - ChatTyping = "typing" - ChatUploadPhoto = "upload_photo" - ChatRecordVideo = "record_video" - ChatUploadVideo = "upload_video" - ChatRecordAudio = "record_audio" - ChatUploadAudio = "upload_audio" - ChatUploadDocument = "upload_document" - ChatFindLocation = "find_location" -) - -// API errors -const ( - // ErrAPIForbidden happens when a token is bad - ErrAPIForbidden = "forbidden" -) - -// Constant values for ParseMode in MessageConfig -const ( - ModeMarkdown = "Markdown" - ModeHTML = "HTML" -) - -// Library errors -const ( - // ErrBadFileType happens when you pass an unknown type - ErrBadFileType = "bad file type" - ErrBadURL = "bad or empty url" -) - -// Chattable is any config type that can be sent. -type Chattable interface { - values() (url.Values, error) - method() string -} - -// Fileable is any config type that can be sent that includes a file. -type Fileable interface { - Chattable - params() (map[string]string, error) - name() string - getFile() interface{} - useExistingFile() bool -} - -// BaseChat is base type for all chat config types. -type BaseChat struct { - ChatID int64 // required - ChannelUsername string - ReplyToMessageID int - ReplyMarkup interface{} - DisableNotification bool -} - -// values returns url.Values representation of BaseChat -func (chat *BaseChat) values() (url.Values, error) { - v := url.Values{} - if chat.ChannelUsername != "" { - v.Add("chat_id", chat.ChannelUsername) - } else { - v.Add("chat_id", strconv.FormatInt(chat.ChatID, 10)) - } - - if chat.ReplyToMessageID != 0 { - v.Add("reply_to_message_id", strconv.Itoa(chat.ReplyToMessageID)) - } - - if chat.ReplyMarkup != nil { - data, err := json.Marshal(chat.ReplyMarkup) - if err != nil { - return v, err - } - - v.Add("reply_markup", string(data)) - } - - v.Add("disable_notification", strconv.FormatBool(chat.DisableNotification)) - - return v, nil -} - -// BaseFile is a base type for all file config types. -type BaseFile struct { - BaseChat - File interface{} - FileID string - UseExisting bool - MimeType string - FileSize int -} - -// params returns a map[string]string representation of BaseFile. -func (file BaseFile) params() (map[string]string, error) { - params := make(map[string]string) - - if file.ChannelUsername != "" { - params["chat_id"] = file.ChannelUsername - } else { - params["chat_id"] = strconv.FormatInt(file.ChatID, 10) - } - - if file.ReplyToMessageID != 0 { - params["reply_to_message_id"] = strconv.Itoa(file.ReplyToMessageID) - } - - if file.ReplyMarkup != nil { - data, err := json.Marshal(file.ReplyMarkup) - if err != nil { - return params, err - } - - params["reply_markup"] = string(data) - } - - if file.MimeType != "" { - params["mime_type"] = file.MimeType - } - - if file.FileSize > 0 { - params["file_size"] = strconv.Itoa(file.FileSize) - } - - params["disable_notification"] = strconv.FormatBool(file.DisableNotification) - - return params, nil -} - -// getFile returns the file. -func (file BaseFile) getFile() interface{} { - return file.File -} - -// useExistingFile returns if the BaseFile has already been uploaded. -func (file BaseFile) useExistingFile() bool { - return file.UseExisting -} - -// BaseEdit is base type of all chat edits. -type BaseEdit struct { - ChatID int64 - ChannelUsername string - MessageID int - InlineMessageID string - ReplyMarkup *InlineKeyboardMarkup -} - -func (edit BaseEdit) values() (url.Values, error) { - v := url.Values{} - - if edit.InlineMessageID == "" { - if edit.ChannelUsername != "" { - v.Add("chat_id", edit.ChannelUsername) - } else { - v.Add("chat_id", strconv.FormatInt(edit.ChatID, 10)) - } - v.Add("message_id", strconv.Itoa(edit.MessageID)) - } else { - v.Add("inline_message_id", edit.InlineMessageID) - } - - if edit.ReplyMarkup != nil { - data, err := json.Marshal(edit.ReplyMarkup) - if err != nil { - return v, err - } - v.Add("reply_markup", string(data)) - } - - return v, nil -} - -// MessageConfig contains information about a SendMessage request. -type MessageConfig struct { - BaseChat - Text string - ParseMode string - DisableWebPagePreview bool -} - -// values returns a url.Values representation of MessageConfig. -func (config MessageConfig) values() (url.Values, error) { - v, err := config.BaseChat.values() - if err != nil { - return v, err - } - v.Add("text", config.Text) - v.Add("disable_web_page_preview", strconv.FormatBool(config.DisableWebPagePreview)) - if config.ParseMode != "" { - v.Add("parse_mode", config.ParseMode) - } - - return v, nil -} - -// method returns Telegram API method name for sending Message. -func (config MessageConfig) method() string { - return "sendMessage" -} - -// ForwardConfig contains information about a ForwardMessage request. -type ForwardConfig struct { - BaseChat - FromChatID int64 // required - FromChannelUsername string - MessageID int // required -} - -// values returns a url.Values representation of ForwardConfig. -func (config ForwardConfig) values() (url.Values, error) { - v, err := config.BaseChat.values() - if err != nil { - return v, err - } - v.Add("from_chat_id", strconv.FormatInt(config.FromChatID, 10)) - v.Add("message_id", strconv.Itoa(config.MessageID)) - return v, nil -} - -// method returns Telegram API method name for sending Forward. -func (config ForwardConfig) method() string { - return "forwardMessage" -} - -// PhotoConfig contains information about a SendPhoto request. -type PhotoConfig struct { - BaseFile - Caption string -} - -// Params returns a map[string]string representation of PhotoConfig. -func (config PhotoConfig) params() (map[string]string, error) { - params, _ := config.BaseFile.params() - - if config.Caption != "" { - params["caption"] = config.Caption - } - - return params, nil -} - -// Values returns a url.Values representation of PhotoConfig. -func (config PhotoConfig) values() (url.Values, error) { - v, err := config.BaseChat.values() - if err != nil { - return v, err - } - - v.Add(config.name(), config.FileID) - if config.Caption != "" { - v.Add("caption", config.Caption) - } - return v, nil -} - -// name returns the field name for the Photo. -func (config PhotoConfig) name() string { - return "photo" -} - -// method returns Telegram API method name for sending Photo. -func (config PhotoConfig) method() string { - return "sendPhoto" -} - -// AudioConfig contains information about a SendAudio request. -type AudioConfig struct { - BaseFile - Caption string - Duration int - Performer string - Title string -} - -// values returns a url.Values representation of AudioConfig. -func (config AudioConfig) values() (url.Values, error) { - v, err := config.BaseChat.values() - if err != nil { - return v, err - } - - v.Add(config.name(), config.FileID) - if config.Duration != 0 { - v.Add("duration", strconv.Itoa(config.Duration)) - } - - if config.Performer != "" { - v.Add("performer", config.Performer) - } - if config.Title != "" { - v.Add("title", config.Title) - } - if config.Caption != "" { - v.Add("caption", config.Caption) - } - - return v, nil -} - -// params returns a map[string]string representation of AudioConfig. -func (config AudioConfig) params() (map[string]string, error) { - params, _ := config.BaseFile.params() - - if config.Duration != 0 { - params["duration"] = strconv.Itoa(config.Duration) - } - - if config.Performer != "" { - params["performer"] = config.Performer - } - if config.Title != "" { - params["title"] = config.Title - } - if config.Caption != "" { - params["caption"] = config.Caption - } - - return params, nil -} - -// name returns the field name for the Audio. -func (config AudioConfig) name() string { - return "audio" -} - -// method returns Telegram API method name for sending Audio. -func (config AudioConfig) method() string { - return "sendAudio" -} - -// DocumentConfig contains information about a SendDocument request. -type DocumentConfig struct { - BaseFile - Caption string -} - -// values returns a url.Values representation of DocumentConfig. -func (config DocumentConfig) values() (url.Values, error) { - v, err := config.BaseChat.values() - if err != nil { - return v, err - } - - v.Add(config.name(), config.FileID) - if config.Caption != "" { - v.Add("caption", config.Caption) - } - - return v, nil -} - -// params returns a map[string]string representation of DocumentConfig. -func (config DocumentConfig) params() (map[string]string, error) { - params, _ := config.BaseFile.params() - - if config.Caption != "" { - params["caption"] = config.Caption - } - - return params, nil -} - -// name returns the field name for the Document. -func (config DocumentConfig) name() string { - return "document" -} - -// method returns Telegram API method name for sending Document. -func (config DocumentConfig) method() string { - return "sendDocument" -} - -// StickerConfig contains information about a SendSticker request. -type StickerConfig struct { - BaseFile -} - -// values returns a url.Values representation of StickerConfig. -func (config StickerConfig) values() (url.Values, error) { - v, err := config.BaseChat.values() - if err != nil { - return v, err - } - - v.Add(config.name(), config.FileID) - - return v, nil -} - -// params returns a map[string]string representation of StickerConfig. -func (config StickerConfig) params() (map[string]string, error) { - params, _ := config.BaseFile.params() - - return params, nil -} - -// name returns the field name for the Sticker. -func (config StickerConfig) name() string { - return "sticker" -} - -// method returns Telegram API method name for sending Sticker. -func (config StickerConfig) method() string { - return "sendSticker" -} - -// VideoConfig contains information about a SendVideo request. -type VideoConfig struct { - BaseFile - Duration int - Caption string -} - -// values returns a url.Values representation of VideoConfig. -func (config VideoConfig) values() (url.Values, error) { - v, err := config.BaseChat.values() - if err != nil { - return v, err - } - - v.Add(config.name(), config.FileID) - if config.Duration != 0 { - v.Add("duration", strconv.Itoa(config.Duration)) - } - if config.Caption != "" { - v.Add("caption", config.Caption) - } - - return v, nil -} - -// params returns a map[string]string representation of VideoConfig. -func (config VideoConfig) params() (map[string]string, error) { - params, _ := config.BaseFile.params() - - if config.Caption != "" { - params["caption"] = config.Caption - } - - return params, nil -} - -// name returns the field name for the Video. -func (config VideoConfig) name() string { - return "video" -} - -// method returns Telegram API method name for sending Video. -func (config VideoConfig) method() string { - return "sendVideo" -} - -// VideoNoteConfig contains information about a SendVideoNote request. -type VideoNoteConfig struct { - BaseFile - Duration int - Length int -} - -// values returns a url.Values representation of VideoNoteConfig. -func (config VideoNoteConfig) values() (url.Values, error) { - v, err := config.BaseChat.values() - if err != nil { - return v, err - } - - v.Add(config.name(), config.FileID) - if config.Duration != 0 { - v.Add("duration", strconv.Itoa(config.Duration)) - } - - // Telegram API seems to have a bug, if no length is provided or it is 0, it will send an error response - if config.Length != 0 { - v.Add("length", strconv.Itoa(config.Length)) - } - - return v, nil -} - -// params returns a map[string]string representation of VideoNoteConfig. -func (config VideoNoteConfig) params() (map[string]string, error) { - params, _ := config.BaseFile.params() - - if config.Length != 0 { - params["length"] = strconv.Itoa(config.Length) - } - if config.Duration != 0 { - params["duration"] = strconv.Itoa(config.Duration) - } - - return params, nil -} - -// name returns the field name for the VideoNote. -func (config VideoNoteConfig) name() string { - return "video_note" -} - -// method returns Telegram API method name for sending VideoNote. -func (config VideoNoteConfig) method() string { - return "sendVideoNote" -} - -// VoiceConfig contains information about a SendVoice request. -type VoiceConfig struct { - BaseFile - Caption string - Duration int -} - -// values returns a url.Values representation of VoiceConfig. -func (config VoiceConfig) values() (url.Values, error) { - v, err := config.BaseChat.values() - if err != nil { - return v, err - } - - v.Add(config.name(), config.FileID) - if config.Duration != 0 { - v.Add("duration", strconv.Itoa(config.Duration)) - } - if config.Caption != "" { - v.Add("caption", config.Caption) - } - - return v, nil -} - -// params returns a map[string]string representation of VoiceConfig. -func (config VoiceConfig) params() (map[string]string, error) { - params, _ := config.BaseFile.params() - - if config.Duration != 0 { - params["duration"] = strconv.Itoa(config.Duration) - } - if config.Caption != "" { - params["caption"] = config.Caption - } - - return params, nil -} - -// name returns the field name for the Voice. -func (config VoiceConfig) name() string { - return "voice" -} - -// method returns Telegram API method name for sending Voice. -func (config VoiceConfig) method() string { - return "sendVoice" -} - -// LocationConfig contains information about a SendLocation request. -type LocationConfig struct { - BaseChat - Latitude float64 // required - Longitude float64 // required -} - -// values returns a url.Values representation of LocationConfig. -func (config LocationConfig) values() (url.Values, error) { - v, err := config.BaseChat.values() - if err != nil { - return v, err - } - - v.Add("latitude", strconv.FormatFloat(config.Latitude, 'f', 6, 64)) - v.Add("longitude", strconv.FormatFloat(config.Longitude, 'f', 6, 64)) - - return v, nil -} - -// method returns Telegram API method name for sending Location. -func (config LocationConfig) method() string { - return "sendLocation" -} - -// VenueConfig contains information about a SendVenue request. -type VenueConfig struct { - BaseChat - Latitude float64 // required - Longitude float64 // required - Title string // required - Address string // required - FoursquareID string -} - -func (config VenueConfig) values() (url.Values, error) { - v, err := config.BaseChat.values() - if err != nil { - return v, err - } - - v.Add("latitude", strconv.FormatFloat(config.Latitude, 'f', 6, 64)) - v.Add("longitude", strconv.FormatFloat(config.Longitude, 'f', 6, 64)) - v.Add("title", config.Title) - v.Add("address", config.Address) - if config.FoursquareID != "" { - v.Add("foursquare_id", config.FoursquareID) - } - - return v, nil -} - -func (config VenueConfig) method() string { - return "sendVenue" -} - -// ContactConfig allows you to send a contact. -type ContactConfig struct { - BaseChat - PhoneNumber string - FirstName string - LastName string -} - -func (config ContactConfig) values() (url.Values, error) { - v, err := config.BaseChat.values() - if err != nil { - return v, err - } - - v.Add("phone_number", config.PhoneNumber) - v.Add("first_name", config.FirstName) - v.Add("last_name", config.LastName) - - return v, nil -} - -func (config ContactConfig) method() string { - return "sendContact" -} - -// GameConfig allows you to send a game. -type GameConfig struct { - BaseChat - GameShortName string -} - -func (config GameConfig) values() (url.Values, error) { - v, err := config.BaseChat.values() - if err != nil { - return v, err - } - - v.Add("game_short_name", config.GameShortName) - - return v, nil -} - -func (config GameConfig) method() string { - return "sendGame" -} - -// SetGameScoreConfig allows you to update the game score in a chat. -type SetGameScoreConfig struct { - UserID int - Score int - Force bool - DisableEditMessage bool - ChatID int64 - ChannelUsername string - MessageID int - InlineMessageID string -} - -func (config SetGameScoreConfig) values() (url.Values, error) { - v := url.Values{} - - v.Add("user_id", strconv.Itoa(config.UserID)) - v.Add("score", strconv.Itoa(config.Score)) - if config.InlineMessageID == "" { - if config.ChannelUsername == "" { - v.Add("chat_id", strconv.FormatInt(config.ChatID, 10)) - } else { - v.Add("chat_id", config.ChannelUsername) - } - v.Add("message_id", strconv.Itoa(config.MessageID)) - } else { - v.Add("inline_message_id", config.InlineMessageID) - } - v.Add("disable_edit_message", strconv.FormatBool(config.DisableEditMessage)) - - return v, nil -} - -func (config SetGameScoreConfig) method() string { - return "setGameScore" -} - -// GetGameHighScoresConfig allows you to fetch the high scores for a game. -type GetGameHighScoresConfig struct { - UserID int - ChatID int - ChannelUsername string - MessageID int - InlineMessageID string -} - -func (config GetGameHighScoresConfig) values() (url.Values, error) { - v := url.Values{} - - v.Add("user_id", strconv.Itoa(config.UserID)) - if config.InlineMessageID == "" { - if config.ChannelUsername == "" { - v.Add("chat_id", strconv.Itoa(config.ChatID)) - } else { - v.Add("chat_id", config.ChannelUsername) - } - v.Add("message_id", strconv.Itoa(config.MessageID)) - } else { - v.Add("inline_message_id", config.InlineMessageID) - } - - return v, nil -} - -func (config GetGameHighScoresConfig) method() string { - return "getGameHighScores" -} - -// ChatActionConfig contains information about a SendChatAction request. -type ChatActionConfig struct { - BaseChat - Action string // required -} - -// values returns a url.Values representation of ChatActionConfig. -func (config ChatActionConfig) values() (url.Values, error) { - v, err := config.BaseChat.values() - if err != nil { - return v, err - } - v.Add("action", config.Action) - return v, nil -} - -// method returns Telegram API method name for sending ChatAction. -func (config ChatActionConfig) method() string { - return "sendChatAction" -} - -// EditMessageTextConfig allows you to modify the text in a message. -type EditMessageTextConfig struct { - BaseEdit - Text string - ParseMode string - DisableWebPagePreview bool -} - -func (config EditMessageTextConfig) values() (url.Values, error) { - v, err := config.BaseEdit.values() - if err != nil { - return v, err - } - - v.Add("text", config.Text) - v.Add("parse_mode", config.ParseMode) - v.Add("disable_web_page_preview", strconv.FormatBool(config.DisableWebPagePreview)) - - return v, nil -} - -func (config EditMessageTextConfig) method() string { - return "editMessageText" -} - -// EditMessageCaptionConfig allows you to modify the caption of a message. -type EditMessageCaptionConfig struct { - BaseEdit - Caption string -} - -func (config EditMessageCaptionConfig) values() (url.Values, error) { - v, _ := config.BaseEdit.values() - - v.Add("caption", config.Caption) - - return v, nil -} - -func (config EditMessageCaptionConfig) method() string { - return "editMessageCaption" -} - -// EditMessageReplyMarkupConfig allows you to modify the reply markup -// of a message. -type EditMessageReplyMarkupConfig struct { - BaseEdit -} - -func (config EditMessageReplyMarkupConfig) values() (url.Values, error) { - return config.BaseEdit.values() -} - -func (config EditMessageReplyMarkupConfig) method() string { - return "editMessageReplyMarkup" -} - -// UserProfilePhotosConfig contains information about a -// GetUserProfilePhotos request. -type UserProfilePhotosConfig struct { - UserID int - Offset int - Limit int -} - -// FileConfig has information about a file hosted on Telegram. -type FileConfig struct { - FileID string -} - -// UpdateConfig contains information about a GetUpdates request. -type UpdateConfig struct { - Offset int - Limit int - Timeout int -} - -// WebhookConfig contains information about a SetWebhook request. -type WebhookConfig struct { - URL *url.URL - Certificate interface{} - MaxConnections int -} - -// FileBytes contains information about a set of bytes to upload -// as a File. -type FileBytes struct { - Name string - Bytes []byte -} - -// FileReader contains information about a reader to upload as a File. -// If Size is -1, it will read the entire Reader into memory to -// calculate a Size. -type FileReader struct { - Name string - Reader io.Reader - Size int64 -} - -// InlineConfig contains information on making an InlineQuery response. -type InlineConfig struct { - InlineQueryID string `json:"inline_query_id"` - Results []interface{} `json:"results"` - CacheTime int `json:"cache_time"` - IsPersonal bool `json:"is_personal"` - NextOffset string `json:"next_offset"` - SwitchPMText string `json:"switch_pm_text"` - SwitchPMParameter string `json:"switch_pm_parameter"` -} - -// CallbackConfig contains information on making a CallbackQuery response. -type CallbackConfig struct { - CallbackQueryID string `json:"callback_query_id"` - Text string `json:"text"` - ShowAlert bool `json:"show_alert"` - URL string `json:"url"` - CacheTime int `json:"cache_time"` -} - -// ChatMemberConfig contains information about a user in a chat for use -// with administrative functions such as kicking or unbanning a user. -type ChatMemberConfig struct { - ChatID int64 - SuperGroupUsername string - ChannelUsername string - UserID int -} - -// KickChatMemberConfig contains extra fields to kick user -type KickChatMemberConfig struct { - ChatMemberConfig - UntilDate int64 -} - -// RestrictChatMemberConfig contains fields to restrict members of chat -type RestrictChatMemberConfig struct { - ChatMemberConfig - UntilDate int64 - CanSendMessages *bool - CanSendMediaMessages *bool - CanSendOtherMessages *bool - CanAddWebPagePreviews *bool -} - -// PromoteChatMemberConfig contains fields to promote members of chat -type PromoteChatMemberConfig struct { - ChatMemberConfig - CanChangeInfo *bool - CanPostMessages *bool - CanEditMessages *bool - CanDeleteMessages *bool - CanInviteUsers *bool - CanRestrictMembers *bool - CanPinMessages *bool - CanPromoteMembers *bool -} - -// ChatConfig contains information about getting information on a chat. -type ChatConfig struct { - ChatID int64 - SuperGroupUsername string -} - -// ChatConfigWithUser contains information about getting information on -// a specific user within a chat. -type ChatConfigWithUser struct { - ChatID int64 - SuperGroupUsername string - UserID int -} - -// InvoiceConfig contains information for sendInvoice request. -type InvoiceConfig struct { - BaseChat - Title string // required - Description string // required - Payload string // required - ProviderToken string // required - StartParameter string // required - Currency string // required - Prices *[]LabeledPrice // required - PhotoURL string - PhotoSize int - PhotoWidth int - PhotoHeight int - NeedName bool - NeedPhoneNumber bool - NeedEmail bool - NeedShippingAddress bool - IsFlexible bool -} - -func (config InvoiceConfig) values() (url.Values, error) { - v, err := config.BaseChat.values() - if err != nil { - return v, err - } - v.Add("title", config.Title) - v.Add("description", config.Description) - v.Add("payload", config.Payload) - v.Add("provider_token", config.ProviderToken) - v.Add("start_parameter", config.StartParameter) - v.Add("currency", config.Currency) - data, err := json.Marshal(config.Prices) - if err != nil { - return v, err - } - v.Add("prices", string(data)) - if config.PhotoURL != "" { - v.Add("photo_url", config.PhotoURL) - } - if config.PhotoSize != 0 { - v.Add("photo_size", strconv.Itoa(config.PhotoSize)) - } - if config.PhotoWidth != 0 { - v.Add("photo_width", strconv.Itoa(config.PhotoWidth)) - } - if config.PhotoHeight != 0 { - v.Add("photo_height", strconv.Itoa(config.PhotoHeight)) - } - if config.NeedName != false { - v.Add("need_name", strconv.FormatBool(config.NeedName)) - } - if config.NeedPhoneNumber != false { - v.Add("need_phone_number", strconv.FormatBool(config.NeedPhoneNumber)) - } - if config.NeedEmail != false { - v.Add("need_email", strconv.FormatBool(config.NeedEmail)) - } - if config.NeedShippingAddress != false { - v.Add("need_shipping_address", strconv.FormatBool(config.NeedShippingAddress)) - } - if config.IsFlexible != false { - v.Add("is_flexible", strconv.FormatBool(config.IsFlexible)) - } - - return v, nil -} - -func (config InvoiceConfig) method() string { - return "sendInvoice" -} - -// ShippingConfig contains information for answerShippingQuery request. -type ShippingConfig struct { - ShippingQueryID string // required - OK bool // required - ShippingOptions *[]ShippingOption - ErrorMessage string -} - -// PreCheckoutConfig conatins information for answerPreCheckoutQuery request. -type PreCheckoutConfig struct { - PreCheckoutQueryID string // required - OK bool // required - ErrorMessage string -} - -// DeleteMessageConfig contains information of a message in a chat to delete. -type DeleteMessageConfig struct { - ChatID int64 - MessageID int -} - -func (config DeleteMessageConfig) method() string { - return "deleteMessage" -} - -func (config DeleteMessageConfig) values() (url.Values, error) { - v := url.Values{} - - v.Add("chat_id", strconv.FormatInt(config.ChatID, 10)) - v.Add("message_id", strconv.Itoa(config.MessageID)) - - return v, nil -} - -// PinChatMessageConfig contains information of a message in a chat to pin. -type PinChatMessageConfig struct { - ChatID int64 - MessageID int - DisableNotification bool -} - -func (config PinChatMessageConfig) method() string { - return "pinChatMessage" -} - -func (config PinChatMessageConfig) values() (url.Values, error) { - v := url.Values{} - - v.Add("chat_id", strconv.FormatInt(config.ChatID, 10)) - v.Add("message_id", strconv.Itoa(config.MessageID)) - v.Add("disable_notification", strconv.FormatBool(config.DisableNotification)) - - return v, nil -} - -// UnpinChatMessageConfig contains information of chat to unpin. -type UnpinChatMessageConfig struct { - ChatID int64 -} - -func (config UnpinChatMessageConfig) method() string { - return "unpinChatMessage" -} - -func (config UnpinChatMessageConfig) values() (url.Values, error) { - v := url.Values{} - - v.Add("chat_id", strconv.FormatInt(config.ChatID, 10)) - - return v, nil -} - -// SetChatTitleConfig contains information for change chat title. -type SetChatTitleConfig struct { - ChatID int64 - Title string -} - -func (config SetChatTitleConfig) method() string { - return "setChatTitle" -} - -func (config SetChatTitleConfig) values() (url.Values, error) { - v := url.Values{} - - v.Add("chat_id", strconv.FormatInt(config.ChatID, 10)) - v.Add("title", config.Title) - - return v, nil -} - -// SetChatDescriptionConfig contains information for change chat description. -type SetChatDescriptionConfig struct { - ChatID int64 - Description string -} - -func (config SetChatDescriptionConfig) method() string { - return "setChatDescription" -} - -func (config SetChatDescriptionConfig) values() (url.Values, error) { - v := url.Values{} - - v.Add("chat_id", strconv.FormatInt(config.ChatID, 10)) - v.Add("description", config.Description) - - return v, nil -} - -// SetChatPhotoConfig contains information for change chat photo -type SetChatPhotoConfig struct { - BaseFile -} - -// name returns the field name for the Photo. -func (config SetChatPhotoConfig) name() string { - return "photo" -} - -// method returns Telegram API method name for sending Photo. -func (config SetChatPhotoConfig) method() string { - return "setChatPhoto" -} - -// DeleteChatPhotoConfig contains information for delete chat photo. -type DeleteChatPhotoConfig struct { - ChatID int64 -} - -func (config DeleteChatPhotoConfig) method() string { - return "deleteChatPhoto" -} - -func (config DeleteChatPhotoConfig) values() (url.Values, error) { - v := url.Values{} - - v.Add("chat_id", strconv.FormatInt(config.ChatID, 10)) - - return v, nil -} 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 deleted file mode 100644 index c23a3bf..0000000 --- a/vendor/github.com/go-telegram-bot-api/telegram-bot-api/helpers.go +++ /dev/null @@ -1,686 +0,0 @@ -package tgbotapi - -import ( - "log" - "net/url" -) - -// NewMessage creates a new Message. -// -// chatID is where to send it, text is the message text. -func NewMessage(chatID int64, text string) MessageConfig { - return MessageConfig{ - BaseChat: BaseChat{ - ChatID: chatID, - ReplyToMessageID: 0, - }, - Text: text, - DisableWebPagePreview: false, - } -} - -// 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. -func NewMessageToChannel(username string, text string) MessageConfig { - return MessageConfig{ - BaseChat: BaseChat{ - ChannelUsername: username, - }, - Text: text, - } -} - -// NewForward creates a new forward. -// -// chatID is where to send it, fromChatID is the source chat, -// and messageID is the ID of the original message. -func NewForward(chatID int64, fromChatID int64, messageID int) ForwardConfig { - return ForwardConfig{ - BaseChat: BaseChat{ChatID: chatID}, - FromChatID: fromChatID, - MessageID: messageID, - } -} - -// NewPhotoUpload creates a new photo uploader. -// -// chatID is where to send it, file is a string path to the file, -// FileReader, or FileBytes. -// -// Note that you must send animated GIFs as a document. -func NewPhotoUpload(chatID int64, file interface{}) PhotoConfig { - return PhotoConfig{ - BaseFile: BaseFile{ - BaseChat: BaseChat{ChatID: chatID}, - File: file, - UseExisting: false, - }, - } -} - -// NewPhotoShare shares an existing photo. -// You may use this to reshare an existing photo without reuploading it. -// -// chatID is where to send it, fileID is the ID of the file -// already uploaded. -func NewPhotoShare(chatID int64, fileID string) PhotoConfig { - return PhotoConfig{ - BaseFile: BaseFile{ - BaseChat: BaseChat{ChatID: chatID}, - FileID: fileID, - UseExisting: true, - }, - } -} - -// NewAudioUpload creates a new audio uploader. -// -// chatID is where to send it, file is a string path to the file, -// FileReader, or FileBytes. -func NewAudioUpload(chatID int64, file interface{}) AudioConfig { - return AudioConfig{ - BaseFile: BaseFile{ - BaseChat: BaseChat{ChatID: chatID}, - File: file, - UseExisting: false, - }, - } -} - -// NewAudioShare shares an existing audio file. -// You may use this to reshare an existing audio file without -// reuploading it. -// -// chatID is where to send it, fileID is the ID of the audio -// already uploaded. -func NewAudioShare(chatID int64, fileID string) AudioConfig { - return AudioConfig{ - BaseFile: BaseFile{ - BaseChat: BaseCha