Skip to content

Commit b553d48

Browse files
committed
use link preview instead of send photo
1 parent e34e19a commit b553d48

File tree

5 files changed

+117
-132
lines changed

5 files changed

+117
-132
lines changed

bot/handlers_common.go

+22-39
Original file line numberDiff line numberDiff line change
@@ -301,56 +301,39 @@ func getArtworkInfo(ctx context.Context, bot *telego.Bot, message telego.Message
301301
}
302302
}
303303

304-
var inputFile telego.InputFile
305-
if artwork.Pictures[0].TelegramInfo == nil || artwork.Pictures[0].TelegramInfo.PhotoFileID == "" {
306-
fileBytes, err := common.DownloadWithCache(artwork.Pictures[0].Original, nil)
307-
if err != nil {
308-
telegram.ReplyMessage(bot, message, "下载图片失败: "+err.Error())
309-
return
310-
}
311-
fileBytes, err = common.CompressImage(fileBytes, 5, 2560)
312-
if err != nil {
313-
telegram.ReplyMessage(bot, message, "压缩图片失败: "+err.Error())
314-
return
315-
}
316-
inputFile = telegoutil.File(telegoutil.NameReader(bytes.NewReader(fileBytes), artwork.Title))
317-
} else {
318-
inputFile = telegoutil.FileFromID(artwork.Pictures[0].TelegramInfo.PhotoFileID)
319-
}
320-
321-
photo := telegoutil.Photo(message.Chat.ChatID(), inputFile).
322-
WithReplyParameters(&telego.ReplyParameters{MessageID: message.MessageID}).
323-
WithParseMode(telego.ModeHTML)
324-
325-
deletedModel, _ := service.GetDeletedByURL(ctx, sourceURL)
326-
artworkInfoCaption := telegram.GetArtworkHTMLCaption(artwork)
327-
if deletedModel != nil && hasPermission {
328-
photo.WithCaption(artworkInfoCaption + fmt.Sprintf("\n\n这是一个在 %s 删除的作品\n如果发布则会取消删除", deletedModel.DeletedAt.Time().Format("2006-01-02 15:04:05")))
329-
} else {
330-
artworkInfoCaption += fmt.Sprintf("\n该作品共有%d张图片", len(artwork.Pictures))
331-
photo.WithCaption(artworkInfoCaption)
304+
text := telegram.GetArtworkHTMLCaption(artwork) + fmt.Sprintf("\n该作品共有%d张图片", len(artwork.Pictures))
305+
deleteModel, _ := service.GetDeletedByURL(ctx, sourceURL)
306+
if deleteModel != nil && hasPermission {
307+
text += fmt.Sprintf("\n\n这是一个在 %s 删除的作品\n如果发布则会取消删除", deleteModel.DeletedAt.Time().Format("2006-01-02 15:04:05"))
332308
}
309+
var replyMarkup telego.ReplyMarkup
333310
if isAlreadyPosted {
334-
photo.WithReplyMarkup(telegram.GetPostedPictureReplyMarkup(artwork.Pictures[0]))
311+
replyMarkup = telegram.GetPostedPictureReplyMarkup(artwork.Pictures[0])
335312
} else if hasPermission {
336-
id, err := service.CreateCallbackData(ctx, artwork.SourceURL)
313+
cbId, err := service.CreateCallbackData(ctx, artwork.SourceURL)
337314
if err != nil {
338315
telegram.ReplyMessage(bot, message, "创建回调数据失败: "+err.Error())
339316
return
340317
}
341-
photo.WithReplyMarkup(telegoutil.InlineKeyboard(
318+
replyMarkup = telegoutil.InlineKeyboard(
342319
[]telego.InlineKeyboardButton{
343-
telegoutil.InlineKeyboardButton("发布").WithCallbackData("post_artwork " + id),
344-
telegoutil.InlineKeyboardButton("设为R18并发布").WithCallbackData("post_artwork_r18 " + id),
320+
telegoutil.InlineKeyboardButton("发布").WithCallbackData("post_artwork " + cbId),
321+
telegoutil.InlineKeyboardButton("设为R18并发布").WithCallbackData("post_artwork_r18 " + cbId),
345322
},
346-
))
347-
}
348-
if artwork.R18 {
349-
photo.WithHasSpoiler()
323+
)
350324
}
351-
_, err = bot.SendPhoto(photo)
325+
_, err = bot.SendMessage(telegoutil.Message(message.Chat.ChatID(), text).
326+
WithReplyMarkup(replyMarkup).
327+
WithReplyParameters(&telego.ReplyParameters{MessageID: message.MessageID}).
328+
WithParseMode(telego.ModeHTML).
329+
WithLinkPreviewOptions(
330+
&telego.LinkPreviewOptions{
331+
URL: artwork.Pictures[0].Original,
332+
ShowAboveText: true,
333+
},
334+
))
352335
if err != nil {
353-
telegram.ReplyMessage(bot, message, "发送图片失败: "+err.Error())
336+
Logger.Errorf("发送消息失败: %s", err)
354337
}
355338
}
356339

