forked from Clinet/clinet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd-xkcd.go
47 lines (43 loc) · 1.33 KB
/
cmd-xkcd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"strconv"
"github.com/bwmarrin/discordgo"
)
func commandXKCD(args []string, env *CommandEnvironment) *discordgo.MessageEmbed {
switch args[0] {
case "latest":
comic, err := botData.BotClients.XKCD.Latest()
if err != nil {
return NewErrorEmbed("XKCD Error", "There was an error fetching the latest XKCD comic.")
}
return NewEmbed().
SetTitle("xkcd - #" + strconv.Itoa(comic.Number)).
SetDescription(comic.Title).
SetImage(comic.ImageURL).
SetColor(0x96A8C8).MessageEmbed
case "random":
comic, err := botData.BotClients.XKCD.Random()
if err != nil {
return NewErrorEmbed("XKCD Error", "There was an error fetching a random XKCD comic.")
}
return NewEmbed().
SetTitle("xkcd - #" + strconv.Itoa(comic.Number)).
SetDescription(comic.Title).
SetImage(comic.ImageURL).
SetColor(0x96A8C8).MessageEmbed
default:
comicNumber, err := strconv.Atoi(args[0])
if err != nil {
return NewErrorEmbed("XKCD Error", "``"+args[0]+"`` is not a valid number.")
}
comic, err := botData.BotClients.XKCD.Get(comicNumber)
if err != nil {
return NewErrorEmbed("XKCD Error", "There was an error fetching XKCD comic #"+args[0]+".")
}
return NewEmbed().
SetTitle("xkcd - #" + args[0]).
SetDescription(comic.Title).
SetImage(comic.ImageURL).
SetColor(0x96A8C8).MessageEmbed
}
}