@@ -477,19 +477,23 @@ func batchPostArtwork(ctx context.Context, bot *telego.Bot, message telego.Messa
477
477
callbackMessage = nil
478
478
}
479
479
480
- failed := 0
481
480
reader := bufio .NewReader (bytes .NewReader (file ))
482
- for i := startIndex ; i < count + startIndex ; i ++ {
483
- if callbackMessage != nil {
484
- if i - startIndex == 0 || (i - startIndex )% 10 == 0 {
485
- bot .EditMessageText (& telego.EditMessageTextParams {
486
- ChatID : message .Chat .ChatID (),
487
- MessageID : callbackMessage .MessageID ,
488
- Text : fmt .Sprintf ("总数: %d\n 起始索引: %d\n 间隔时间: %d秒\n 已发布: %d\n 失败: %d" , count , startIndex , sleepTime , i , failed ),
489
- })
490
- }
481
+ sourceURLs := make ([]string , 0 )
482
+
483
+ for i := 0 ; i < startIndex ; i ++ {
484
+ _ , err := reader .ReadString ('\n' )
485
+ if err == io .EOF {
486
+ telegram .ReplyMessage (bot , message , "起始索引超出文件行数" )
487
+ return
488
+ }
489
+ if err != nil {
490
+ telegram .ReplyMessage (bot , message , "读取文件失败: " + err .Error ())
491
+ return
491
492
}
492
- line , _ , err := reader .ReadLine ()
493
+ }
494
+
495
+ for i := startIndex ; i < count + startIndex ; i ++ {
496
+ text , err := reader .ReadString ('\n' )
493
497
if err == io .EOF {
494
498
telegram .ReplyMessage (bot , message , "文件已读取完毕" )
495
499
break
@@ -498,12 +502,25 @@ func batchPostArtwork(ctx context.Context, bot *telego.Bot, message telego.Messa
498
502
telegram .ReplyMessage (bot , message , "读取文件失败: " + err .Error ())
499
503
return
500
504
}
501
- sourceURL := sources .FindSourceURL (string ( line ) )
505
+ sourceURL := sources .FindSourceURL (text )
502
506
if sourceURL == "" {
503
- Logger .Warnf ("不支持的链接: %s" , string (line ))
504
- failed ++
507
+ Logger .Warnf ("不支持的链接: %s" , text )
505
508
continue
506
509
}
510
+ sourceURLs = append (sourceURLs , sourceURL )
511
+ }
512
+
513
+ failed := 0
514
+ for i , sourceURL := range sourceURLs {
515
+ if callbackMessage != nil {
516
+ if i == 0 || i % 10 == 0 {
517
+ bot .EditMessageText (& telego.EditMessageTextParams {
518
+ ChatID : message .Chat .ChatID (),
519
+ MessageID : callbackMessage .MessageID ,
520
+ Text : fmt .Sprintf ("总数: %d\n 起始索引: %d\n 间隔时间: %d秒\n 已发布: %d\n 失败: %d" , count , startIndex , sleepTime , i , failed ),
521
+ })
522
+ }
523
+ }
507
524
Logger .Infof ("posting artwork: %s" , sourceURL )
508
525
509
526
artwork , _ := service .GetArtworkByURL (ctx , sourceURL )
0 commit comments