Skip to content

Commit

Permalink
Upgrade tucnak/telebot to v3
Browse files Browse the repository at this point in the history
  • Loading branch information
waybackarchiver committed Feb 1, 2022
1 parent be21ac1 commit 68ebe3f
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 17 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ require (
go.etcd.io/bbolt v1.3.6
golang.org/x/net v0.0.0-20220121210141-e204ce36a2ba
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
gopkg.in/tucnak/telebot.v2 v2.4.1
gopkg.in/telebot.v3 v3.0.0-20220130115853-f0291132d3c3
maunium.net/go/mautrix v0.10.4
)

Expand Down
10 changes: 8 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vb
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
github.com/go-rod/rod v0.101.0/go.mod h1:h9igqSGReLmOWyHtdf0AtUd0mdkHFu3gFwBeV+stleM=
github.com/go-shiori/dom v0.0.0-20210627111528-4e4722cd0d65 h1:zx4B0AiwqKDQq+AgqxWeHwbbLJQeidq20hgfP+aMNWI=
github.com/go-shiori/dom v0.0.0-20210627111528-4e4722cd0d65/go.mod h1:NPO1+buE6TYOWhUI98/hXLHHJhunIpXRuvDN4xjkCoE=
Expand All @@ -200,6 +204,7 @@ github.com/gobwas/pool v0.2.1 h1:xfeeEhW7pwmX8nuLVlqbzVc7udMDrwetjEv+TZIz1og=
github.com/gobwas/pool v0.2.1/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
github.com/gobwas/ws v1.1.0 h1:7RFti/xnNkMJnrK7D1yQ/iCIB5OrrY/54/H930kIbHA=
github.com/gobwas/ws v1.1.0/go.mod h1:nzvNcVha5eUziGrbxFCo6qFIojQHjJV5cLYIbezhfL0=
github.com/goccy/go-yaml v1.9.5/go.mod h1:U/jl18uSupI5rdI2jmuCswEA2htH9eXfferR3KfscvA=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
Expand Down Expand Up @@ -373,6 +378,7 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
github.com/libp2p/go-buffer-pool v0.0.2 h1:QNK2iAFa8gjAe1SPz6mHSMuCcjs+X1wlHzeOSqcmlfs=
github.com/libp2p/go-buffer-pool v0.0.2/go.mod h1:MvaB6xw5vOrDl8rYZGLFdKAuk/hRoRZd1Vi32+RXyFM=
github.com/libp2p/go-flow-metrics v0.0.3 h1:8tAs/hSdNvUiLgtlSy3mxwxWP4I9y/jlkPFT7epKdeM=
Expand Down Expand Up @@ -1068,9 +1074,9 @@ gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMy
gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/ini.v1 v1.62.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
gopkg.in/telebot.v3 v3.0.0-20220130115853-f0291132d3c3 h1:ifpOmJCnVni31dBAw99qxgCRfD33ROgv7vYxuhu+iWc=
gopkg.in/telebot.v3 v3.0.0-20220130115853-f0291132d3c3/go.mod h1:7rExV8/0mDDNu9epSrDm/8j22KLaActH1Tbee6YjzWg=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/tucnak/telebot.v2 v2.4.1 h1:bUOFHtHhuhPekjHGe1Q1BmITvtBLdQI4yjSMC405KcU=
gopkg.in/tucnak/telebot.v2 v2.4.1/go.mod h1:BgaIIx50PSRS9pG59JH+geT82cfvoJU/IaI5TJdN3v8=
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
2 changes: 1 addition & 1 deletion publish/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
mstdn "github.com/mattn/go-mastodon"
slack "github.com/slack-go/slack"
irc "github.com/thoj/go-ircevent"
telegram "gopkg.in/tucnak/telebot.v2"
telegram "gopkg.in/telebot.v3"
matrix "maunium.net/go/mautrix"
)

Expand Down
2 changes: 1 addition & 1 deletion publish/publish_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/wabarc/wayback"
"github.com/wabarc/wayback/config"
"github.com/wabarc/wayback/reduxer"
telegram "gopkg.in/tucnak/telebot.v2"
telegram "gopkg.in/telebot.v3"
)

var collects = []wayback.Collect{
Expand Down
4 changes: 2 additions & 2 deletions publish/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/wabarc/wayback/metrics"
"github.com/wabarc/wayback/reduxer"
"github.com/wabarc/wayback/template/render"
telegram "gopkg.in/tucnak/telebot.v2"
telegram "gopkg.in/telebot.v3"
)

