diff --git a/commands.go b/commands.go index 48afb5a..b45585a 100644 --- a/commands.go +++ b/commands.go @@ -1,6 +1,7 @@ package main import ( + "context" "encoding/json" "github.com/bwmarrin/discordgo" "github.com/bwmarrin/disgord/x/mux" @@ -103,12 +104,14 @@ func getXKCD(s *discordgo.Session, m *discordgo.Message, ctx *mux.Context) { } matchedNum, _ := regexp.MatchString(`[0-9]+`, arg) if arg == "latest" { - comic, err = xkclient.Latest() + comic, err = xkclient.Latest(context.Background()) } else if matchedNum { comicNum, _ := strconv.Atoi(arg) - comic, err = xkclient.Get(comicNum) + comic, err = xkclient.Get(context.Background(), comicNum) } else { - comic, err = xkclient.Random() + latestcomic, _ := xkclient.Latest(context.Background()) + randcomic := rand.Intn(latestcomic.Number) + comic, err = xkclient.Get(context.Background(), randcomic) } if err != nil { resp = err.Error()