Skip to content
This repository has been archived by the owner on Feb 26, 2023. It is now read-only.

Commit

Permalink
Migrate back to an original telegram library
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyaglow committed Nov 27, 2018
1 parent 416909a commit d6f5ca2
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 18 deletions.
6 changes: 4 additions & 2 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strconv"
"strings"

"github.com/ilyaglow/telegram-bot-api"
"github.com/go-telegram-bot-api/telegram-bot-api"
)

// Auth handles simple password authentication of a user
Expand All @@ -23,7 +23,9 @@ func (c *Client) Auth(input *tgbotapi.Message) {
} else {
msg.Text = "Wrong password"
}
c.Bot.Send(msg)
if _, err := c.Bot.Send(msg); err != nil {
log.Println(err)
}
}

// CheckAuth checks if user is allowed to interact with a bot
Expand Down
2 changes: 1 addition & 1 deletion auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strconv"
"testing"

"github.com/ilyaglow/telegram-bot-api"
"github.com/go-telegram-bot-api/telegram-bot-api"
)

func TestCheckAuth(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"golang.org/x/net/proxy"

"github.com/boltdb/bolt"
"github.com/go-telegram-bot-api/telegram-bot-api"
"github.com/ilyaglow/go-cortex"
"github.com/ilyaglow/telegram-bot-api"
)

const (
Expand Down
22 changes: 12 additions & 10 deletions process.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"strings"

valid "github.com/asaskevich/govalidator"
"github.com/go-telegram-bot-api/telegram-bot-api"
"github.com/ilyaglow/go-cortex"
"github.com/ilyaglow/telegram-bot-api"
)

// sendReport sends a report depends on success
Expand All @@ -31,9 +31,9 @@ func (c *Client) sendReport(r *cortex.Report, callback *tgbotapi.CallbackQuery)
attachment := tgbotapi.NewDocumentUpload(callback.Message.Chat.ID, fb)
attachment.ReplyToMessageID = callback.Message.ReplyToMessage.MessageID
attachment.Caption = buildTaxonomies(r.Taxonomies())
go c.Bot.Send(attachment)

return nil
_, err := c.Bot.Send(attachment)
return err
}

// processCallback analyzes observables with a selected set of analyzers
Expand Down Expand Up @@ -76,31 +76,33 @@ func (c *Client) processCallback(callback *tgbotapi.CallbackQuery) error {
case "close":
kb := showButton()
edit := tgbotapi.NewEditMessageReplyMarkup(callback.Message.Chat.ID, callback.Message.MessageID, *kb)
go c.Bot.Send(edit)
if _, err := c.Bot.Send(edit); err != nil {
return err
}
case "show":
kb, err := c.analyzersButtons(dataType(callback.Message.ReplyToMessage.Text))
if err != nil {
return err
}
edit := tgbotapi.NewEditMessageReplyMarkup(callback.Message.Chat.ID, callback.Message.MessageID, *kb)
go c.Bot.Send(edit)
if _, err := c.Bot.Send(edit); err != nil {
return err
}
default:
r, err := c.Cortex.Analyzers.Run(context.Background(), callback.Data, j, c.Timeout)
if err != nil {
msg := tgbotapi.NewMessage(callback.Message.Chat.ID, fmt.Sprintf("%s failed: %s", callback.Data, err.Error()))
msg.ReplyToMessageID = callback.Message.MessageID
c.Bot.Send(msg)
if _, err := c.Bot.Send(msg); err != nil {
return err
}
} else {
err = c.sendReport(r, callback)
if err != nil {
return err
}
}
}

cbcfg := tgbotapi.NewCallback(callback.ID, "")
go c.Bot.AnswerCallbackQuery(cbcfg)

return nil
}

Expand Down
10 changes: 8 additions & 2 deletions run.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"log"
"strings"

"github.com/ilyaglow/telegram-bot-api"
"github.com/go-telegram-bot-api/telegram-bot-api"
)

// Run represents infinite function that waits for a message,
Expand All @@ -30,6 +30,10 @@ func (c *Client) Run() {
if err := c.processCallback(update.CallbackQuery); err != nil {
log.Println(err)
}
cbcfg := tgbotapi.NewCallback(update.CallbackQuery.ID, "")
if _, err := c.Bot.AnswerCallbackQuery(cbcfg); err != nil {
log.Println(err)
}
}()
} else {
log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text)
Expand All @@ -40,7 +44,9 @@ func (c *Client) Run() {
update.Message.Command() == "start" &&
!c.CheckAuth(update.Message.From) {
msg.Text = "Enter your password"
go c.Bot.Send(msg)
if _, err := c.Bot.Send(msg); err != nil {
log.Println(err)
}
continue
}

Expand Down
2 changes: 1 addition & 1 deletion users.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strconv"

"github.com/boltdb/bolt"
"github.com/ilyaglow/telegram-bot-api"
"github.com/go-telegram-bot-api/telegram-bot-api"
)

// registerUser adds a user to boltdb bucket
Expand Down
2 changes: 1 addition & 1 deletion users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"testing"

"github.com/boltdb/bolt"
"github.com/ilyaglow/telegram-bot-api"
"github.com/go-telegram-bot-api/telegram-bot-api"
)

func mockupClient() *Client {
Expand Down

0 comments on commit d6f5ca2

Please sign in to comment.