type telegramBot struct {
Expand Down Expand Up @@ -81,7 +81,7 @@ func (t *telegramBot) toChannel(bundle *reduxer.Bundle, text string) (ok bool) {
}
}

chat, err := t.bot.ChatByID(config.Opts.TelegramChannel())
chat, err := t.bot.ChatByUsername(config.Opts.TelegramChannel())
if err != nil {
logger.Error("open a chat failed: %v", err)
return ok
Expand Down
2 changes: 1 addition & 1 deletion publish/telegram_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/wabarc/helper"
"github.com/wabarc/wayback/config"
"github.com/wabarc/wayback/template/render"
telegram "gopkg.in/tucnak/telebot.v2"
telegram "gopkg.in/telebot.v3"
)

var (
Expand Down
21 changes: 13 additions & 8 deletions service/telegram/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"github.com/wabarc/wayback/storage"
"github.com/wabarc/wayback/template/render"

telegram "gopkg.in/tucnak/telebot.v2"
telegram "gopkg.in/telebot.v3"
)

// ErrServiceClosed is returned by the Service's Serve method after a call to Shutdown.
Expand Down Expand Up @@ -61,7 +61,7 @@ func New(ctx context.Context, store *storage.Storage, pool pooling.Pool) *Telegr
// Verbose: config.Opts.HasDebugMode(),
ParseMode: telegram.ModeHTML,
Poller: &telegram.LongPoller{Timeout: pollTick},
Reporter: func(err error) {
OnError: func(err error, _ telegram.Context) {
if err != nil {
logger.Warn(err.Error())
}
Expand Down Expand Up @@ -91,7 +91,7 @@ func (t *Telegram) Serve() (err error) {
}
logger.Info("authorized on account %s", color.BlueString(t.bot.Me.Username))

if channel, err := t.bot.ChatByID(config.Opts.TelegramChannel()); err == nil {
if channel, err := t.bot.ChatByUsername(config.Opts.TelegramChannel()); err == nil {
id := strconv.FormatInt(channel.ID, 10)
logger.Info("channel title: %s, channel id: %s", color.BlueString(channel.Title), color.BlueString(id))
}
Expand Down Expand Up @@ -265,13 +265,18 @@ func (t *Telegram) wayback(ctx context.Context, message *telegram.Message, urls
ctx = context.WithValue(ctx, publish.PubBundle, bundles)
go publish.To(ctx, cols, publish.FlagTelegram.String())

var album telegram.Album
var albums telegram.Album
for _, bundle := range bundles {
album = append(album, publish.UploadToTelegram(bundle)...)
albums = append(albums, publish.UploadToTelegram(bundle)...)
}
if len(albums) == 0 {
logger.Debug("no albums to send")
return nil
}

// Send album attach files, and reply to wayback result message
opts = &telegram.SendOptions{ReplyTo: stage, DisableNotification: true}
if _, err := t.bot.SendAlbum(stage.Chat, album, opts); err != nil {
if _, err := t.bot.SendAlbum(stage.Chat, albums, opts); err != nil {
logger.Error("reply failed: %v", err)
}

Expand All @@ -281,7 +286,7 @@ func (t *Telegram) wayback(ctx context.Context, message *telegram.Message, urls
func (t *Telegram) playback(message *telegram.Message) error {
metrics.IncrementPlayback(metrics.ServiceTelegram, metrics.StatusRequest)

recipient, err := t.bot.ChatByID(fmt.Sprint(message.Chat.ID))
recipient, err := t.bot.ChatByID(message.Chat.ID)
if err != nil {
metrics.IncrementPlayback(metrics.ServiceTelegram, metrics.StatusFailure)
logger.Error("playback failed: %v", err)
Expand Down Expand Up @@ -368,7 +373,7 @@ func (t *Telegram) commandFallback() string {
}

func (t *Telegram) getCommands() []telegram.Command {
commands, err := t.bot.GetCommands()
commands, err := t.bot.Commands()
if err != nil {
logger.Error("got my commands failed: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion service/telegram/telegram_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/wabarc/wayback/config"
"github.com/wabarc/wayback/pooling"
"github.com/wabarc/wayback/storage"
telegram "gopkg.in/tucnak/telebot.v2"
telegram "gopkg.in/telebot.v3"
)

var (
Expand Down

0 comments on commit 68ebe3f

Please sign in to comment.