cmd/version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
const (
10-
Version string = "0.10.10"
10+
Version string = "0.10.11"
1111
)
1212

1313
var VersionCmd = &cobra.Command{

go.mod

+29-29
Original file line numberDiff line numberDiff line change
@@ -9,83 +9,83 @@ require (
99
github.com/google/uuid v1.6.0
1010
github.com/gookit/slog v0.5.6
1111
github.com/rhysd/go-github-selfupdate v1.2.3
12-
github.com/spf13/cobra v1.8.0
13-
github.com/spf13/viper v1.18.2
12+
github.com/spf13/cobra v1.8.1
13+
github.com/spf13/viper v1.19.0
1414
github.com/studio-b12/gowebdav v0.9.0
15-
go.mongodb.org/mongo-driver v1.15.0
15+
go.mongodb.org/mongo-driver v1.16.0
1616
golang.org/x/image v0.18.0
1717
)
1818

1919
require (
2020
github.com/andybalholm/brotli v1.1.0 // indirect
21-
github.com/bytedance/sonic v1.11.8 // indirect
21+
github.com/bytedance/sonic v1.11.9 // indirect
2222
github.com/bytedance/sonic/loader v0.1.1 // indirect
23-
github.com/cloudflare/circl v1.3.8 // indirect
23+
github.com/cloudflare/circl v1.3.9 // indirect
2424
github.com/cloudwego/base64x v0.1.4 // indirect
2525
github.com/cloudwego/iasm v0.2.0 // indirect
26-
github.com/fasthttp/router v1.5.1 // indirect
27-
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
26+
github.com/fasthttp/router v1.5.2 // indirect
27+
github.com/gabriel-vasile/mimetype v1.4.4 // indirect
2828
github.com/gin-contrib/sse v0.1.0 // indirect
2929
github.com/go-playground/locales v0.14.1 // indirect
3030
github.com/go-playground/universal-translator v0.18.1 // indirect
31-
github.com/go-playground/validator/v10 v10.20.0 // indirect
31+
github.com/go-playground/validator/v10 v10.22.0 // indirect
3232
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
33-
github.com/goccy/go-json v0.10.2 // indirect
33+
github.com/goccy/go-json v0.10.3 // indirect
3434
github.com/golang/snappy v0.0.4 // indirect
3535
github.com/google/go-github/v30 v30.1.0 // indirect
3636
github.com/google/go-querystring v1.1.0 // indirect
37-
github.com/google/pprof v0.0.0-20240509144519-723abb6459b7 // indirect
37+
github.com/google/pprof v0.0.0-20240711041743-f6c9dda6c6da // indirect
3838
github.com/grbit/go-json v0.11.0 // indirect
3939
github.com/hashicorp/errwrap v1.1.0 // indirect
4040
github.com/hashicorp/go-multierror v1.1.1 // indirect
4141
github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf // indirect
4242
github.com/inconshreveable/mousetrap v1.1.0 // indirect
4343
github.com/json-iterator/go v1.1.12 // indirect
44-
github.com/klauspost/compress v1.17.8 // indirect
45-
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
44+
github.com/klauspost/compress v1.17.9 // indirect
45+
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
4646
github.com/leodido/go-urn v1.4.0 // indirect
4747
github.com/mattn/go-isatty v0.0.20 // indirect
4848
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
4949
github.com/modern-go/reflect2 v1.0.2 // indirect
5050
github.com/montanaflynn/stats v0.7.1 // indirect
5151
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect
52-
github.com/onsi/ginkgo/v2 v2.17.3 // indirect
52+
github.com/onsi/ginkgo/v2 v2.19.0 // indirect
5353
github.com/quic-go/qpack v0.4.0 // indirect
54-
github.com/quic-go/quic-go v0.43.1 // indirect
55-
github.com/refraction-networking/utls v1.6.6 // indirect
56-
github.com/savsgio/gotils v0.0.0-20240303185622-093b76447511 // indirect
54+
github.com/quic-go/quic-go v0.45.1 // indirect
55+
github.com/refraction-networking/utls v1.6.7 // indirect
56+
github.com/savsgio/gotils v0.0.0-20240704082632-aef3928b8a38 // indirect
5757
github.com/tcnksm/go-gitconfig v0.1.2 // indirect
5858
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
5959
github.com/ugorji/go/codec v1.2.12 // indirect
6060
github.com/ulikunitz/xz v0.5.12 // indirect
61-
github.com/valyala/fasthttp v1.54.0 // indirect
61+
github.com/valyala/fasthttp v1.55.0 // indirect
6262
github.com/valyala/fastjson v1.6.4 // indirect
6363
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
6464
github.com/xdg-go/scram v1.1.2 // indirect
6565
github.com/xdg-go/stringprep v1.0.4 // indirect
6666
github.com/youmark/pkcs8 v0.0.0-20240424034433-3c2c7870ae76 // indirect
6767
go.uber.org/mock v0.4.0 // indirect
6868
golang.org/x/arch v0.8.0 // indirect
69-
golang.org/x/crypto v0.23.0 // indirect
70-
golang.org/x/mod v0.17.0 // indirect
71-
golang.org/x/net v0.25.0 // indirect
72-
golang.org/x/oauth2 v0.20.0 // indirect
73-
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
74-
google.golang.org/protobuf v1.34.1 // indirect
69+
golang.org/x/crypto v0.25.0 // indirect
70+
golang.org/x/mod v0.19.0 // indirect
71+
golang.org/x/net v0.27.0 // indirect
72+
golang.org/x/oauth2 v0.21.0 // indirect
73+
golang.org/x/tools v0.23.0 // indirect
74+
google.golang.org/protobuf v1.34.2 // indirect
7575
)
7676

7777
require (
7878
github.com/fsnotify/fsnotify v1.7.0 // indirect
7979
github.com/gookit/color v1.5.4 // indirect
80-
github.com/gookit/goutil v0.6.15 // indirect
80+
github.com/gookit/goutil v0.6.16 // indirect
8181
github.com/gookit/gsr v0.1.0 // indirect
8282
github.com/hashicorp/hcl v1.0.0 // indirect
83-
github.com/imroc/req/v3 v3.43.4
83+
github.com/imroc/req/v3 v3.43.7
8484
github.com/magiconair/properties v1.8.7 // indirect
8585
github.com/mitchellh/mapstructure v1.5.0 // indirect
86-
github.com/mymmrac/telego v0.30.2
86+
github.com/mymmrac/telego v0.31.0
8787
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
88-
github.com/sagikazarmark/locafero v0.4.0 // indirect
88+
github.com/sagikazarmark/locafero v0.6.0 // indirect
8989
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
9090
github.com/sourcegraph/conc v0.3.0 // indirect
9191
github.com/spf13/afero v1.11.0 // indirect
@@ -95,9 +95,9 @@ require (
9595
github.com/valyala/bytebufferpool v1.0.0 // indirect
9696
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
9797
go.uber.org/multierr v1.11.0 // indirect
98-
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
98+
golang.org/x/exp v0.0.0-20240707233637-46b078467d37 // indirect
9999
golang.org/x/sync v0.7.0 // indirect
100-
golang.org/x/sys v0.20.0 // indirect
100+
golang.org/x/sys v0.22.0 // indirect
101101
golang.org/x/text v0.16.0 // indirect
102102
gopkg.in/ini.v1 v1.67.0 // indirect
103103
gopkg.in/yaml.v3 v3.0.1 // indirect

0 commit comments

Comments
 (0)