@@ -204,7 +204,7 @@ func fetchArtwork(ctx context.Context, bot *telego.Bot, message telego.Message)
204
204
telegram .ReplyMessage (bot , message , "开始拉取作品了" )
205
205
}
206
206
207
- func postArtwork (ctx context.Context , bot * telego.Bot , query telego.CallbackQuery ) {
207
+ func postArtworkCb (ctx context.Context , bot * telego.Bot , query telego.CallbackQuery ) {
208
208
if ! service .CheckAdminPermission (ctx , query .From .ID , types .PermissionPostArtwork ) &&
209
209
! service .CheckAdminPermission (ctx , query .Message .GetChat ().ID , types .PermissionPostArtwork ) {
210
210
bot .AnswerCallbackQuery (& telego.AnswerCallbackQueryParams {
@@ -316,6 +316,71 @@ func postArtwork(ctx context.Context, bot *telego.Bot, query telego.CallbackQuer
316
316
})
317
317
}
318
318
319
+ func postArtworkCmd (ctx context.Context , bot * telego.Bot , message telego.Message ) {
320
+ if ! CheckPermissionInGroup (ctx , message , types .PermissionPostArtwork ) {
321
+ telegram .ReplyMessage (bot , message , "你没有发布作品的权限" )
322
+ return
323
+ }
324
+ _ , _ , args := telegoutil .ParseCommand (message .Text )
325
+ if len (args ) == 0 && message .ReplyToMessage == nil {
326
+ telegram .ReplyMessage (bot , message , "请提供作品链接, 或回复一条消息" )
327
+ return
328
+ }
329
+ var sourceURL string
330
+ if message .ReplyToMessage != nil {
331
+ sourceURL = FindSourceURLForMessage (message .ReplyToMessage )
332
+ if sourceURL == "" {
333
+ if len (args ) == 0 {
334
+ telegram .ReplyMessage (bot , message , "不支持的链接" )
335
+ return
336
+ }
337
+ sourceURL = sources .FindSourceURL (args [0 ])
338
+ }
339
+ }
340
+ if len (args ) > 0 {
341
+ sourceURL = sources .FindSourceURL (args [0 ])
342
+ }
343
+ if sourceURL == "" {
344
+ telegram .ReplyMessage (bot , message , "不支持的链接" )
345
+ return
346
+ }
347
+ artwork , _ := service .GetArtworkByURL (ctx , sourceURL )
348
+ if artwork != nil {
349
+ telegram .ReplyMessage (bot , message , "作品已存在" )
350
+ return
351
+ }
352
+ msg , err := telegram .ReplyMessage (bot , message , "正在发布..." )
353
+ if err == nil && msg != nil {
354
+ defer bot .DeleteMessage (telegoutil .Delete (msg .Chat .ChatID (), msg .MessageID ))
355
+ }
356
+ cachedArtwork , err := service .GetCachedArtworkByURL (ctx , sourceURL )
357
+ if err != nil {
358
+ artwork , err = sources .GetArtworkInfo (sourceURL )
359
+ if err != nil {
360
+ Logger .Errorf ("获取作品信息失败: %s" , err )
361
+ telegram .ReplyMessage (bot , message , "获取作品信息失败: " + err .Error ())
362
+ return
363
+ }
364
+ } else {
365
+ artwork = cachedArtwork .Artwork
366
+ }
367
+ if err := fetcher .PostAndCreateArtwork (ctx , artwork , bot , storage .GetStorage (), message .Chat .ID ); err != nil {
368
+ telegram .ReplyMessage (bot , message , "发布失败: " + err .Error ())
369
+ return
370
+ }
371
+ artwork , err = service .GetArtworkByURL (ctx , sourceURL )
372
+ if err != nil {
373
+ telegram .ReplyMessage (bot , message , "获取发布后的作品信息失败: " + err .Error ())
374
+ return
375
+ }
376
+ bot .SendMessage (telegoutil .Message (telegoutil .ID (message .Chat .ID ), "发布成功: " + artwork .Title ).
377
+ WithReplyParameters (& telego.ReplyParameters {
378
+ ChatID : message .Chat .ChatID (),
379
+ MessageID : message .MessageID ,
380
+ },
381
+ ).WithReplyMarkup (telegram .GetPostedPictureReplyMarkup (artwork .Pictures [0 ])))
382
+ }
383
+
319
384
func processPictures (ctx context.Context , bot * telego.Bot , message telego.Message ) {
320
385
userAdmin , err := service .GetAdminByUserID (ctx , message .From .ID )
321
386
if err != nil {
0 commit comments