Fix XKCD command after new go-xkcd broke it.

pull/20/head
pocketjawa 2020-04-26 02:56:15 -04:00
parent c5b91113a3
commit c2142bb741
1 changed files with 6 additions and 3 deletions

View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"context"
"encoding/json" "encoding/json"
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
"github.com/bwmarrin/disgord/x/mux" "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) matchedNum, _ := regexp.MatchString(`[0-9]+`, arg)
if arg == "latest" { if arg == "latest" {
comic, err = xkclient.Latest() comic, err = xkclient.Latest(context.Background())
} else if matchedNum { } else if matchedNum {
comicNum, _ := strconv.Atoi(arg) comicNum, _ := strconv.Atoi(arg)
comic, err = xkclient.Get(comicNum) comic, err = xkclient.Get(context.Background(), comicNum)
} else { } 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 { if err != nil {
resp = err.Error() resp = err.Error()