diff --git a/go.mod b/go.mod index 1746428..f1edb4e 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/Brawl345/gobot go 1.22 require ( - github.com/PaulSonOfLars/gotgbot/v2 v2.0.0-rc.27 + github.com/PaulSonOfLars/gotgbot/v2 v2.0.0-rc.28 github.com/go-shiori/go-readability v0.0.0-20240518065624-0b7c0223026a github.com/go-sql-driver/mysql v1.8.1 github.com/jmoiron/sqlx v1.4.0 diff --git a/go.sum b/go.sum index 85d0528..d3a0e4e 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= -github.com/PaulSonOfLars/gotgbot/v2 v2.0.0-rc.27 h1:rOlGzmYC3jPVPLVLWKMiiYuePQ6MV8Cyw5qJYBoMnkY= -github.com/PaulSonOfLars/gotgbot/v2 v2.0.0-rc.27/go.mod h1:kL1v4iIjlalwm3gCYGvF4NLa3hs+aKEfRkNJvj4aoDU= +github.com/PaulSonOfLars/gotgbot/v2 v2.0.0-rc.28 h1:3EidAXUUuDBwaRX5881fmpGGv2WPnW9oHwRMlvdQiwU= +github.com/PaulSonOfLars/gotgbot/v2 v2.0.0-rc.28/go.mod h1:kL1v4iIjlalwm3gCYGvF4NLa3hs+aKEfRkNJvj4aoDU= github.com/andybalholm/cascadia v1.3.2 h1:3Xi6Dw5lHF15JtdcmAHD3i1+T8plmv7BQ/nsViSLyss= github.com/andybalholm/cascadia v1.3.2/go.mod h1:7gtRlve5FxPPgIgX36uWBX58OdBsSS6lUvCFb+h7KvU= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= diff --git a/plugin/dcrypt/dcrypt.go b/plugin/dcrypt/dcrypt.go index f4a3ca9..455f3de 100644 --- a/plugin/dcrypt/dcrypt.go +++ b/plugin/dcrypt/dcrypt.go @@ -174,10 +174,7 @@ func (p *Plugin) OnFile(b *gotgbot.Bot, c plugin.GobotContext) error { } buf := bytes.NewBufferString(sb.String()) - document := &gotgbot.NamedFile{ - File: buf, - FileName: filename, - } + document := gotgbot.InputFileByReader(filename, buf) _, err = b.SendDocument(c.EffectiveChat.Id, document, &gotgbot.SendDocumentOpts{ Caption: "🔑 Hier sind deine entschlüsselten Links!", diff --git a/plugin/google_images/google_images.go b/plugin/google_images/google_images.go index 5cec386..ef9798f 100644 --- a/plugin/google_images/google_images.go +++ b/plugin/google_images/google_images.go @@ -213,7 +213,7 @@ func (p *Plugin) doImageSearch(b *gotgbot.Bot, c *plugin.GobotContext) error { } if image.IsGIF() { - _, err = b.SendDocument(c.EffectiveChat.Id, image.ImageLink(), &gotgbot.SendDocumentOpts{ + _, err = b.SendDocument(c.EffectiveChat.Id, gotgbot.InputFileByURL(image.ImageLink()), &gotgbot.SendDocumentOpts{ Caption: caption, ReplyParameters: &gotgbot.ReplyParameters{ AllowSendingWithoutReply: true, @@ -224,7 +224,7 @@ func (p *Plugin) doImageSearch(b *gotgbot.Bot, c *plugin.GobotContext) error { ReplyMarkup: replyMarkup, }) } else { - _, err = b.SendPhoto(c.EffectiveChat.Id, image.ImageLink(), &gotgbot.SendPhotoOpts{ + _, err = b.SendPhoto(c.EffectiveChat.Id, gotgbot.InputFileByURL(image.ImageLink()), &gotgbot.SendPhotoOpts{ Caption: caption, ReplyParameters: &gotgbot.ReplyParameters{ AllowSendingWithoutReply: true, diff --git a/plugin/twitter/api.go b/plugin/twitter/api.go index 3bf5b2e..875b44b 100644 --- a/plugin/twitter/api.go +++ b/plugin/twitter/api.go @@ -7,6 +7,7 @@ import ( "time" "github.com/Brawl345/gobot/utils" + "github.com/PaulSonOfLars/gotgbot/v2" ) const ( @@ -405,6 +406,10 @@ func (m *Medium) Link() string { return highestResURL } +func (m *Medium) InputFile() gotgbot.InputFileOrString { + return gotgbot.InputFileByURL(m.Link()) +} + func (m *Medium) Caption() string { var caption string if m.IsVideo() { diff --git a/plugin/twitter/twitter.go b/plugin/twitter/twitter.go index 634a848..0e3df22 100644 --- a/plugin/twitter/twitter.go +++ b/plugin/twitter/twitter.go @@ -439,9 +439,9 @@ func (p *Plugin) OnStatus(b *gotgbot.Bot, c plugin.GobotContext) error { for _, medium := range media { if medium.IsPhoto() { - album = append(album, gotgbot.InputMediaPhoto{Caption: medium.Caption(), Media: medium.Link()}) + album = append(album, gotgbot.InputMediaPhoto{Caption: medium.Caption(), Media: medium.InputFile()}) } else if medium.IsVideo() { - album = append(album, gotgbot.InputMediaVideo{Caption: medium.Caption(), Media: medium.Link()}) + album = append(album, gotgbot.InputMediaVideo{Caption: medium.Caption(), Media: medium.InputFile()}) } } @@ -496,19 +496,23 @@ func (p *Plugin) OnStatus(b *gotgbot.Bot, c plugin.GobotContext) error { }(resp.Body) if medium.IsPhoto() { - _, err = b.SendPhoto(c.EffectiveChat.Id, resp.Body, &gotgbot.SendPhotoOpts{ - ReplyParameters: &gotgbot.ReplyParameters{AllowSendingWithoutReply: true, - MessageId: c.EffectiveMessage.MessageId}, - DisableNotification: true, - }) + _, err = b.SendPhoto(c.EffectiveChat.Id, gotgbot.InputFileByReader(medium.IdStr, resp.Body), + &gotgbot.SendPhotoOpts{ + ReplyParameters: &gotgbot.ReplyParameters{AllowSendingWithoutReply: true, + MessageId: c.EffectiveMessage.MessageId}, + DisableNotification: true, + }, + ) } else { - _, 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, - }) + _, err = b.SendVideo(c.EffectiveChat.Id, gotgbot.InputFileByReader(medium.IdStr, 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 @@ -534,7 +538,7 @@ func (p *Plugin) OnStatus(b *gotgbot.Bot, c plugin.GobotContext) error { for _, gif := range gifs { _, err := b.SendAnimation(c.EffectiveChat.Id, - gif.Link(), + gif.InputFile(), &gotgbot.SendAnimationOpts{ Caption: gif.Caption(), ReplyParameters: &gotgbot.ReplyParameters{AllowSendingWithoutReply: true, @@ -570,12 +574,14 @@ func (p *Plugin) OnStatus(b *gotgbot.Bot, c plugin.GobotContext) error { } }(resp.Body) - _, err = b.SendAnimation(c.EffectiveChat.Id, resp.Body, &gotgbot.SendAnimationOpts{ - Caption: gif.Caption(), - ReplyParameters: &gotgbot.ReplyParameters{AllowSendingWithoutReply: true, - MessageId: c.EffectiveMessage.MessageId}, - DisableNotification: true, - }) + _, err = b.SendAnimation(c.EffectiveChat.Id, gotgbot.InputFileByReader(gif.IdStr, resp.Body), + &gotgbot.SendAnimationOpts{ + Caption: gif.Caption(), + ReplyParameters: &gotgbot.ReplyParameters{AllowSendingWithoutReply: true, + MessageId: c.EffectiveMessage.MessageId}, + DisableNotification: true, + }, + ) if err != nil { // Last resort: Send URL as text diff --git a/plugin/upload_by_url/upload_by_url.go b/plugin/upload_by_url/upload_by_url.go index 5edd4ec..197ee9e 100644 --- a/plugin/upload_by_url/upload_by_url.go +++ b/plugin/upload_by_url/upload_by_url.go @@ -101,15 +101,15 @@ func onFileLink(b *gotgbot.Bot, c plugin.GobotContext) error { // Send file through Telegram first if fileSize < tgUtils.MaxFilesizeDownload { if slices.Contains(audioExt, ext) { - _, err = b.SendAudio(c.EffectiveChat.Id, url, &gotgbot.SendAudioOpts{ReplyParameters: replyParams}) + _, err = b.SendAudio(c.EffectiveChat.Id, gotgbot.InputFileByURL(url), &gotgbot.SendAudioOpts{ReplyParameters: replyParams}) } else if slices.Contains(videoExt, ext) { - _, err = b.SendVideo(c.EffectiveChat.Id, url, + _, err = b.SendVideo(c.EffectiveChat.Id, gotgbot.InputFileByURL(url), &gotgbot.SendVideoOpts{ReplyParameters: replyParams, SupportsStreaming: true}, ) } else if slices.Contains(imageExt, ext) && fileSize < tgUtils.MaxPhotosizeUpload { - _, err = b.SendPhoto(c.EffectiveChat.Id, url, &gotgbot.SendPhotoOpts{ReplyParameters: replyParams}) + _, err = b.SendPhoto(c.EffectiveChat.Id, gotgbot.InputFileByURL(url), &gotgbot.SendPhotoOpts{ReplyParameters: replyParams}) } else { - _, err = b.SendDocument(c.EffectiveChat.Id, url, &gotgbot.SendDocumentOpts{ReplyParameters: replyParams}) + _, err = b.SendDocument(c.EffectiveChat.Id, gotgbot.InputFileByURL(url), &gotgbot.SendDocumentOpts{ReplyParameters: replyParams}) } } @@ -138,7 +138,8 @@ func onFileLink(b *gotgbot.Bot, c plugin.GobotContext) error { }(resp.Body) fileName := path.Base(url) - file := gotgbot.NamedFile{File: resp.Body, FileName: fileName} + + file := gotgbot.InputFileByReader(fileName, resp.Body) if slices.Contains(audioExt, ext) { _, err = b.SendAudio(c.EffectiveChat.Id, file, &gotgbot.SendAudioOpts{ReplyParameters: replyParams}) } else if slices.Contains(videoExt, ext) {