Skip to content

Commit dd8db8b

Browse files
committed
Added selecting random entry
1 parent 9c4c4d7 commit dd8db8b

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

anilist_app.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"fmt"
55
"math"
6+
"math/rand"
67
"net/url"
78
"sort"
89
"strconv"
@@ -92,6 +93,12 @@ func AniListApp(app *cli.App) *cli.App {
9293
Usage: "Select an entry",
9394
UsageText: "mal sel [entry title]",
9495
Action: alSelectEntry,
96+
Flags: []cli.Flag{
97+
cli.BoolFlag{
98+
Name: "rand",
99+
Usage: "select random entry from \"planning\" list",
100+
},
101+
},
95102
},
96103
cli.Command{
97104
Name: "selected",
@@ -478,6 +485,10 @@ func alDeleteEntry(ctx *cli.Context) error {
478485
}
479486

480487
func alSelectEntry(ctx *cli.Context) error {
488+
if ctx.Bool("rand") {
489+
return alSelectRandomEntry(ctx)
490+
}
491+
481492
al, err := loadAniList(ctx)
482493
if err != nil {
483494
return err
@@ -508,6 +519,19 @@ func alSelectEntry(ctx *cli.Context) error {
508519
return alFuzzySelectEntry(ctx)
509520
}
510521

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+
511535
func alSaveSelection(cfg *Config, entry *anilist.MediaListEntry) {
512536
cfg.ALSelectedID = entry.Id
513537
cfg.Save()

0 commit comments

Comments
 (0)