File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package main
3
3
import (
4
4
"fmt"
5
5
"math"
6
+ "math/rand"
6
7
"net/url"
7
8
"sort"
8
9
"strconv"
@@ -92,6 +93,12 @@ func AniListApp(app *cli.App) *cli.App {
92
93
Usage : "Select an entry" ,
93
94
UsageText : "mal sel [entry title]" ,
94
95
Action : alSelectEntry ,
96
+ Flags : []cli.Flag {
97
+ cli.BoolFlag {
98
+ Name : "rand" ,
99
+ Usage : "select random entry from \" planning\" list" ,
100
+ },
101
+ },
95
102
},
96
103
cli.Command {
97
104
Name : "selected" ,
@@ -478,6 +485,10 @@ func alDeleteEntry(ctx *cli.Context) error {
478
485
}
479
486
480
487
func alSelectEntry (ctx * cli.Context ) error {
488
+ if ctx .Bool ("rand" ) {
489
+ return alSelectRandomEntry (ctx )
490
+ }
491
+
481
492
al , err := loadAniList (ctx )
482
493
if err != nil {
483
494
return err
@@ -508,6 +519,19 @@ func alSelectEntry(ctx *cli.Context) error {
508
519
return alFuzzySelectEntry (ctx )
509
520
}
510
521
522
+ func alSelectRandomEntry (ctx * cli.Context ) error {
523
+ al , err := loadAniList (ctx )
524
+ if err != nil {
525
+ return err
526
+ }
527
+
528
+ planToWatchList := alGetList (al , anilist .Planning )
529
+ idx := rand .New (rand .NewSource (time .Now ().UnixNano ())).Intn (len (planToWatchList ))
530
+ alSaveSelection (LoadConfig (), & planToWatchList [idx ])
531
+
532
+ return nil
533
+ }
534
+
511
535
func alSaveSelection (cfg * Config , entry * anilist.MediaListEntry ) {
512
536
cfg .ALSelectedID = entry .Id
513
537
cfg .Save ()
You can’t perform that action at this time.
0 commit comments