Skip to content

Commit

Permalink
core: Update gotgbot to v2.0.0-rc.28
Browse files Browse the repository at this point in the history
  • Loading branch information
Brawl345 committed Jul 2, 2024
1 parent 182efd6 commit 53611f9
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 35 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
5 changes: 1 addition & 4 deletions plugin/dcrypt/dcrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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!",
Expand Down
4 changes: 2 additions & 2 deletions plugin/google_images/google_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions plugin/twitter/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/Brawl345/gobot/utils"
"github.com/PaulSonOfLars/gotgbot/v2"
)

const (
Expand Down Expand Up @@ -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() {
Expand Down
48 changes: 27 additions & 21 deletions plugin/twitter/twitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()})
}
}

Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions plugin/upload_by_url/upload_by_url.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
}
}

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 53611f9

Please sign in to comment.