From 0b68c9b7906ce2b3af7c9a42053f32c286b17801 Mon Sep 17 00:00:00 2001 From: Oleksandr Savchuk Date: Mon, 30 Jul 2018 19:53:11 +0300 Subject: [PATCH 1/5] add full support of parse mode in captions - parse_mode of caption support in AudioConfig - parse_mode of caption support in DocumentConfig - parse_mode of caption support in VideoConfig - parse_mode of caption support in VoiceConfig - in PhotoConfig add parse_mode only if caption is not empty --- configs.go | 51 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/configs.go b/configs.go index bcc850d..e316ceb 100644 --- a/configs.go +++ b/configs.go @@ -253,9 +253,9 @@ func (config PhotoConfig) params() (map[string]string, error) { if config.Caption != "" { params["caption"] = config.Caption - } - if config.ParseMode != "" { - params["parse_mode"] = config.ParseMode + if config.ParseMode != "" { + params["parse_mode"] = config.ParseMode + } } return params, nil @@ -271,10 +271,11 @@ func (config PhotoConfig) values() (url.Values, error) { v.Add(config.name(), config.FileID) if config.Caption != "" { v.Add("caption", config.Caption) + if config.ParseMode != "" { + v.Add("parse_mode", config.ParseMode) + } } - if config.ParseMode != "" { - v.Add("parse_mode", config.ParseMode) - } + return v, nil } @@ -292,6 +293,7 @@ func (config PhotoConfig) method() string { type AudioConfig struct { BaseFile Caption string + ParseMode string Duration int Performer string Title string @@ -317,6 +319,9 @@ func (config AudioConfig) values() (url.Values, error) { } if config.Caption != "" { v.Add("caption", config.Caption) + if config.ParseMode != "" { + v.Add("parse_mode", config.ParseMode) + } } return v, nil @@ -338,6 +343,9 @@ func (config AudioConfig) params() (map[string]string, error) { } if config.Caption != "" { params["caption"] = config.Caption + if config.ParseMode != "" { + params["parse_mode"] = config.ParseMode + } } return params, nil @@ -356,7 +364,8 @@ func (config AudioConfig) method() string { // DocumentConfig contains information about a SendDocument request. type DocumentConfig struct { BaseFile - Caption string + Caption string + ParseMode string } // values returns a url.Values representation of DocumentConfig. @@ -369,6 +378,9 @@ func (config DocumentConfig) values() (url.Values, error) { v.Add(config.name(), config.FileID) if config.Caption != "" { v.Add("caption", config.Caption) + if config.ParseMode != "" { + v.Add("parse_mode", config.ParseMode) + } } return v, nil @@ -380,6 +392,9 @@ func (config DocumentConfig) params() (map[string]string, error) { if config.Caption != "" { params["caption"] = config.Caption + if config.ParseMode != "" { + params["parse_mode"] = config.ParseMode + } } return params, nil @@ -432,8 +447,9 @@ func (config StickerConfig) method() string { // VideoConfig contains information about a SendVideo request. type VideoConfig struct { BaseFile - Duration int - Caption string + Duration int + Caption string + ParseMode string } // values returns a url.Values representation of VideoConfig. @@ -449,6 +465,9 @@ func (config VideoConfig) values() (url.Values, error) { } if config.Caption != "" { v.Add("caption", config.Caption) + if config.ParseMode != "" { + v.Add("parse_mode", config.ParseMode) + } } return v, nil @@ -460,6 +479,9 @@ func (config VideoConfig) params() (map[string]string, error) { if config.Caption != "" { params["caption"] = config.Caption + if config.ParseMode != "" { + params["parse_mode"] = config.ParseMode + } } return params, nil @@ -529,8 +551,9 @@ func (config VideoNoteConfig) method() string { // VoiceConfig contains information about a SendVoice request. type VoiceConfig struct { BaseFile - Caption string - Duration int + Caption string + ParseMode string + Duration int } // values returns a url.Values representation of VoiceConfig. @@ -546,6 +569,9 @@ func (config VoiceConfig) values() (url.Values, error) { } if config.Caption != "" { v.Add("caption", config.Caption) + if config.ParseMode != "" { + v.Add("parse_mode", config.ParseMode) + } } return v, nil @@ -560,6 +586,9 @@ func (config VoiceConfig) params() (map[string]string, error) { } if config.Caption != "" { params["caption"] = config.Caption + if config.ParseMode != "" { + params["parse_mode"] = config.ParseMode + } } return params, nil From af72b0a3dbea69429d85ead3ccc39e22f4b83eef Mon Sep 17 00:00:00 2001 From: Oleksandr Savchuk Date: Mon, 30 Jul 2018 20:00:09 +0300 Subject: [PATCH 2/5] add support of parse_mode in EditMessageCaptionConfig --- configs.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/configs.go b/configs.go index e316ceb..a750182 100644 --- a/configs.go +++ b/configs.go @@ -822,13 +822,17 @@ func (config EditMessageTextConfig) method() string { // EditMessageCaptionConfig allows you to modify the caption of a message. type EditMessageCaptionConfig struct { BaseEdit - Caption string + Caption string + ParseMode string } func (config EditMessageCaptionConfig) values() (url.Values, error) { v, _ := config.BaseEdit.values() v.Add("caption", config.Caption) + if config.ParseMode != "" { + v.Add("parse_mode", config.ParseMode) + } return v, nil } From a1b3e4187891a214fb8d67ed937444145d569d23 Mon Sep 17 00:00:00 2001 From: Yan Mihailov Date: Tue, 7 Aug 2018 00:15:37 +0300 Subject: [PATCH 3/5] added custom logger and SetLogger func --- bot.go | 1 - helpers.go | 1 - log.go | 17 +++++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 log.go diff --git a/bot.go b/bot.go index 8fb6200..35d1e25 100644 --- a/bot.go +++ b/bot.go @@ -9,7 +9,6 @@ import ( "fmt" "io" "io/ioutil" - "log" "net/http" "net/url" "os" diff --git a/helpers.go b/helpers.go index b5480ea..f04a0a7 100644 --- a/helpers.go +++ b/helpers.go @@ -1,7 +1,6 @@ package tgbotapi import ( - "log" "net/url" ) diff --git a/log.go b/log.go new file mode 100644 index 0000000..18e339f --- /dev/null +++ b/log.go @@ -0,0 +1,17 @@ +package tgbotapi + +import ( + "os" + "errors" + stdlog "log" +) + +var log = stdlog.New(os.Stderr, "", stdlog.LstdFlags) + +func SetLogger(newLog *stdlog.Logger) error { + if newLog == nil { + return errors.New("logger is nil") + } + log = newLog + return nil +} From ca185227e57755c4e0944e61e8d584a721c9e64d Mon Sep 17 00:00:00 2001 From: Frederik Ring Date: Sun, 26 Aug 2018 18:52:52 +0200 Subject: [PATCH 4/5] Test in up-to-date Go versions --- .travis.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8408fb7..dc570dc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,7 @@ language: go go: - - 1.4 - - tip \ No newline at end of file + - '1.4' + - '1.10' + - '1.11' + - tip From 483f21c48bebae648c4464138be96b1344151035 Mon Sep 17 00:00:00 2001 From: Frederik Ring Date: Mon, 27 Aug 2018 22:44:02 +0200 Subject: [PATCH 5/5] Remove go1.4 from travis configuration --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index dc570dc..5769aa1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: go go: - - '1.4' - '1.10' - '1.11' - tip