From 238ab91aa5e68acded6c3f4deb4184aa7bc32772 Mon Sep 17 00:00:00 2001 From: Andreas Bielawski Date: Wed, 24 Jan 2024 15:34:12 +0100 Subject: [PATCH] Migrate the rest of the plugins --- bot/bot.go | 21 ++-- plugin/dcrypt/dcrypt.go | 1 + plugin/google_images/google_images.go | 2 + plugin/home/home.go | 8 +- plugin/notify/notify.go | 8 +- plugin/{todo => }/twitter/api.go | 3 +- plugin/{todo => }/twitter/twitter.go | 119 +++++++++++------- plugin/{todo => }/twitter/twitter_api.http | 0 .../{todo => }/twitter/twitter_graphql.http | 0 .../{todo => }/upload_by_url/upload_by_url.go | 55 +++----- plugin/{todo => }/urbandictionary/api.go | 0 .../urbandictionary/urbandictionary.go | 3 +- .../urbandictionary/urbandictionary.http | 0 plugin/{todo => }/weather/api.go | 0 plugin/{todo => }/weather/weather.go | 52 ++++---- plugin/{todo => }/weather/weather.http | 0 plugin/{todo => }/weather/weathercode.go | 0 plugin/{todo => }/wikipedia/api.go | 0 plugin/{todo => }/wikipedia/wikipedia.go | 38 +++--- plugin/{todo => }/wikipedia/wikipedia.http | 0 plugin/{todo => }/worldclock/api.go | 0 plugin/{todo => }/worldclock/worldclock.go | 12 +- plugin/{todo => }/worldclock/worldclock.http | 0 plugin/{todo => }/youtube/api.go | 0 plugin/{todo => }/youtube/youtube.go | 25 ++-- plugin/{todo => }/youtube/youtube.http | 0 utils/const.go | 1 + 27 files changed, 197 insertions(+), 151 deletions(-) rename plugin/{todo => }/twitter/api.go (99%) rename plugin/{todo => }/twitter/twitter.go (81%) rename plugin/{todo => }/twitter/twitter_api.http (100%) rename plugin/{todo => }/twitter/twitter_graphql.http (100%) rename plugin/{todo => }/upload_by_url/upload_by_url.go (71%) rename plugin/{todo => }/urbandictionary/api.go (100%) rename plugin/{todo => }/urbandictionary/urbandictionary.go (95%) rename plugin/{todo => }/urbandictionary/urbandictionary.http (100%) rename plugin/{todo => }/weather/api.go (100%) rename plugin/{todo => }/weather/weather.go (83%) rename plugin/{todo => }/weather/weather.http (100%) rename plugin/{todo => }/weather/weathercode.go (100%) rename plugin/{todo => }/wikipedia/api.go (100%) rename plugin/{todo => }/wikipedia/wikipedia.go (82%) rename plugin/{todo => }/wikipedia/wikipedia.http (100%) rename plugin/{todo => }/worldclock/api.go (100%) rename plugin/{todo => }/worldclock/worldclock.go (90%) rename plugin/{todo => }/worldclock/worldclock.http (100%) rename plugin/{todo => }/youtube/api.go (100%) rename plugin/{todo => }/youtube/youtube.go (92%) rename plugin/{todo => }/youtube/youtube.http (100%) diff --git a/bot/bot.go b/bot/bot.go index 47ef6ae..27911da 100644 --- a/bot/bot.go +++ b/bot/bot.go @@ -45,6 +45,13 @@ import ( "github.com/Brawl345/gobot/plugin/speech_to_text" "github.com/Brawl345/gobot/plugin/stats" "github.com/Brawl345/gobot/plugin/summarize" + "github.com/Brawl345/gobot/plugin/twitter" + "github.com/Brawl345/gobot/plugin/upload_by_url" + "github.com/Brawl345/gobot/plugin/urbandictionary" + "github.com/Brawl345/gobot/plugin/weather" + "github.com/Brawl345/gobot/plugin/wikipedia" + "github.com/Brawl345/gobot/plugin/worldclock" + "github.com/Brawl345/gobot/plugin/youtube" "github.com/PaulSonOfLars/gotgbot/v2" "github.com/PaulSonOfLars/gotgbot/v2/ext" "github.com/jmoiron/sqlx" @@ -141,13 +148,13 @@ func New(db *sqlx.DB) (*Gobot, error) { speech_to_text.New(credentialService), stats.New(chatsUsersService), summarize.New(credentialService), - //twitter.New(), - //upload_by_url.New(), - //urbandictionary.New(), - //weather.New(geocodingService, homeService), - //wikipedia.New(), - //worldclock.New(credentialService, geocodingService), - //youtube.New(credentialService), + twitter.New(), + upload_by_url.New(), + urbandictionary.New(), + weather.New(geocodingService, homeService), + wikipedia.New(), + worldclock.New(credentialService, geocodingService), + youtube.New(credentialService), } managerSrvce.SetPlugins(plugins) diff --git a/plugin/dcrypt/dcrypt.go b/plugin/dcrypt/dcrypt.go index c974983..267668a 100644 --- a/plugin/dcrypt/dcrypt.go +++ b/plugin/dcrypt/dcrypt.go @@ -181,6 +181,7 @@ func (p *Plugin) OnFile(b *gotgbot.Bot, c plugin.GobotContext) error { Caption: "πŸ”‘ Hier sind deine entschlΓΌsselten Links!", ReplyParameters: &gotgbot.ReplyParameters{ AllowSendingWithoutReply: true, + MessageId: c.EffectiveMessage.MessageId, }, DisableNotification: true, ParseMode: gotgbot.ParseModeHTML, diff --git a/plugin/google_images/google_images.go b/plugin/google_images/google_images.go index b0b8a57..c1d69ec 100644 --- a/plugin/google_images/google_images.go +++ b/plugin/google_images/google_images.go @@ -203,6 +203,7 @@ func (p *Plugin) doImageSearch(b *gotgbot.Bot, c *plugin.GobotContext) error { Caption: caption, ReplyParameters: &gotgbot.ReplyParameters{ AllowSendingWithoutReply: true, + MessageId: c.EffectiveMessage.MessageId, }, DisableNotification: true, ParseMode: gotgbot.ParseModeHTML, @@ -213,6 +214,7 @@ func (p *Plugin) doImageSearch(b *gotgbot.Bot, c *plugin.GobotContext) error { Caption: caption, ReplyParameters: &gotgbot.ReplyParameters{ AllowSendingWithoutReply: true, + MessageId: c.EffectiveMessage.MessageId, }, DisableNotification: true, ParseMode: gotgbot.ParseModeHTML, diff --git a/plugin/home/home.go b/plugin/home/home.go index 85d28ad..2c3c93d 100644 --- a/plugin/home/home.go +++ b/plugin/home/home.go @@ -79,7 +79,7 @@ func (p *Plugin) onGetHome(b *gotgbot.Bot, c plugin.GobotContext) error { Int64("user_id", c.EffectiveUser.Id). Str("guid", guid). Msg("error getting home") - _, err := c.EffectiveMessage.Reply(b, fmt.Sprintf("❌ Ein Fehler ist aufgetreten.%s", utils.EmbedGUID(guid)), + _, err := c.EffectiveMessage.Reply(b, fmt.Sprintf("❌ Es ist ein Fehler aufgetreten.%s", utils.EmbedGUID(guid)), utils.DefaultSendOptions()) return err } @@ -108,7 +108,7 @@ func (p *Plugin) onHomeSet(b *gotgbot.Bot, c plugin.GobotContext) error { Err(err). Str("guid", guid). Msg("error getting location") - _, err := c.EffectiveMessage.Reply(b, fmt.Sprintf("❌ Ein Fehler ist aufgetreten.%s", utils.EmbedGUID(guid)), + _, err := c.EffectiveMessage.Reply(b, fmt.Sprintf("❌ Es ist ein Fehler aufgetreten.%s", utils.EmbedGUID(guid)), utils.DefaultSendOptions()) return err } @@ -121,7 +121,7 @@ func (p *Plugin) onHomeSet(b *gotgbot.Bot, c plugin.GobotContext) error { Int64("user_id", c.EffectiveUser.Id). Str("guid", guid). Msg("error setting home") - _, err := c.EffectiveMessage.Reply(b, fmt.Sprintf("❌ Ein Fehler ist aufgetreten.%s", utils.EmbedGUID(guid)), + _, err := c.EffectiveMessage.Reply(b, fmt.Sprintf("❌ Es ist ein Fehler aufgetreten.%s", utils.EmbedGUID(guid)), utils.DefaultSendOptions()) return err } @@ -145,7 +145,7 @@ func (p *Plugin) onDeleteHome(b *gotgbot.Bot, c plugin.GobotContext) error { Int64("user_id", c.EffectiveUser.Id). Str("guid", guid). Msg("error deleting home") - _, err = c.EffectiveMessage.Reply(b, fmt.Sprintf("❌ Ein Fehler ist aufgetreten.%s", utils.EmbedGUID(guid)), + _, err = c.EffectiveMessage.Reply(b, fmt.Sprintf("❌ Es ist ein Fehler aufgetreten.%s", utils.EmbedGUID(guid)), utils.DefaultSendOptions()) return err } diff --git a/plugin/notify/notify.go b/plugin/notify/notify.go index 93147e1..5e8028e 100644 --- a/plugin/notify/notify.go +++ b/plugin/notify/notify.go @@ -198,7 +198,7 @@ func (p *Plugin) enableNotify(b *gotgbot.Bot, c plugin.GobotContext) error { Int64("user_id", c.EffectiveUser.Id). Str("guid", guid). Msg("error during enabled check") - _, err = c.EffectiveMessage.Reply(b, fmt.Sprintf("❌ Ein Fehler ist aufgetreten.%s", utils.EmbedGUID(guid)), + _, err = c.EffectiveMessage.Reply(b, fmt.Sprintf("❌ Es ist ein Fehler aufgetreten.%s", utils.EmbedGUID(guid)), utils.DefaultSendOptions()) } @@ -215,7 +215,7 @@ func (p *Plugin) enableNotify(b *gotgbot.Bot, c plugin.GobotContext) error { Int64("user_id", c.EffectiveUser.Id). Str("guid", guid). Msg("error while enabling notifications") - _, err = c.EffectiveMessage.Reply(b, fmt.Sprintf("❌ Ein Fehler ist aufgetreten.%s", utils.EmbedGUID(guid)), + _, err = c.EffectiveMessage.Reply(b, fmt.Sprintf("❌ Es ist ein Fehler aufgetreten.%s", utils.EmbedGUID(guid)), utils.DefaultSendOptions()) } @@ -233,7 +233,7 @@ func (p *Plugin) disableNotify(b *gotgbot.Bot, c plugin.GobotContext) error { Int64("user_id", c.EffectiveUser.Id). Str("guid", guid). Msg("error during enabled check") - _, err = c.EffectiveMessage.Reply(b, fmt.Sprintf("❌ Ein Fehler ist aufgetreten.%s", utils.EmbedGUID(guid)), + _, err = c.EffectiveMessage.Reply(b, fmt.Sprintf("❌ Es ist ein Fehler aufgetreten.%s", utils.EmbedGUID(guid)), utils.DefaultSendOptions()) } @@ -250,7 +250,7 @@ func (p *Plugin) disableNotify(b *gotgbot.Bot, c plugin.GobotContext) error { Int64("user_id", c.EffectiveUser.Id). Str("guid", guid). Msg("error while disabling notifications") - _, err = c.EffectiveMessage.Reply(b, fmt.Sprintf("❌ Ein Fehler ist aufgetreten.%s", utils.EmbedGUID(guid)), + _, err = c.EffectiveMessage.Reply(b, fmt.Sprintf("❌ Es ist ein Fehler aufgetreten.%s", utils.EmbedGUID(guid)), utils.DefaultSendOptions()) return err } diff --git a/plugin/todo/twitter/api.go b/plugin/twitter/api.go similarity index 99% rename from plugin/todo/twitter/api.go rename to plugin/twitter/api.go index ebaf629..10961d4 100644 --- a/plugin/todo/twitter/api.go +++ b/plugin/twitter/api.go @@ -2,10 +2,11 @@ package twitter import ( "fmt" - "github.com/Brawl345/gobot/utils" "strconv" "strings" "time" + + "github.com/Brawl345/gobot/utils" ) const ( diff --git a/plugin/todo/twitter/twitter.go b/plugin/twitter/twitter.go similarity index 81% rename from plugin/todo/twitter/twitter.go rename to plugin/twitter/twitter.go index b9a1506..c83b4ff 100644 --- a/plugin/todo/twitter/twitter.go +++ b/plugin/twitter/twitter.go @@ -14,6 +14,7 @@ import ( "github.com/Brawl345/gobot/plugin" "github.com/Brawl345/gobot/utils" "github.com/Brawl345/gobot/utils/httpUtils" + "github.com/PaulSonOfLars/gotgbot/v2" "github.com/rs/xid" ) @@ -191,12 +192,15 @@ func (p *Plugin) OnStatus(b *gotgbot.Bot, c plugin.GobotContext) error { if result.Typename == "TweetUnavailable" { if result.Reason == "NsfwLoggedOut" { - return c.Reply(fmt.Sprintf("https://vxtwitter.com/_/status/%s", tweetID), &telebot.SendOptions{ - AllowWithoutReply: true, - DisableWebPagePreview: false, - DisableNotification: true, - ParseMode: telebot.ModeHTML, - }) + _, err = c.EffectiveMessage.Reply(b, + fmt.Sprintf("https://vxtwitter.com/_/status/%s", tweetID), + &gotgbot.SendMessageOpts{ + ReplyParameters: &gotgbot.ReplyParameters{AllowSendingWithoutReply: true}, + DisableNotification: true, + ParseMode: gotgbot.ParseModeHTML, + }, + ) + return err } else if result.Reason == "Protected" { _, err := c.EffectiveMessage.Reply(b, "πŸ”“ Der Account-Inhaber hat beschrΓ€nkt, wer seine Tweets ansehen kann.", utils.DefaultSendOptions()) return err @@ -211,11 +215,11 @@ func (p *Plugin) OnStatus(b *gotgbot.Bot, c plugin.GobotContext) error { return err } - sendOptions := &telebot.SendOptions{ - AllowWithoutReply: true, - DisableWebPagePreview: true, - DisableNotification: true, - ParseMode: telebot.ModeHTML, + sendOptions := &gotgbot.SendMessageOpts{ + ReplyParameters: &gotgbot.ReplyParameters{AllowSendingWithoutReply: true}, + LinkPreviewOptions: &gotgbot.LinkPreviewOptions{IsDisabled: true}, + DisableNotification: true, + ParseMode: gotgbot.ParseModeHTML, } var sb strings.Builder timezone := utils.GermanTimezone() @@ -410,14 +414,15 @@ func (p *Plugin) OnStatus(b *gotgbot.Bot, c plugin.GobotContext) error { // Media media := result.Legacy.ExtendedEntities.Media if len(media) == 1 && (media[0].IsPhoto() || media[0].IsGIF()) { // One picture or GIF = send as preview - sendOptions.DisableWebPagePreview = false - return c.Reply( + sendOptions.LinkPreviewOptions.IsDisabled = false + _, err := c.EffectiveMessage.Reply(b, utils.EmbedImage(media[0].Link())+sb.String(), sendOptions, ) + return err } - err = c.Reply(sb.String(), sendOptions) + _, err = c.EffectiveMessage.Reply(b, sb.String(), sendOptions) if err != nil { return err } @@ -434,25 +439,23 @@ func (p *Plugin) OnStatus(b *gotgbot.Bot, c plugin.GobotContext) error { if len(media) > 0 && len(media) != len(gifs) { // Try album (photos + videos, no GIFs) first - _ = c.Notify(telebot.UploadingPhoto) - album := make([]telebot.Inputtable, 0, len(media)) + _, _ = c.EffectiveChat.SendAction(b, utils.ChatActionUploadPhoto, nil) + album := make([]gotgbot.InputMedia, 0, len(media)) for _, medium := range media { if medium.IsPhoto() { - album = append(album, &telebot.Photo{Caption: medium.Caption(), File: telebot.FromURL(medium.Link())}) + album = append(album, gotgbot.InputMediaPhoto{Caption: medium.Caption(), Media: medium.Link()}) } else if medium.IsVideo() { - album = append(album, &telebot.Video{ - Caption: medium.Caption(), - File: telebot.FromURL(medium.Link()), - }) + album = append(album, gotgbot.InputMediaVideo{Caption: medium.Caption(), Media: medium.Link()}) } } - err := c.SendAlbum(album, telebot.Silent) + _, err := b.SendMediaGroup(c.EffectiveChat.Id, album, &gotgbot.SendMediaGroupOpts{DisableNotification: true, + RequestOpts: &gotgbot.RequestOpts{Timeout: 30 * time.Second}}) if err != nil { // Group send failed - sending media manually as seperate messages log.Err(err).Msg("Error while sending album") - msg, err := c.Bot().Reply(c.EffectiveMessage, + msg, err := c.EffectiveMessage.Reply(b, "πŸ•’ Medien werden heruntergeladen und gesendet...", utils.DefaultSendOptions(), ) @@ -463,9 +466,9 @@ func (p *Plugin) OnStatus(b *gotgbot.Bot, c plugin.GobotContext) error { for _, medium := range media { if medium.IsPhoto() { - _ = c.Notify(telebot.UploadingPhoto) + _, _ = c.EffectiveChat.SendAction(b, utils.ChatActionUploadPhoto, nil) } else { - _ = c.Notify(telebot.UploadingVideo) + _, _ = c.EffectiveChat.SendAction(b, utils.ChatActionUploadVideo, nil) } func() { @@ -473,7 +476,10 @@ func (p *Plugin) OnStatus(b *gotgbot.Bot, c plugin.GobotContext) error { log.Info().Str("url", medium.Link()).Msg("Downloading") if err != nil { log.Err(err).Str("url", medium.Link()).Msg("Error while downloading") - err := c.Reply(medium.Caption(), telebot.Silent, telebot.AllowWithoutReply) + _, err := c.EffectiveMessage.Reply(b, medium.Caption(), &gotgbot.SendMessageOpts{ + ReplyParameters: &gotgbot.ReplyParameters{AllowSendingWithoutReply: true}, + DisableNotification: true, + }) if err != nil { log.Err(err).Str("url", medium.Link()).Msg("Error while replying with link") } @@ -488,19 +494,27 @@ func (p *Plugin) OnStatus(b *gotgbot.Bot, c plugin.GobotContext) error { }(resp.Body) if medium.IsPhoto() { - err = c.Reply(&telebot.Photo{File: telebot.FromReader(resp.Body)}, - telebot.Silent, telebot.AllowWithoutReply) + _, err = b.SendPhoto(c.EffectiveChat.Id, resp.Body, &gotgbot.SendPhotoOpts{ + ReplyParameters: &gotgbot.ReplyParameters{AllowSendingWithoutReply: true, + MessageId: c.EffectiveMessage.MessageId}, + DisableNotification: true, + }) } else { - err = c.Reply(&telebot.Video{ - Caption: medium.Caption(), - File: telebot.FromReader(resp.Body), - Streaming: true, - }, telebot.Silent, telebot.AllowWithoutReply) + _, err = b.SendVideo(c.EffectiveChat.Id, resp.Body, &gotgbot.SendVideoOpts{ + Caption: medium.Caption(), + ReplyParameters: &gotgbot.ReplyParameters{AllowSendingWithoutReply: true, + MessageId: c.EffectiveMessage.MessageId}, + DisableNotification: true, + SupportsStreaming: true, + }) } if err != nil { // Last resort: Send URL as text log.Err(err).Str("url", medium.Link()).Msg("Error while replying with downloaded medium") - err := c.Reply(medium.Caption(), telebot.Silent, telebot.AllowWithoutReply) + _, err := c.EffectiveMessage.Reply(b, medium.Caption(), &gotgbot.SendMessageOpts{ + ReplyParameters: &gotgbot.ReplyParameters{AllowSendingWithoutReply: true}, + DisableNotification: true, + }) if err != nil { log.Err(err).Str("url", medium.Link()).Msg("Error while sending medium link") } @@ -508,23 +522,28 @@ func (p *Plugin) OnStatus(b *gotgbot.Bot, c plugin.GobotContext) error { }() } - _ = c.Bot().Delete(msg) + _, _ = msg.Delete(b, nil) } } // Now to GIFs... if len(gifs) > 0 { - _ = c.Notify(telebot.UploadingVideo) + _, _ = c.EffectiveChat.SendAction(b, utils.ChatActionUploadVideo, nil) for _, gif := range gifs { - err = c.Reply(&telebot.Animation{ - Caption: gif.Caption(), - File: telebot.FromURL(gif.Link()), - }, telebot.Silent, telebot.AllowWithoutReply) + _, err := b.SendAnimation(c.EffectiveChat.Id, + gif.Link(), + &gotgbot.SendAnimationOpts{ + Caption: gif.Caption(), + ReplyParameters: &gotgbot.ReplyParameters{AllowSendingWithoutReply: true, + MessageId: c.EffectiveMessage.MessageId}, + DisableNotification: true, + }, + ) if err != nil { func() { - _ = c.Notify(telebot.UploadingVideo) + _, _ = c.EffectiveChat.SendAction(b, utils.ChatActionUploadVideo, nil) log.Err(err).Str("url", gif.Link()).Msg("Error while sending gif through Telegram") @@ -532,7 +551,10 @@ func (p *Plugin) OnStatus(b *gotgbot.Bot, c plugin.GobotContext) error { log.Info().Str("url", gif.Link()).Msg("Downloading gif") if err != nil { log.Err(err).Str("url", gif.Link()).Msg("Error while downloading gif") - err := c.Reply(gif.Caption(), telebot.Silent, telebot.AllowWithoutReply) + _, err := c.EffectiveMessage.Reply(b, gif.Caption(), &gotgbot.SendMessageOpts{ + ReplyParameters: &gotgbot.ReplyParameters{AllowSendingWithoutReply: true}, + DisableNotification: true, + }) if err != nil { log.Err(err).Str("url", gif.Link()).Msg("Error while replying with link") } @@ -546,15 +568,20 @@ func (p *Plugin) OnStatus(b *gotgbot.Bot, c plugin.GobotContext) error { } }(resp.Body) - err = c.Reply(&telebot.Animation{ + _, err = b.SendAnimation(c.EffectiveChat.Id, resp.Body, &gotgbot.SendAnimationOpts{ Caption: gif.Caption(), - File: telebot.FromReader(resp.Body), - }, telebot.Silent, telebot.AllowWithoutReply) + ReplyParameters: &gotgbot.ReplyParameters{AllowSendingWithoutReply: true, + MessageId: c.EffectiveMessage.MessageId}, + DisableNotification: true, + }) if err != nil { // Last resort: Send URL as text log.Err(err).Str("url", gif.Link()).Msg("Error while replying with downloaded gif") - err := c.Reply(gif.Caption(), telebot.Silent, telebot.AllowWithoutReply) + _, err := c.EffectiveMessage.Reply(b, gif.Caption(), &gotgbot.SendMessageOpts{ + ReplyParameters: &gotgbot.ReplyParameters{AllowSendingWithoutReply: true}, + DisableNotification: true, + }) if err != nil { log.Err(err).Str("url", gif.Link()).Msg("Error while sending gif link") } diff --git a/plugin/todo/twitter/twitter_api.http b/plugin/twitter/twitter_api.http similarity index 100% rename from plugin/todo/twitter/twitter_api.http rename to plugin/twitter/twitter_api.http diff --git a/plugin/todo/twitter/twitter_graphql.http b/plugin/twitter/twitter_graphql.http similarity index 100% rename from plugin/todo/twitter/twitter_graphql.http rename to plugin/twitter/twitter_graphql.http diff --git a/plugin/todo/upload_by_url/upload_by_url.go b/plugin/upload_by_url/upload_by_url.go similarity index 71% rename from plugin/todo/upload_by_url/upload_by_url.go rename to plugin/upload_by_url/upload_by_url.go index 0835eb5..5ae4c2e 100644 --- a/plugin/todo/upload_by_url/upload_by_url.go +++ b/plugin/upload_by_url/upload_by_url.go @@ -12,6 +12,7 @@ import ( "github.com/Brawl345/gobot/plugin" "github.com/Brawl345/gobot/utils" "github.com/Brawl345/gobot/utils/httpUtils" + "github.com/PaulSonOfLars/gotgbot/v2" "golang.org/x/exp/slices" ) @@ -92,27 +93,22 @@ func onFileLink(b *gotgbot.Bot, c plugin.GobotContext) error { return nil } + replyParams := &gotgbot.ReplyParameters{ + MessageId: c.EffectiveMessage.MessageId, + } + // Send file through Telegram first if fileSize < utils.MaxFilesizeDownload { - file := telebot.FromURL(url) - if slices.Contains(audioExt, ext) { - err = c.Reply(&telebot.Audio{ - File: file, - }) + _, err = b.SendAudio(c.EffectiveChat.Id, url, &gotgbot.SendAudioOpts{ReplyParameters: replyParams}) } else if slices.Contains(videoExt, ext) { - err = c.Reply(&telebot.Video{ - File: file, - Streaming: true, - }) + _, err = b.SendVideo(c.EffectiveChat.Id, url, + &gotgbot.SendVideoOpts{ReplyParameters: replyParams, SupportsStreaming: true}, + ) } else if slices.Contains(imageExt, ext) && fileSize < utils.MaxPhotosizeUpload { - err = c.Reply(&telebot.Photo{ - File: file, - }) + _, err = b.SendPhoto(c.EffectiveChat.Id, url, &gotgbot.SendPhotoOpts{ReplyParameters: replyParams}) } else { - err = c.Reply(&telebot.Document{ - File: file, - }) + _, err = b.SendDocument(c.EffectiveChat.Id, url, &gotgbot.SendDocumentOpts{ReplyParameters: replyParams}) } } @@ -140,34 +136,21 @@ func onFileLink(b *gotgbot.Bot, c plugin.GobotContext) error { } }(resp.Body) - file := telebot.FromReader(resp.Body) fileName := path.Base(url) + file := gotgbot.NamedFile{File: resp.Body, FileName: fileName} if slices.Contains(audioExt, ext) { - err = c.Reply(&telebot.Audio{ - File: file, - FileName: fileName, - }) + _, err = b.SendAudio(c.EffectiveChat.Id, file, &gotgbot.SendAudioOpts{ReplyParameters: replyParams}) } else if slices.Contains(videoExt, ext) { - err = c.Reply(&telebot.Video{ - File: file, - FileName: fileName, - Streaming: true, - }) + _, err = b.SendVideo(c.EffectiveChat.Id, file, + &gotgbot.SendVideoOpts{ReplyParameters: replyParams, SupportsStreaming: true}, + ) } else if slices.Contains(imageExt, ext) && fileSize < utils.MaxPhotosizeUpload { - err = c.Reply(&telebot.Photo{ - File: file, - }) + _, err = b.SendPhoto(c.EffectiveChat.Id, file, &gotgbot.SendPhotoOpts{ReplyParameters: replyParams}) if err != nil { - err = c.Reply(&telebot.Document{ - File: file, - FileName: fileName, - }) + _, err = b.SendDocument(c.EffectiveChat.Id, file, &gotgbot.SendDocumentOpts{ReplyParameters: replyParams}) } } else { - err = c.Reply(&telebot.Document{ - File: file, - FileName: fileName, - }) + _, err = b.SendDocument(c.EffectiveChat.Id, file, &gotgbot.SendDocumentOpts{ReplyParameters: replyParams}) } if err != nil { log.Err(err). diff --git a/plugin/todo/urbandictionary/api.go b/plugin/urbandictionary/api.go similarity index 100% rename from plugin/todo/urbandictionary/api.go rename to plugin/urbandictionary/api.go diff --git a/plugin/todo/urbandictionary/urbandictionary.go b/plugin/urbandictionary/urbandictionary.go similarity index 95% rename from plugin/todo/urbandictionary/urbandictionary.go rename to plugin/urbandictionary/urbandictionary.go index 7446076..065efbc 100644 --- a/plugin/todo/urbandictionary/urbandictionary.go +++ b/plugin/urbandictionary/urbandictionary.go @@ -10,6 +10,7 @@ import ( "github.com/Brawl345/gobot/plugin" "github.com/Brawl345/gobot/utils" "github.com/Brawl345/gobot/utils/httpUtils" + "github.com/PaulSonOfLars/gotgbot/v2" "github.com/rs/xid" ) @@ -104,6 +105,6 @@ func onUrbanDictionary(b *gotgbot.Bot, c plugin.GobotContext) error { sb.WriteString(fmt.Sprintf(" - πŸ‘Ž %s", utils.FormatThousand(term.Downvotes))) } - _, err := c.EffectiveMessage.Reply(b, sb.String(), utils.DefaultSendOptions()) + _, err = c.EffectiveMessage.Reply(b, sb.String(), utils.DefaultSendOptions()) return err } diff --git a/plugin/todo/urbandictionary/urbandictionary.http b/plugin/urbandictionary/urbandictionary.http similarity index 100% rename from plugin/todo/urbandictionary/urbandictionary.http rename to plugin/urbandictionary/urbandictionary.http diff --git a/plugin/todo/weather/api.go b/plugin/weather/api.go similarity index 100% rename from plugin/todo/weather/api.go rename to plugin/weather/api.go diff --git a/plugin/todo/weather/weather.go b/plugin/weather/weather.go similarity index 83% rename from plugin/todo/weather/weather.go rename to plugin/weather/weather.go index 4d5c60d..ebc08b2 100644 --- a/plugin/todo/weather/weather.go +++ b/plugin/weather/weather.go @@ -12,6 +12,7 @@ import ( "github.com/Brawl345/gobot/plugin" "github.com/Brawl345/gobot/utils" "github.com/Brawl345/gobot/utils/httpUtils" + "github.com/PaulSonOfLars/gotgbot/v2" "github.com/rs/xid" ) @@ -80,10 +81,10 @@ func (p *Plugin) Handlers(botInfo *gotgbot.User) []plugin.Handler { } func (p *Plugin) onWeather(b *gotgbot.Bot, c plugin.GobotContext) error { - _ = c.Notify(telebot.FindingLocation) + _, _ = c.EffectiveChat.SendAction(b, utils.ChatActionFindLocation, nil) var err error - var venue telebot.Venue + var venue gotgbot.Venue if len(c.Matches) > 1 { venue, err = p.geocodingService.Geocode(c.Matches[1]) } else { @@ -92,8 +93,9 @@ func (p *Plugin) onWeather(b *gotgbot.Bot, c plugin.GobotContext) error { if err != nil { if errors.Is(err, model.ErrHomeAddressNotSet) { - return c.Reply("🏠 Dein Heimatort wurde noch nicht gesetzt.\n"+ + _, err := c.EffectiveMessage.Reply(b, "🏠 Dein Heimatort wurde noch nicht gesetzt.\n"+ "Setze ihn mit /home ORT", utils.DefaultSendOptions()) + return err } if errors.Is(err, model.ErrAddressNotFound) { _, err := c.EffectiveMessage.Reply(b, "❌ Ort nicht gefunden.", utils.DefaultSendOptions()) @@ -105,11 +107,12 @@ func (p *Plugin) onWeather(b *gotgbot.Bot, c plugin.GobotContext) error { Int64("user_id", c.EffectiveUser.Id). Str("guid", guid). Msg("error getting location") - return c.Reply(fmt.Sprintf("❌ Ein Fehler ist aufgetreten.%s", utils.EmbedGUID(guid)), + _, err = c.EffectiveMessage.Reply(b, fmt.Sprintf("❌ Es ist ein Fehler aufgetreten.%s", utils.EmbedGUID(guid)), utils.DefaultSendOptions()) + return err } - requestUrl := fmt.Sprintf("https://api.open-meteo.com/v1/forecast?latitude=%f&longitude=%f&daily=weathercode,temperature_2m_max,temperature_2m_min,sunrise,sunset,precipitation_sum,precipitation_hours&hourly=precipitation¤t_weather=true&timezone=Europe/Berlin", venue.Location.Lat, venue.Location.Lng) + requestUrl := fmt.Sprintf("https://api.open-meteo.com/v1/forecast?latitude=%f&longitude=%f&daily=weathercode,temperature_2m_max,temperature_2m_min,sunrise,sunset,precipitation_sum,precipitation_hours&hourly=precipitation¤t_weather=true&timezone=Europe/Berlin", venue.Location.Latitude, venue.Location.Longitude) var response Response err = httpUtils.GetRequest(requestUrl, &response) @@ -119,8 +122,9 @@ func (p *Plugin) onWeather(b *gotgbot.Bot, c plugin.GobotContext) error { Err(err). Str("guid", guid). Msg("error getting weather") - return c.Reply(fmt.Sprintf("❌ Ein Fehler ist aufgetreten.%s", utils.EmbedGUID(guid)), + _, err = c.EffectiveMessage.Reply(b, fmt.Sprintf("❌ Es ist ein Fehler aufgetreten.%s", utils.EmbedGUID(guid)), utils.DefaultSendOptions()) + return err } var sb strings.Builder @@ -251,15 +255,15 @@ func (p *Plugin) onWeather(b *gotgbot.Bot, c plugin.GobotContext) error { ), ) - _, err := c.EffectiveMessage.Reply(b, sb.String(), utils.DefaultSendOptions()) + _, err = c.EffectiveMessage.Reply(b, sb.String(), utils.DefaultSendOptions()) return err } func (p *Plugin) onForecast(b *gotgbot.Bot, c plugin.GobotContext) error { - _ = c.Notify(telebot.FindingLocation) + _, _ = c.EffectiveChat.SendAction(b, utils.ChatActionFindLocation, nil) var err error - var venue telebot.Venue + var venue gotgbot.Venue if len(c.Matches) > 1 { venue, err = p.geocodingService.Geocode(c.Matches[1]) } else { @@ -268,8 +272,9 @@ func (p *Plugin) onForecast(b *gotgbot.Bot, c plugin.GobotContext) error { if err != nil { if errors.Is(err, model.ErrHomeAddressNotSet) { - return c.Reply("🏠 Dein Heimatort wurde noch nicht gesetzt.\n"+ + _, err := c.EffectiveMessage.Reply(b, "🏠 Dein Heimatort wurde noch nicht gesetzt.\n"+ "Setze ihn mit /home ORT", utils.DefaultSendOptions()) + return err } if errors.Is(err, model.ErrAddressNotFound) { _, err := c.EffectiveMessage.Reply(b, "❌ Ort nicht gefunden.", utils.DefaultSendOptions()) @@ -281,11 +286,12 @@ func (p *Plugin) onForecast(b *gotgbot.Bot, c plugin.GobotContext) error { Int64("user_id", c.EffectiveUser.Id). Str("guid", guid). Msg("error getting location") - return c.Reply(fmt.Sprintf("❌ Ein Fehler ist aufgetreten.%s", utils.EmbedGUID(guid)), + _, err = c.EffectiveMessage.Reply(b, fmt.Sprintf("❌ Es ist ein Fehler aufgetreten.%s", utils.EmbedGUID(guid)), utils.DefaultSendOptions()) + return err } - requestUrl := fmt.Sprintf("https://api.open-meteo.com/v1/forecast?latitude=%f&longitude=%f&daily=weathercode,temperature_2m_max,temperature_2m_min&timezone=Europe/Berlin", venue.Location.Lat, venue.Location.Lng) + requestUrl := fmt.Sprintf("https://api.open-meteo.com/v1/forecast?latitude=%f&longitude=%f&daily=weathercode,temperature_2m_max,temperature_2m_min&timezone=Europe/Berlin", venue.Location.Latitude, venue.Location.Longitude) var response Response err = httpUtils.GetRequest(requestUrl, &response) @@ -295,8 +301,9 @@ func (p *Plugin) onForecast(b *gotgbot.Bot, c plugin.GobotContext) error { Err(err). Str("guid", guid). Msg("error getting weather") - return c.Reply(fmt.Sprintf("❌ Ein Fehler ist aufgetreten.%s", utils.EmbedGUID(guid)), + _, err = c.EffectiveMessage.Reply(b, fmt.Sprintf("❌ Es ist ein Fehler aufgetreten.%s", utils.EmbedGUID(guid)), utils.DefaultSendOptions()) + return err } var sb strings.Builder @@ -323,15 +330,15 @@ func (p *Plugin) onForecast(b *gotgbot.Bot, c plugin.GobotContext) error { sb.WriteString("\n") } - _, err := c.EffectiveMessage.Reply(b, sb.String(), utils.DefaultSendOptions()) + _, err = c.EffectiveMessage.Reply(b, sb.String(), utils.DefaultSendOptions()) return err } func (p *Plugin) onHourlyForecast(b *gotgbot.Bot, c plugin.GobotContext) error { - _ = c.Notify(telebot.FindingLocation) + _, _ = c.EffectiveChat.SendAction(b, utils.ChatActionFindLocation, nil) var err error - var venue telebot.Venue + var venue gotgbot.Venue if len(c.Matches) > 1 { venue, err = p.geocodingService.Geocode(c.Matches[1]) } else { @@ -340,8 +347,9 @@ func (p *Plugin) onHourlyForecast(b *gotgbot.Bot, c plugin.GobotContext) error { if err != nil { if errors.Is(err, model.ErrHomeAddressNotSet) { - return c.Reply("🏠 Dein Heimatort wurde noch nicht gesetzt.\n"+ + _, err := c.EffectiveMessage.Reply(b, "🏠 Dein Heimatort wurde noch nicht gesetzt.\n"+ "Setze ihn mit /home ORT", utils.DefaultSendOptions()) + return err } if errors.Is(err, model.ErrAddressNotFound) { _, err := c.EffectiveMessage.Reply(b, "❌ Ort nicht gefunden.", utils.DefaultSendOptions()) @@ -353,11 +361,12 @@ func (p *Plugin) onHourlyForecast(b *gotgbot.Bot, c plugin.GobotContext) error { Int64("user_id", c.EffectiveUser.Id). Str("guid", guid). Msg("error getting location") - return c.Reply(fmt.Sprintf("❌ Ein Fehler ist aufgetreten.%s", utils.EmbedGUID(guid)), + _, err = c.EffectiveMessage.Reply(b, fmt.Sprintf("❌ Es ist ein Fehler aufgetreten.%s", utils.EmbedGUID(guid)), utils.DefaultSendOptions()) + return err } - requestUrl := fmt.Sprintf("https://api.open-meteo.com/v1/forecast?latitude=%f&longitude=%f&hourly=temperature_2m,weathercode&timezone=Europe/Berlin", venue.Location.Lat, venue.Location.Lng) + requestUrl := fmt.Sprintf("https://api.open-meteo.com/v1/forecast?latitude=%f&longitude=%f&hourly=temperature_2m,weathercode&timezone=Europe/Berlin", venue.Location.Latitude, venue.Location.Longitude) var response Response err = httpUtils.GetRequest(requestUrl, &response) @@ -367,8 +376,9 @@ func (p *Plugin) onHourlyForecast(b *gotgbot.Bot, c plugin.GobotContext) error { Err(err). Str("guid", guid). Msg("error getting weather") - return c.Reply(fmt.Sprintf("❌ Ein Fehler ist aufgetreten.%s", utils.EmbedGUID(guid)), + _, err = c.EffectiveMessage.Reply(b, fmt.Sprintf("❌ Es ist ein Fehler aufgetreten.%s", utils.EmbedGUID(guid)), utils.DefaultSendOptions()) + return err } var sb strings.Builder @@ -401,6 +411,6 @@ func (p *Plugin) onHourlyForecast(b *gotgbot.Bot, c plugin.GobotContext) error { } } - _, err := c.EffectiveMessage.Reply(b, sb.String(), utils.DefaultSendOptions()) + _, err = c.EffectiveMessage.Reply(b, sb.String(), utils.DefaultSendOptions()) return err } diff --git a/plugin/todo/weather/weather.http b/plugin/weather/weather.http similarity index 100% rename from plugin/todo/weather/weather.http rename to plugin/weather/weather.http diff --git a/plugin/todo/weather/weathercode.go b/plugin/weather/weathercode.go similarity index 100% rename from plugin/todo/weather/weathercode.go rename to plugin/weather/weathercode.go diff --git a/plugin/todo/wikipedia/api.go b/plugin/wikipedia/api.go similarity index 100% rename from plugin/todo/wikipedia/api.go rename to plugin/wikipedia/api.go diff --git a/plugin/todo/wikipedia/wikipedia.go b/plugin/wikipedia/wikipedia.go similarity index 82% rename from plugin/todo/wikipedia/wikipedia.go rename to plugin/wikipedia/wikipedia.go index 2bca616..4323297 100644 --- a/plugin/todo/wikipedia/wikipedia.go +++ b/plugin/wikipedia/wikipedia.go @@ -12,8 +12,8 @@ import ( "github.com/Brawl345/gobot/plugin" "github.com/Brawl345/gobot/utils" "github.com/Brawl345/gobot/utils/httpUtils" + "github.com/PaulSonOfLars/gotgbot/v2" "github.com/rs/xid" - "gopkg.in/telebot.v3" ) var log = logger.New("wikipedia") @@ -82,8 +82,9 @@ func onArticle(b *gotgbot.Bot, c plugin.GobotContext) error { Str("guid", guid). Str("query", query). Msg("Failed to unescape query") - return c.Reply(fmt.Sprintf("❌ Es ist ein Fehler aufgetreten.%s", utils.EmbedGUID(guid)), + _, err = c.EffectiveMessage.Reply(b, fmt.Sprintf("❌ Es ist ein Fehler aufgetreten.%s", utils.EmbedGUID(guid)), utils.DefaultSendOptions()) + return err } requestUrl := url.URL{ @@ -113,7 +114,8 @@ func onArticle(b *gotgbot.Bot, c plugin.GobotContext) error { if err != nil { var noSuchHostErr *net.DNSError if errors.As(err, &noSuchHostErr) { - return c.Reply("❌ Diese Wikipedia-Sprachversion existiert nicht.") + _, err := c.EffectiveMessage.Reply(b, "❌ Diese Wikipedia-Sprachversion existiert nicht.", nil) + return err } guid := xid.New().String() @@ -121,8 +123,9 @@ func onArticle(b *gotgbot.Bot, c plugin.GobotContext) error { Str("guid", guid). Str("query", query). Msg("Failed to get Wikipedia response") - return c.Reply(fmt.Sprintf("❌ Es ist ein Fehler aufgetreten.%s", utils.EmbedGUID(guid)), + _, err = c.EffectiveMessage.Reply(b, fmt.Sprintf("❌ Es ist ein Fehler aufgetreten.%s", utils.EmbedGUID(guid)), utils.DefaultSendOptions()) + return err } if len(response.Query.Pages) == 0 { @@ -159,7 +162,7 @@ func onArticle(b *gotgbot.Bot, c plugin.GobotContext) error { // Need to parse the disambiguation page manually requestUrl := url.URL{ Scheme: "https", - Host: "de.wikipedia.org", + Host: fmt.Sprintf("%s.wikipedia.org", lang), Path: "/w/api.php", } @@ -183,8 +186,9 @@ func onArticle(b *gotgbot.Bot, c plugin.GobotContext) error { Str("guid", guid). Str("query", query). Msg("Failed to get disambiugation response") - return c.Reply(fmt.Sprintf("❌ Es ist ein Fehler aufgetreten.%s", utils.EmbedGUID(guid)), + _, err = c.EffectiveMessage.Reply(b, fmt.Sprintf("❌ Es ist ein Fehler aufgetreten.%s", utils.EmbedGUID(guid)), utils.DefaultSendOptions()) + return err } matches := regexDisambiguation.FindAllStringSubmatch(response.Query.Pages[0].Text, -1) @@ -201,22 +205,23 @@ func onArticle(b *gotgbot.Bot, c plugin.GobotContext) error { } } - return c.Reply(sb.String(), &telebot.SendOptions{ - AllowWithoutReply: true, - DisableWebPagePreview: true, - DisableNotification: true, - ParseMode: telebot.ModeHTML, - ReplyMarkup: &telebot.ReplyMarkup{ - InlineKeyboard: [][]telebot.InlineButton{ + _, err = c.EffectiveMessage.Reply(b, sb.String(), &gotgbot.SendMessageOpts{ + ReplyParameters: &gotgbot.ReplyParameters{AllowSendingWithoutReply: true}, + LinkPreviewOptions: &gotgbot.LinkPreviewOptions{IsDisabled: true}, + DisableNotification: true, + ParseMode: gotgbot.ParseModeHTML, + ReplyMarkup: &gotgbot.InlineKeyboardMarkup{ + InlineKeyboard: [][]gotgbot.InlineKeyboardButton{ { { Text: "...weitere?", - URL: article.URL, + Url: article.URL, }, }, }, }, }) + return err } if section != "" { @@ -228,8 +233,9 @@ func onArticle(b *gotgbot.Bot, c plugin.GobotContext) error { Str("query", query). Str("section", section). Msg("Failed to unescape section") - return c.Reply(fmt.Sprintf("❌ Es ist ein Fehler aufgetreten.%s", utils.EmbedGUID(guid)), + _, err = c.EffectiveMessage.Reply(b, fmt.Sprintf("❌ Es ist ein Fehler aufgetreten.%s", utils.EmbedGUID(guid)), utils.DefaultSendOptions()) + return err } matches := regexSection.FindAllStringSubmatch(article.Text, -1) for _, match := range matches { @@ -262,6 +268,6 @@ func onArticle(b *gotgbot.Bot, c plugin.GobotContext) error { ), ) - _, err := c.EffectiveMessage.Reply(b, sb.String(), utils.DefaultSendOptions()) + _, err = c.EffectiveMessage.Reply(b, sb.String(), utils.DefaultSendOptions()) return err } diff --git a/plugin/todo/wikipedia/wikipedia.http b/plugin/wikipedia/wikipedia.http similarity index 100% rename from plugin/todo/wikipedia/wikipedia.http rename to plugin/wikipedia/wikipedia.http diff --git a/plugin/todo/worldclock/api.go b/plugin/worldclock/api.go similarity index 100% rename from plugin/todo/worldclock/api.go rename to plugin/worldclock/api.go diff --git a/plugin/todo/worldclock/worldclock.go b/plugin/worldclock/worldclock.go similarity index 90% rename from plugin/todo/worldclock/worldclock.go rename to plugin/worldclock/worldclock.go index 77037c0..6ec162a 100644 --- a/plugin/todo/worldclock/worldclock.go +++ b/plugin/worldclock/worldclock.go @@ -12,6 +12,7 @@ import ( "github.com/Brawl345/gobot/plugin" "github.com/Brawl345/gobot/utils" "github.com/Brawl345/gobot/utils/httpUtils" + "github.com/PaulSonOfLars/gotgbot/v2" "github.com/rs/xid" ) @@ -81,14 +82,15 @@ func (p *Plugin) onTime(b *gotgbot.Bot, c plugin.GobotContext) error { Str("guid", guid). Str("location", c.Matches[1]). Msg("Failed to get coordinates for location") - return c.Reply(fmt.Sprintf("❌ Fehler beim Abrufen der Koordinaten.%s", utils.EmbedGUID(guid)), + _, err = c.EffectiveMessage.Reply(b, fmt.Sprintf("❌ Fehler beim Abrufen der Koordinaten.%s", utils.EmbedGUID(guid)), utils.DefaultSendOptions()) + return err } requestUrl := url.URL{ Scheme: "https", Host: "dev.virtualearth.net", - Path: fmt.Sprintf("/REST/v1/TimeZone/%f,%f", venue.Location.Lat, venue.Location.Lng), + Path: fmt.Sprintf("/REST/v1/TimeZone/%f,%f", venue.Location.Latitude, venue.Location.Longitude), } q := requestUrl.Query() @@ -112,8 +114,10 @@ func (p *Plugin) onTime(b *gotgbot.Bot, c plugin.GobotContext) error { Str("guid", guid). Str("url", requestUrl.String()). Msg("error requesting API") - return c.Reply(fmt.Sprintf("❌ Ein Fehler ist aufgetreten.%s", utils.EmbedGUID(guid)), + + _, err := c.EffectiveMessage.Reply(b, fmt.Sprintf("❌ Es ist ein Fehler aufgetreten.%s", utils.EmbedGUID(guid)), utils.DefaultSendOptions()) + return err } if len(response.ResourceSets) == 0 || len(response.ResourceSets[0].Resources) == 0 { @@ -158,6 +162,6 @@ func (p *Plugin) onTime(b *gotgbot.Bot, c plugin.GobotContext) error { ), ) - _, err := c.EffectiveMessage.Reply(b, sb.String(), utils.DefaultSendOptions()) + _, err = c.EffectiveMessage.Reply(b, sb.String(), utils.DefaultSendOptions()) return err } diff --git a/plugin/todo/worldclock/worldclock.http b/plugin/worldclock/worldclock.http similarity index 100% rename from plugin/todo/worldclock/worldclock.http rename to plugin/worldclock/worldclock.http diff --git a/plugin/todo/youtube/api.go b/plugin/youtube/api.go similarity index 100% rename from plugin/todo/youtube/api.go rename to plugin/youtube/api.go diff --git a/plugin/todo/youtube/youtube.go b/plugin/youtube/youtube.go similarity index 92% rename from plugin/todo/youtube/youtube.go rename to plugin/youtube/youtube.go index af6f3c9..7d47e85 100644 --- a/plugin/todo/youtube/youtube.go +++ b/plugin/youtube/youtube.go @@ -12,6 +12,7 @@ import ( "github.com/Brawl345/gobot/plugin" "github.com/Brawl345/gobot/utils" "github.com/Brawl345/gobot/utils/httpUtils" + "github.com/PaulSonOfLars/gotgbot/v2" "github.com/rs/xid" ) @@ -298,7 +299,8 @@ func (p *Plugin) OnYouTubeLink(b *gotgbot.Bot, c plugin.GobotContext) error { if err != nil { if errors.Is(err, ErrNoVideoFound) { - return c.Reply("❌ Video nicht gefunden") + _, err := c.EffectiveMessage.Reply(b, "❌ Video nicht gefunden", nil) + return err } guid := xid.New().String() @@ -312,7 +314,7 @@ func (p *Plugin) OnYouTubeLink(b *gotgbot.Bot, c plugin.GobotContext) error { text := constructText(&video) - msg, err := c.Bot().Reply(c.EffectiveMessage, text, utils.DefaultSendOptions()) + msg, err := c.EffectiveMessage.Reply(b, text, utils.DefaultSendOptions()) if err == nil { modifiedText, err := deArrow(text, &video) if err != nil { @@ -322,7 +324,9 @@ func (p *Plugin) OnYouTubeLink(b *gotgbot.Bot, c plugin.GobotContext) error { return nil } - _, err = c.Bot().Edit(msg, modifiedText, utils.DefaultSendOptions()) + _, _, err = msg.EditText(b, modifiedText, &gotgbot.EditMessageTextOpts{ + ParseMode: gotgbot.ParseModeHTML, + }) } return err @@ -370,7 +374,8 @@ func (p *Plugin) onYouTubeSearch(b *gotgbot.Bot, c plugin.GobotContext) error { if err != nil { if errors.Is(err, ErrNoVideoFound) { - return c.Reply("❌ Video nicht gefunden") + _, err := c.EffectiveMessage.Reply(b, "❌ Video nicht gefunden", nil) + return err } guid := xid.New().String() @@ -387,10 +392,10 @@ func (p *Plugin) onYouTubeSearch(b *gotgbot.Bot, c plugin.GobotContext) error { sb.WriteString(constructText(&video)) text := sb.String() - msg, err := c.Bot().Reply(c.EffectiveMessage, text, &telebot.SendOptions{ - AllowWithoutReply: true, + msg, err := c.EffectiveMessage.Reply(b, text, &gotgbot.SendMessageOpts{ + ReplyParameters: &gotgbot.ReplyParameters{AllowSendingWithoutReply: true}, DisableNotification: true, - ParseMode: telebot.ModeHTML, + ParseMode: gotgbot.ParseModeHTML, }) if err == nil { @@ -402,10 +407,8 @@ func (p *Plugin) onYouTubeSearch(b *gotgbot.Bot, c plugin.GobotContext) error { return nil } - _, err = c.Bot().Edit(msg, modifiedText, &telebot.SendOptions{ - AllowWithoutReply: true, - DisableNotification: true, - ParseMode: telebot.ModeHTML, + _, _, err = msg.EditText(b, modifiedText, &gotgbot.EditMessageTextOpts{ + ParseMode: gotgbot.ParseModeHTML, }) } diff --git a/plugin/todo/youtube/youtube.http b/plugin/youtube/youtube.http similarity index 100% rename from plugin/todo/youtube/youtube.http rename to plugin/youtube/youtube.http diff --git a/utils/const.go b/utils/const.go index 55300da..1113064 100644 --- a/utils/const.go +++ b/utils/const.go @@ -30,6 +30,7 @@ const ( ChatActionFindLocation = "find_location" ChatActionUploadDocument = "upload_document" ChatActionUploadPhoto = "upload_photo" + ChatActionUploadVideo = "upload_video" ChatActionTyping = "typing" ChatMemberStatusCreator = "creator"