From 5698d47edda387e252494073a2e7d7a897eae70c Mon Sep 17 00:00:00 2001 From: Syfaro Date: Fri, 26 Jun 2015 21:46:06 -0500 Subject: [PATCH 1/7] fix import in example in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c476f16..37b7a41 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ package main import ( "log" - "src.foxpaw.in/Syfaro/telegram-bot-api" + "github.com/Syfaro/telegram-bot-api" ) func main() { From 7b9b7856fc1005a6d04f039704c70aee26d50ade Mon Sep 17 00:00:00 2001 From: Syfaro Date: Fri, 26 Jun 2015 21:53:55 -0500 Subject: [PATCH 2/7] add license --- LICENSE.txt | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE.txt diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..b1fef93 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +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. From f6cf1bb7824bd6bdb3f30e7932c10f653d5e27b1 Mon Sep 17 00:00:00 2001 From: Jqs7 <7@jqs7.com> Date: Tue, 30 Jun 2015 00:04:48 +0800 Subject: [PATCH 3/7] should not panic in production env --- updates.go | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/updates.go b/updates.go index 7106201..0fb2e50 100644 --- a/updates.go +++ b/updates.go @@ -1,5 +1,10 @@ package tgbotapi +import ( + "log" + "time" +) + // UpdatesChan returns a chan that is called whenever a new message is gotten. func (bot *BotAPI) UpdatesChan(config UpdateConfig) (chan Update, error) { bot.Updates = make(chan Update, 100) @@ -8,15 +13,22 @@ func (bot *BotAPI) UpdatesChan(config UpdateConfig) (chan Update, error) { for { updates, err := bot.GetUpdates(config) if err != nil { - panic(err) - } - - for _, update := range updates { - if update.UpdateID >= config.Offset { - config.Offset = update.UpdateID + 1 - bot.Updates <- update + if bot.Debug == true { + panic(err) + } else { + log.Println(err) + log.Println("Retry in 3 Seconds") + time.Sleep(time.Second * 3) + } + } else { + for _, update := range updates { + if update.UpdateID >= config.Offset { + config.Offset = update.UpdateID + 1 + bot.Updates <- update + } } } + } }() From 69bb4a9c33b1861e616862688e1d60ffeb7d0c83 Mon Sep 17 00:00:00 2001 From: Jqs7 <7@jqs7.com> Date: Tue, 30 Jun 2015 11:28:55 +0800 Subject: [PATCH 4/7] update log message --- updates.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/updates.go b/updates.go index 0fb2e50..1a3a34a 100644 --- a/updates.go +++ b/updates.go @@ -17,7 +17,7 @@ func (bot *BotAPI) UpdatesChan(config UpdateConfig) (chan Update, error) { panic(err) } else { log.Println(err) - log.Println("Retry in 3 Seconds") + log.Println("Fail to GetUpdates,Retry in 3 Seconds...") time.Sleep(time.Second * 3) } } else { From 92ad19733ba69ebe635916af04cf51ea6fd4a71b Mon Sep 17 00:00:00 2001 From: Jqs7 <7@jqs7.com> Date: Tue, 30 Jun 2015 11:33:26 +0800 Subject: [PATCH 5/7] remove blank line --- updates.go | 1 - 1 file changed, 1 deletion(-) diff --git a/updates.go b/updates.go index 1a3a34a..edbcb20 100644 --- a/updates.go +++ b/updates.go @@ -28,7 +28,6 @@ func (bot *BotAPI) UpdatesChan(config UpdateConfig) (chan Update, error) { } } } - } }() From 2024a55b8769e678719ba5dce8463cc7e1415e53 Mon Sep 17 00:00:00 2001 From: Syfaro Date: Mon, 29 Jun 2015 22:44:12 -0500 Subject: [PATCH 6/7] slight code improvments, better language --- updates.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/updates.go b/updates.go index edbcb20..72f518b 100644 --- a/updates.go +++ b/updates.go @@ -13,19 +13,21 @@ func (bot *BotAPI) UpdatesChan(config UpdateConfig) (chan Update, error) { for { updates, err := bot.GetUpdates(config) if err != nil { - if bot.Debug == true { + if bot.Debug { panic(err) } else { log.Println(err) - log.Println("Fail to GetUpdates,Retry in 3 Seconds...") + log.Println("Failed to get updates, retrying in 3 seconds...") time.Sleep(time.Second * 3) } - } else { - for _, update := range updates { - if update.UpdateID >= config.Offset { - config.Offset = update.UpdateID + 1 - bot.Updates <- update - } + + continue + } + + for _, update := range updates { + if update.UpdateID >= config.Offset { + config.Offset = update.UpdateID + 1 + bot.Updates <- update } } } From b68832daa682e4e5fa44007f5bfae6d38d942dfe Mon Sep 17 00:00:00 2001 From: Syfaro Date: Mon, 29 Jun 2015 22:55:58 -0500 Subject: [PATCH 7/7] clarify scope of project in readme, update godoc link --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 37b7a41..af48acd 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,14 @@ # Golang Telegram bindings for the Bot API -[![GoDoc](https://godoc.org/src.foxpaw.in/Syfaro/telegram-bot-api?status.svg)](https://godoc.org/src.foxpaw.in/Syfaro/telegram-bot-api) +[![GoDoc](https://godoc.org/github.com/Syfaro/telegram-bot-api?status.svg)](http://godoc.org/github.com/Syfaro/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 (including one I am developing myself) for creating something with plugins and command handlers without having to design all that yourself. + ## Example This is a very simple bot that just displays any gotten updates, then replies it to that chat.