From 889cfd29be45c311f14b9d8a96435a3afe3527f0 Mon Sep 17 00:00:00 2001 From: Kevin Hellemun <17928966+OGKevin@users.noreply.github.com> Date: Mon, 12 Nov 2018 13:33:21 +0100 Subject: [PATCH 1/2] Provide users with more customization when creating a new bot. User are now able to create a bot with debug enabled by default. --- bot.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/bot.go b/bot.go index d56aaf8..d6040b0 100644 --- a/bot.go +++ b/bot.go @@ -34,7 +34,7 @@ type BotAPI struct { // // It requires a token, provided by @BotFather on Telegram. func NewBotAPI(token string) (*BotAPI, error) { - return NewBotAPIWithClient(token, &http.Client{}) + return CreateNewBotApi(token, &http.Client{}, false) } // NewBotAPIWithClient creates a new BotAPI instance @@ -42,11 +42,28 @@ func NewBotAPI(token string) (*BotAPI, error) { // // It requires a token, provided by @BotFather on Telegram. func NewBotAPIWithClient(token string, client *http.Client) (*BotAPI, error) { + return CreateNewBotApi(token, client, false) +} + +// NewBotAPIWithClient creates a new BotAPI instance +// and enables debug by default. +// +// It requires a token, provided by @BotFather on Telegram. +func NewBotApiWithDebug(token string) (*BotAPI, error) { + return CreateNewBotApi(token, &http.Client{}, true) +} + +// NewBotAPIWithClient creates a new BotAPI instance +// and allows you to pass all additional customization that you might need. +// +// It requires a token, provided by @BotFather on Telegram. +func CreateNewBotApi(token string, client *http.Client, debug bool) (*BotAPI, error) { bot := &BotAPI{ Token: token, Client: client, Buffer: 100, shutdownChannel: make(chan interface{}), + Debug: debug, } self, err := bot.GetMe() From 0f74fea13c3f330e543328493453fd84a5a5a020 Mon Sep 17 00:00:00 2001 From: Kevin Hellemun <17928966+OGKevin@users.noreply.github.com> Date: Mon, 25 Feb 2019 12:55:58 +0100 Subject: [PATCH 2/2] Fix method naming and docs. --- bot.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/bot.go b/bot.go index d6040b0..266910a 100644 --- a/bot.go +++ b/bot.go @@ -34,7 +34,7 @@ type BotAPI struct { // // It requires a token, provided by @BotFather on Telegram. func NewBotAPI(token string) (*BotAPI, error) { - return CreateNewBotApi(token, &http.Client{}, false) + return CreateNewBotAPI(token, &http.Client{}, false) } // NewBotAPIWithClient creates a new BotAPI instance @@ -42,22 +42,22 @@ func NewBotAPI(token string) (*BotAPI, error) { // // It requires a token, provided by @BotFather on Telegram. func NewBotAPIWithClient(token string, client *http.Client) (*BotAPI, error) { - return CreateNewBotApi(token, client, false) + return CreateNewBotAPI(token, client, false) } -// NewBotAPIWithClient creates a new BotAPI instance +// NewBotAPIWithDebug creates a new BotAPI instance // and enables debug by default. // // It requires a token, provided by @BotFather on Telegram. -func NewBotApiWithDebug(token string) (*BotAPI, error) { - return CreateNewBotApi(token, &http.Client{}, true) +func NewBotAPIWithDebug(token string) (*BotAPI, error) { + return CreateNewBotAPI(token, &http.Client{}, true) } -// NewBotAPIWithClient creates a new BotAPI instance +// CreateNewBotAPI creates a new BotAPI instance // and allows you to pass all additional customization that you might need. // // It requires a token, provided by @BotFather on Telegram. -func CreateNewBotApi(token string, client *http.Client, debug bool) (*BotAPI, error) { +func CreateNewBotAPI(token string, client *http.Client, debug bool) (*BotAPI, error) { bot := &BotAPI{ Token: token, Client: client,