Skip to content

Commit 09d83a9

Browse files
committed
feat: support expandalbe quote
其实没支持, 我也不知道为什么它发出去之后就是折叠不了的
1 parent 5e2c902 commit 09d83a9

File tree

10 files changed

+50
-30
lines changed

10 files changed

+50
-30
lines changed

bot/bot.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func RunPolling() {
1515
}
1616
Logger.Info("Start polling")
1717
updates, err := telegram.Bot.UpdatesViaLongPolling(&telego.GetUpdatesParams{
18-
Offset: -1,
18+
Offset: -100,
1919
AllowedUpdates: []string{
2020
telego.MessageUpdates,
2121
telego.ChannelPostUpdates,

bot/handlers_admin.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,8 @@ func setArtworkTags(ctx context.Context, bot *telego.Bot, message telego.Message
411411
bot.EditMessageCaption(&telego.EditMessageCaptionParams{
412412
ChatID: telegram.ChannelChatID,
413413
MessageID: artwork.Pictures[0].TelegramInfo.MessageID,
414-
Caption: telegram.GetArtworkMarkdownCaption(artwork),
415-
ParseMode: telego.ModeMarkdownV2,
414+
Caption: telegram.GetArtworkHTMLCaption(artwork),
415+
ParseMode: telego.ModeHTML,
416416
})
417417
telegram.ReplyMessage(bot, message, "更新作品标签成功")
418418
}

bot/handlers_common.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -297,15 +297,14 @@ func getArtworkInfo(ctx context.Context, bot *telego.Bot, message telego.Message
297297

298298
photo := telegoutil.Photo(message.Chat.ChatID(), inputFile).
299299
WithReplyParameters(&telego.ReplyParameters{MessageID: message.MessageID}).
300-
WithParseMode(telego.ModeMarkdownV2)
300+
WithParseMode(telego.ModeHTML)
301301

302302
deletedModel, _ := service.GetDeletedByURL(ctx, sourceURL)
303-
artworkInfoCaption := telegram.GetArtworkMarkdownCaption(artwork)
303+
artworkInfoCaption := telegram.GetArtworkHTMLCaption(artwork)
304304
if deletedModel != nil && hasPermission {
305-
photo.WithCaption(artworkInfoCaption + common.EscapeMarkdown(fmt.Sprintf("\n\n这是一个在 %s 删除的作品\n\n"+
306-
"如果发布则会取消删除", deletedModel.DeletedAt.Time().Format("2006-01-02 15:04:05"))))
305+
photo.WithCaption(artworkInfoCaption + fmt.Sprintf("\n\n这是一个在 %s 删除的作品\n如果发布则会取消删除", deletedModel.DeletedAt.Time().Format("2006-01-02 15:04:05")))
307306
} else {
308-
photo.WithCaption(telegram.GetArtworkMarkdownCaption(artwork))
307+
photo.WithCaption(artworkInfoCaption)
309308
}
310309
if isAlreadyPosted {
311310
photo.WithReplyMarkup(telegram.GetPostedPictureReplyMarkup(artwork.Pictures[0]))

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.7.5"
10+
Version string = "0.7.6"
1111
)
1212

1313
var VersionCmd = &cobra.Command{

common/strings.go

+8
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ func EscapeMarkdown(text string) string {
2929
return re.ReplaceAllString(text, "\\$1")
3030
}
3131

32+
func EscapeHTML(text string) string {
33+
return strings.NewReplacer(
34+
"<", "&lt;",
35+
">", "&gt;",
36+
"&", "&amp;",
37+
).Replace(text)
38+
}
39+
3240
// 解析字符串为二维数组, 如果以字符串以引号包裹, 则无视分隔符
3341
//
3442
// ParseStringTo2DArray("1,2,3;4,5,6", ",", ";") => [][]string{{"1", "2", "3"}, {"4", "5", "6"}}

go.mod

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module ManyACG
22

3-
go 1.22.2
3+
go 1.22.3
44

55
require (
66
github.com/blang/semver v3.5.1+incompatible
@@ -18,12 +18,12 @@ require (
1818

1919
require (
2020
github.com/andybalholm/brotli v1.1.0 // indirect
21-
github.com/bytedance/sonic v1.11.6 // indirect
21+
github.com/bytedance/sonic v1.11.8 // indirect
2222
github.com/bytedance/sonic/loader v0.1.1 // indirect
2323
github.com/cloudflare/circl v1.3.8 // 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.0 // indirect
26+
github.com/fasthttp/router v1.5.1 // indirect
2727
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
2828
github.com/gin-contrib/sse v0.1.0 // indirect
2929
github.com/go-playground/locales v0.14.1 // indirect
@@ -58,7 +58,7 @@ require (
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.52.0 // indirect
61+
github.com/valyala/fasthttp v1.54.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
@@ -83,7 +83,7 @@ require (
8383
github.com/imroc/req/v3 v3.43.4
8484
github.com/magiconair/properties v1.8.7 // indirect
8585
github.com/mitchellh/mapstructure v1.5.0 // indirect
86-
github.com/mymmrac/telego v0.29.2
86+
github.com/mymmrac/telego v0.30.2
8787
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
8888
github.com/sagikazarmark/locafero v0.4.0 // indirect
8989
github.com/sagikazarmark/slog-shim v0.1.0 // indirect

go.sum

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1
22
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
33
github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ=
44
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
5-
github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0=
6-
github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4=
5+
github.com/bytedance/sonic v1.11.8 h1:Zw/j1KfiS+OYTi9lyB3bb0CFxPJVkM17k1wyDG32LRA=
6+
github.com/bytedance/sonic v1.11.8/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4=
77
github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM=
88
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
99
github.com/cloudflare/circl v1.3.8 h1:j+V8jJt09PoeMFIu2uh5JUyEaIHTXVOHslFoLNAKqwI=
@@ -19,8 +19,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
1919
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2020
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
2121
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
22-
github.com/fasthttp/router v1.5.0 h1:3Qbbo27HAPzwbpRzgiV5V9+2faPkPt3eNuRaDV6LYDA=
23-
github.com/fasthttp/router v1.5.0/go.mod h1:FddcKNXFZg1imHcy+uKB0oo/o6yE9zD3wNguqlhWDak=
22+
github.com/fasthttp/router v1.5.1 h1:uViy8UYYhm5npJSKEZ4b/ozM//NGzVCfJbh6VJ0VKr8=
23+
github.com/fasthttp/router v1.5.1/go.mod h1:WrmsLo3mrerZP2VEXRV1E8nL8ymJFYCDTr4HmnB8+Zs=
2424
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
2525
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
2626
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
@@ -117,8 +117,8 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
117117
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
118118
github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE=
119119
github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
120-
github.com/mymmrac/telego v0.29.2 h1:5+fQ/b8d8Ld6ihCJ0OLe1CwUdT3t1sIUl3RaSaSvRJs=
121-
github.com/mymmrac/telego v0.29.2/go.mod h1:BsKr+GF9BHqaVaLBwsZeDnfuJcJx2olWuDEtKm4zHMc=
120+
github.com/mymmrac/telego v0.30.2 h1:CqGlqX0hkgz9qMwdA3q+aZtSonqMOKQQrFLn/oUOTaw=
121+
github.com/mymmrac/telego v0.30.2/go.mod h1:U6cWJBgRCzGt+s0q77x/Dh2+i+u56VTAAYKlMenhuFc=
122122
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
123123
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
124124
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
@@ -188,8 +188,8 @@ github.com/ulikunitz/xz v0.5.12 h1:37Nm15o69RwBkXM0J6A5OlE67RZTfzUxTj8fB3dfcsc=
188188
github.com/ulikunitz/xz v0.5.12/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
189189
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
190190
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
191-
github.com/valyala/fasthttp v1.52.0 h1:wqBQpxH71XW0e2g+Og4dzQM8pk34aFYlA1Ga8db7gU0=
192-
github.com/valyala/fasthttp v1.52.0/go.mod h1:hf5C4QnVMkNXMspnsUlfM3WitlgYflyhHYoKol/szxQ=
191+
github.com/valyala/fasthttp v1.54.0 h1:cCL+ZZR3z3HPLMVfEYVUMtJqVaui0+gu7Lx63unHwS0=
192+
github.com/valyala/fasthttp v1.54.0/go.mod h1:6dt4/8olwq9QARP/TDuPmWyWcl4byhpvTJ4AAtcz+QM=
193193
github.com/valyala/fastjson v1.6.4 h1:uAUNq9Z6ymTgGhcm0UynUAB6tlbakBrz6CQFax3BXVQ=
194194
github.com/valyala/fastjson v1.6.4/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY=
195195
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=

sources/pixiv/types.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func (resp *PixivAjaxResp) ToArtwork() (*types.Artwork, error) {
137137
}
138138
return &types.Artwork{
139139
Title: resp.Body.IlustTitle,
140-
Description: htmlRe.ReplaceAllString(resp.Body.Description, ""),
140+
Description: htmlRe.ReplaceAllString(strings.ReplaceAll(resp.Body.Description, "<br />", "\n"), ""),
141141
R18: r18,
142142
SourceType: types.SourceTypePixiv,
143143
SourceURL: "https://www.pixiv.net/artworks/" + resp.Body.IllustId,

telegram/artwork.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func PostArtwork(bot *telego.Bot, artwork *types.Artwork, storage storage.Storag
3939
}
4040
photo := telegoutil.MediaPhoto(telegoutil.File(telegoutil.NameReader(bytes.NewReader(fileBytes), picture.StorageInfo.Path)))
4141
if i == 0 {
42-
photo = photo.WithCaption(GetArtworkMarkdownCaption(artwork)).WithParseMode(telego.ModeMarkdownV2)
42+
photo = photo.WithCaption(GetArtworkHTMLCaption(artwork)).WithParseMode(telego.ModeHTML)
4343
}
4444
if artwork.R18 {
4545
photo = photo.WithHasSpoiler()

telegram/utils.go

+19-6
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,8 @@ func GetArtworkMarkdownCaption(artwork *types.Artwork) string {
105105
caption := fmt.Sprintf("[*%s*](%s)", common.EscapeMarkdown(artwork.Title), artwork.SourceURL)
106106
caption += "\n" + "*Author:* " + common.EscapeMarkdown(artwork.Artist.Name)
107107
if artwork.Description != "" {
108-
desc := strings.ReplaceAll(artwork.Description, "\n", " ")
109-
if len(desc) > 500 {
110-
caption += "\n\n>" + common.EscapeMarkdown(desc) + "\\.\\.\\."
111-
} else {
112-
caption += "\n\n>" + common.EscapeMarkdown(desc)
113-
}
108+
desc := strings.ReplaceAll(artwork.Description, "\n", "\n>")
109+
caption += "\n\n>" + common.EscapeMarkdown(desc)
114110
}
115111
tags := ""
116112
for _, tag := range artwork.Tags {
@@ -123,6 +119,23 @@ func GetArtworkMarkdownCaption(artwork *types.Artwork) string {
123119
return caption
124120
}
125121

122+
func GetArtworkHTMLCaption(artwork *types.Artwork) string {
123+
caption := fmt.Sprintf("<a href=\"%s\"><b>%s</b></a>", artwork.SourceURL, common.EscapeHTML(artwork.Title))
124+
caption += "\n" + "<b>Author:</b> " + common.EscapeHTML(artwork.Artist.Name)
125+
if artwork.Description != "" {
126+
caption += fmt.Sprintf("\n\n<blockquote expandable=true>%s</blockquote>", common.EscapeHTML(artwork.Description))
127+
}
128+
tags := ""
129+
for _, tag := range artwork.Tags {
130+
tag = ReplaceChars(tag, []string{":", ":", "-", "(", ")", "「", "」", "*"}, "_")
131+
tag = ReplaceChars(tag, []string{"?"}, "")
132+
tag = ReplaceChars(tag, []string{"/"}, " "+"#")
133+
tags += "#" + strings.Join(strings.Split(common.EscapeHTML(tag), " "), "") + " "
134+
}
135+
caption += "\n\n" + tags
136+
return caption
137+
}
138+
126139
func ReplyMessage(bot *telego.Bot, message telego.Message, text string) (*telego.Message, error) {
127140
return bot.SendMessage(telegoutil.Message(message.Chat.ChatID(), text).
128141
WithReplyParameters(&telego.ReplyParameters{

0 commit comments

Comments
 (0)