@@ -17,6 +17,7 @@ import (
17
17
18
18
"github.com/mymmrac/telego"
19
19
"github.com/mymmrac/telego/telegoutil"
20
+ "go.mongodb.org/mongo-driver/bson/primitive"
20
21
"go.mongodb.org/mongo-driver/mongo"
21
22
)
22
23
@@ -213,7 +214,12 @@ func afterCreate(ctx context.Context, artwork *types.Artwork, bot *telego.Bot, f
213
214
Logger .Errorf ("error when getting artwork by URL: %s" , err )
214
215
if sendNotify {
215
216
bot .SendMessage (telegoutil .Messagef (telegoutil .ID (fromID ),
216
- "刚刚发布的作品 [%s](%s) 后续处理失败\\ : \n 无法获取作品信息\\ : %s" , artworkTitleMarkdown , GetArtworkPostMessageURL (artwork .Pictures [0 ].TelegramInfo .MessageID , ChannelChatID ), err ).
217
+ "刚刚发布的作品 [%s](%s) 后续处理失败\\ : \n 无法获取作品信息\\ : %s" , artworkTitleMarkdown , func () string {
218
+ if artwork .Pictures [0 ].TelegramInfo .MessageID != 0 {
219
+ return GetArtworkPostMessageURL (artwork .Pictures [0 ].TelegramInfo .MessageID , ChannelChatID )
220
+ }
221
+ return artwork .SourceURL
222
+ }(), err ).
217
223
WithParseMode (telego .ModeMarkdownV2 ))
218
224
}
219
225
return
@@ -252,20 +258,36 @@ func afterCreate(ctx context.Context, artwork *types.Artwork, bot *telego.Bot, f
252
258
253
259
text := fmt .Sprintf ("*刚刚发布的作品 [%s](%s) 中第 %d 张图片搜索到有%d个相似图片*\n " ,
254
260
artworkTitleMarkdown ,
255
- common .EscapeMarkdown (GetArtworkPostMessageURL (picture .TelegramInfo .MessageID , ChannelChatID )),
261
+ common .EscapeMarkdown (func () string {
262
+ if picture .TelegramInfo .MessageID != 0 {
263
+ return GetArtworkPostMessageURL (picture .TelegramInfo .MessageID , ChannelChatID )
264
+ }
265
+ return artwork .SourceURL
266
+ }()),
256
267
picture .Index + 1 ,
257
268
len (similarPictures ))
258
269
text += common .EscapeMarkdown (fmt .Sprintf ("该图像模糊度: %.2f\n 搜索到的相似图片列表:\n \n " , picture .BlurScore ))
259
270
for _ , similarPicture := range similarPictures {
260
- artworkOfSimilarPicture , err := service . GetArtworkByMessageID ( ctx , similarPicture .TelegramInfo . MessageID )
271
+ pictureObjectID , err := primitive . ObjectIDFromHex ( similarPicture .ID )
261
272
if err != nil {
262
- text += common .EscapeMarkdown (fmt .Sprintf ("%s 模糊度: %.2f\n \n " , GetArtworkPostMessageURL (picture .TelegramInfo .MessageID , ChannelChatID ), similarPicture .BlurScore ))
273
+ Logger .Errorf ("invalid ObjectID: %s" , similarPicture .ID )
274
+ continue
275
+ }
276
+
277
+ artworkOfSimilarPicture , err := service .GetArtworkByID (ctx , pictureObjectID )
278
+ if err != nil {
279
+ Logger .Warnf ("error when getting artwork by ID: %s" , err )
263
280
continue
264
281
}
265
282
text += fmt .Sprintf ("[%s\\ _%d](%s) " ,
266
283
common .EscapeMarkdown (artworkOfSimilarPicture .Title ),
267
284
similarPicture .Index + 1 ,
268
- common .EscapeMarkdown (GetArtworkPostMessageURL (similarPicture .TelegramInfo .MessageID , ChannelChatID )))
285
+ common .EscapeMarkdown (func () string {
286
+ if similarPicture .TelegramInfo .MessageID != 0 {
287
+ return GetArtworkPostMessageURL (similarPicture .TelegramInfo .MessageID , ChannelChatID )
288
+ }
289
+ return artworkOfSimilarPicture .SourceURL
290
+ }()))
269
291
text += common .EscapeMarkdown (fmt .Sprintf ("模糊度: %.2f\n \n " , similarPicture .BlurScore ))
270
292
}
271
293
text += "_模糊度使用原图文件计算得出, 越小图像质量越好_"
0 commit comments