diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d48932..59a5efb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.2.1] - 2023-12-03 + +### Changed + +- Migrate to telegram-bot-api/v5 + ## [1.2.0] - 2023-12-02 ### Added diff --git a/app/app.go b/app/app.go index f43d4c5..ef65ca9 100644 --- a/app/app.go +++ b/app/app.go @@ -14,8 +14,8 @@ import ( "github.com/FreeFeed/freefeed-tg-client/types" "github.com/bluele/gcache" "github.com/davidmz/debug-log" - tg "github.com/davidmz/telegram-bot-api" "github.com/enescakir/emoji" + tg "github.com/go-telegram-bot-api/telegram-bot-api/v5" ) var internaErrorMsg = emoji.Parse(":stop_sign: An internal error occurred during your request. If it repeats, please contact support.") @@ -77,10 +77,7 @@ func (a *App) Start() (err error) { debugLogger: a.DebugLogger, }) - a.updChannel, err = a.TgAPI.GetUpdatesChan(tg.UpdateConfig{Offset: 0, Timeout: 60}) - if err != nil { - return - } + a.updChannel = a.TgAPI.GetUpdatesChan(tg.UpdateConfig{Offset: 0, Timeout: 60}) a.waitGroup.Add(1) a.DebugLogger.Println("▶️ Starting Telegram listener") diff --git a/chat/buttons.go b/chat/buttons.go index 750d706..63802f0 100644 --- a/chat/buttons.go +++ b/chat/buttons.go @@ -4,8 +4,8 @@ import ( "fmt" "github.com/FreeFeed/freefeed-tg-client/frf" - tg "github.com/davidmz/telegram-bot-api" "github.com/enescakir/emoji" + tg "github.com/go-telegram-bot-api/telegram-bot-api/v5" "github.com/gofrs/uuid" "golang.org/x/text/message" ) diff --git a/chat/chat.go b/chat/chat.go index 6526ef4..eb968f9 100644 --- a/chat/chat.go +++ b/chat/chat.go @@ -6,8 +6,8 @@ import ( "github.com/FreeFeed/freefeed-tg-client/frf" "github.com/FreeFeed/freefeed-tg-client/store" "github.com/davidmz/debug-log" - tg "github.com/davidmz/telegram-bot-api" "github.com/enescakir/emoji" + tg "github.com/go-telegram-bot-api/telegram-bot-api/v5" ) type Chat struct { @@ -61,11 +61,6 @@ func (c *Chat) ShouldSendAndSave(msg tg.Chattable, rec store.SentMsgRec) (tg.Mes return m.(tg.Message), err } -func (c *Chat) ShouldAnswer(config tg.CallbackConfig) (tg.APIResponse, error) { - resp, err := c.Should(c.App.Tg().AnswerCallbackQuery(config)) - return resp.(tg.APIResponse), err -} - func (c *Chat) newHTMLMessage(text string) *tg.MessageConfig { return c.newRawHTMLMessage(c.App.Linkify(emoji.Parse(text))) } diff --git a/chat/handle-callback.go b/chat/handle-callback.go index 057d680..ae147d5 100644 --- a/chat/handle-callback.go +++ b/chat/handle-callback.go @@ -6,8 +6,8 @@ import ( "github.com/FreeFeed/freefeed-tg-client/store" "github.com/FreeFeed/freefeed-tg-client/types" "github.com/davidmz/go-try" - tg "github.com/davidmz/telegram-bot-api" "github.com/enescakir/emoji" + tg "github.com/go-telegram-bot-api/telegram-bot-api/v5" "github.com/gofrs/uuid" "golang.org/x/text/language" "golang.org/x/text/message" @@ -36,7 +36,7 @@ func (c *Chat) handleCallback(update tg.Update) { p := message.NewPrinter(c.State.Language) - c.ShouldAnswer(tg.CallbackConfig{ + c.ShouldSend(tg.CallbackConfig{ CallbackQueryID: cbQuery.ID, Text: p.Sprintf("Language is %v now", c.State.Language), }) @@ -55,7 +55,7 @@ func (c *Chat) handleCallback(update tg.Update) { if errors.Is(err, store.ErrNotFound) { text = emoji.Parse(p.Sprintf(":warning: Cannot load event data, probably this message is too old")) } - c.ShouldAnswer(tg.CallbackConfig{ + c.ShouldSend(tg.CallbackConfig{ CallbackQueryID: cbQuery.ID, Text: text, }) @@ -65,7 +65,7 @@ func (c *Chat) handleCallback(update tg.Update) { event := eventRec.Event if err := c.ShouldOK(event.LoadPost(c.frfAPI())); err != nil { - c.ShouldAnswer(tg.CallbackConfig{ + c.ShouldSend(tg.CallbackConfig{ CallbackQueryID: cbQuery.ID, Text: emoji.Parse(p.Sprintf(":warning: FreeFeed error: %v", err)), }) @@ -84,7 +84,7 @@ func (c *Chat) handleCallback(update tg.Update) { } c.saveState() c.App.PauseEvents(c.ID) - c.ShouldAnswer(tg.CallbackConfig{CallbackQueryID: cbQuery.ID}) + c.ShouldSend(tg.CallbackConfig{CallbackQueryID: cbQuery.ID}) } else if cbData == doAcceptRequest || cbData == doRejectRequest { var err error if event.Group == nil { @@ -101,7 +101,7 @@ func (c *Chat) handleCallback(update tg.Update) { } } if err != nil { - c.ShouldAnswer(tg.CallbackConfig{ + c.ShouldSend(tg.CallbackConfig{ CallbackQueryID: cbQuery.ID, Text: emoji.Parse(p.Sprintf(":warning: FreeFeed error: %v", err)), }) @@ -142,7 +142,7 @@ func (c *Chat) handleCallback(update tg.Update) { })() if err != nil { c.errorLog().Print(err) - c.ShouldAnswer(tg.CallbackConfig{ + c.ShouldSend(tg.CallbackConfig{ CallbackQueryID: cbQuery.ID, Text: emoji.Parse(p.Sprintf(":warning: Error: %v", err)), }) @@ -159,7 +159,7 @@ func (c *Chat) handleCallback(update tg.Update) { err = c.frfAPI().UnlikeComment(event.CommentID) } if err != nil { - c.ShouldAnswer(tg.CallbackConfig{ + c.ShouldSend(tg.CallbackConfig{ CallbackQueryID: cbQuery.ID, Text: emoji.Parse(p.Sprintf(":warning: FreeFeed error: %v", err)), }) @@ -172,7 +172,7 @@ func (c *Chat) handleCallback(update tg.Update) { c.ShouldSend(msg) } else { - c.ShouldAnswer(tg.CallbackConfig{ + c.ShouldSend(tg.CallbackConfig{ CallbackQueryID: cbQuery.ID, Text: emoji.Parse(p.Sprintf(":alien: Unknown command %v", cbQuery.Data)), }) @@ -182,14 +182,14 @@ func (c *Chat) handleCallback(update tg.Update) { c.State.ClearExpectations() c.saveState() c.App.ResumeEvents(c.ID) - c.ShouldAnswer(tg.CallbackConfig{ + c.ShouldSend(tg.CallbackConfig{ CallbackQueryID: cbQuery.ID, Text: p.Sprintf("Action is cancelled"), }) } else { // Unknown or irrelevant command c.errorLog().Printf("Unknown callback data received: %v", cbQuery.Data) - c.ShouldAnswer(tg.CallbackConfig{ + c.ShouldSend(tg.CallbackConfig{ CallbackQueryID: cbQuery.ID, Text: emoji.Parse(p.Sprintf(":alien: Unknown command %v", cbQuery.Data)), }) diff --git a/chat/handle-command.go b/chat/handle-command.go index a2cb56d..e28662c 100644 --- a/chat/handle-command.go +++ b/chat/handle-command.go @@ -2,7 +2,7 @@ package chat import ( "github.com/FreeFeed/freefeed-tg-client/store" - tg "github.com/davidmz/telegram-bot-api" + tg "github.com/go-telegram-bot-api/telegram-bot-api/v5" "golang.org/x/text/message" ) diff --git a/chat/handle-message.go b/chat/handle-message.go index 8989ad8..ecf9084 100644 --- a/chat/handle-message.go +++ b/chat/handle-message.go @@ -2,7 +2,7 @@ package chat import ( "github.com/FreeFeed/freefeed-tg-client/store" - tg "github.com/davidmz/telegram-bot-api" + tg "github.com/go-telegram-bot-api/telegram-bot-api/v5" "github.com/gofrs/uuid" "github.com/golang-jwt/jwt/v4" "golang.org/x/text/message" @@ -26,7 +26,7 @@ func (c *Chat) handleMessage(update tg.Update) { } // Delete message with the token for safety - c.Should(c.App.Tg().DeleteMessage(tg.DeleteMessageConfig{ + c.Should(c.App.Tg().Request(tg.DeleteMessageConfig{ ChatID: c.ID, MessageID: msg.MessageID, })) diff --git a/chat/handle-update.go b/chat/handle-update.go index 0a6d293..f41c0bb 100644 --- a/chat/handle-update.go +++ b/chat/handle-update.go @@ -1,6 +1,6 @@ package chat -import tg "github.com/davidmz/telegram-bot-api" +import tg "github.com/go-telegram-bot-api/telegram-bot-api/v5" func (c *Chat) HandleUpdate(update tg.Update) { c.handleMessage(update) diff --git a/chat/print-expectation.go b/chat/print-expectation.go index 5c8271c..ed70377 100644 --- a/chat/print-expectation.go +++ b/chat/print-expectation.go @@ -2,8 +2,8 @@ package chat import ( "github.com/FreeFeed/freefeed-tg-client/store" - tg "github.com/davidmz/telegram-bot-api" "github.com/enescakir/emoji" + tg "github.com/go-telegram-bot-api/telegram-bot-api/v5" "golang.org/x/text/message" ) diff --git a/chat/process-event.go b/chat/process-event.go index faf302e..bd7c8c4 100644 --- a/chat/process-event.go +++ b/chat/process-event.go @@ -5,7 +5,7 @@ import ( "github.com/FreeFeed/freefeed-tg-client/frf" "github.com/FreeFeed/freefeed-tg-client/store" - tg "github.com/davidmz/telegram-bot-api" + tg "github.com/go-telegram-bot-api/telegram-bot-api/v5" "github.com/gofrs/uuid" "golang.org/x/text/message" ) diff --git a/chat/types.go b/chat/types.go index 4e48dbe..3113011 100644 --- a/chat/types.go +++ b/chat/types.go @@ -5,7 +5,7 @@ import ( "github.com/FreeFeed/freefeed-tg-client/store" "github.com/FreeFeed/freefeed-tg-client/types" "github.com/davidmz/debug-log" - tg "github.com/davidmz/telegram-bot-api" + tg "github.com/go-telegram-bot-api/telegram-bot-api/v5" ) type ID = types.TgChatID diff --git a/go.mod b/go.mod index ea2a576..d51b858 100644 --- a/go.mod +++ b/go.mod @@ -6,9 +6,8 @@ require ( github.com/bluele/gcache v0.0.2 github.com/davidmz/debug-log v1.2.0 github.com/davidmz/go-try v0.1.5 - github.com/davidmz/sliceutil v1.2.0 - github.com/davidmz/telegram-bot-api v5.0.2-fork+incompatible github.com/enescakir/emoji v1.0.0 + github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1 github.com/gobwas/ws v1.3.1 github.com/gofrs/uuid v4.4.0+incompatible github.com/golang-jwt/jwt/v4 v4.5.0 @@ -22,7 +21,6 @@ require ( github.com/gobwas/pool v0.2.1 // indirect github.com/kr/pretty v0.3.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/technoweenie/multipartstreamer v1.0.1 // indirect golang.org/x/sys v0.15.0 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index b5578ba..29c96e5 100644 --- a/go.sum +++ b/go.sum @@ -8,12 +8,10 @@ github.com/davidmz/debug-log v1.2.0 h1:7dYMJ2oLGjLXTg/wD9UpG1Ae3BPlEHZrt4F+jlqqx github.com/davidmz/debug-log v1.2.0/go.mod h1:dhNuGbwoCq6gVfwrt+/TlKs7YQMJdAyrdlmX/0YXwj4= github.com/davidmz/go-try v0.1.5 h1:tylL42whKswcvmG9M4uM2DVRN0YJLAxP4nRylDtfN0M= github.com/davidmz/go-try v0.1.5/go.mod h1:OOEBam4PN+vojywL/ZkHo0q4AoQsLeOtTgt7GDS0wYs= -github.com/davidmz/sliceutil v1.2.0 h1:rLTP0kJf7jxYkDB2qsblRM0AZzakTEALnkyQbit1dYs= -github.com/davidmz/sliceutil v1.2.0/go.mod h1:7UYHGgafAEi0muw1W0UGRzfG0To64rJAzXFHTMkM8zk= -github.com/davidmz/telegram-bot-api v5.0.2-fork+incompatible h1:ludjXgKEbl4JkaWPDsZ6zbQPYi3PJvpQa7yWdz+QpJ4= -github.com/davidmz/telegram-bot-api v5.0.2-fork+incompatible/go.mod h1:5jwq2lbK6nddxOsCSMaSkkTik4DTUT036GxIjgC+ySc= github.com/enescakir/emoji v1.0.0 h1:W+HsNql8swfCQFtioDGDHCHri8nudlK1n5p2rHCJoog= github.com/enescakir/emoji v1.0.0/go.mod h1:Bt1EKuLnKDTYpLALApstIkAjdDrS/8IAgTkKp+WKFD0= +github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1 h1:wG8n/XJQ07TmjbITcGiUaOtXxdrINDz1b0J1w0SzqDc= +github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1/go.mod h1:A2S0CWkNylc2phvKXWBBdD3K0iGnDBGbzRpISP2zBl8= github.com/gobwas/httphead v0.1.0 h1:exrUm0f4YX0L7EBwZHuCF4GDp8aJfVeBrlLQrs6NqWU= github.com/gobwas/httphead v0.1.0/go.mod h1:O/RXo79gxV8G+RqlR/otEwx4Q36zl9rqC5u12GKvMCM= github.com/gobwas/pool v0.2.1 h1:xfeeEhW7pwmX8nuLVlqbzVc7udMDrwetjEv+TZIz1og= @@ -40,8 +38,6 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/technoweenie/multipartstreamer v1.0.1 h1:XRztA5MXiR1TIRHxH2uNxXxaIkKQDeX7m2XsSOlQEnM= -github.com/technoweenie/multipartstreamer v1.0.1/go.mod h1:jNVxdtShOxzAsukZwTSw6MDx5eUJoiEBsSvzDU9uzog= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= diff --git a/main.go b/main.go index ecfd86f..da6d69e 100644 --- a/main.go +++ b/main.go @@ -17,7 +17,7 @@ import ( "github.com/FreeFeed/freefeed-tg-client/store" "github.com/davidmz/debug-log" "github.com/davidmz/go-try" - tgbotapi "github.com/davidmz/telegram-bot-api" + tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" ) const ( diff --git a/store/fs-tracked-posts.go b/store/fs-tracked-posts.go index 04b5074..b48f59d 100644 --- a/store/fs-tracked-posts.go +++ b/store/fs-tracked-posts.go @@ -1,8 +1,9 @@ package store import ( + "slices" + "github.com/FreeFeed/freefeed-tg-client/types" - "github.com/davidmz/sliceutil" "github.com/gofrs/uuid" ) @@ -26,8 +27,9 @@ func (s *fsStore) TrackPost(chatID types.TgChatID, postID uuid.UUID) error { trackedPostsFile, &tracked, func() error { - tracked.PostIDs = append(tracked.PostIDs, postID) - sliceutil.Unique(&tracked.PostIDs) + if !slices.Contains(tracked.PostIDs, postID) { + tracked.PostIDs = append(tracked.PostIDs, postID) + } return nil }, ) @@ -40,8 +42,9 @@ func (s *fsStore) UntrackPost(chatID types.TgChatID, postID uuid.UUID) error { trackedPostsFile, &tracked, func() error { - sliceutil.Filter(&tracked.PostIDs, - func(i int) bool { return tracked.PostIDs[i] != postID }) + if idx := slices.Index(tracked.PostIDs, postID); idx >= 0 { + slices.Delete(tracked.PostIDs, idx, idx+1) + } return nil }, )