package discord import ( "fmt" "strings" "git.canopymc.net/Etzelia/canopeas/config" "git.canopymc.net/Etzelia/canopeas/imgur" "github.com/bwmarrin/discordgo" ) func Album(cfg *config.Config) error { for _, a := range cfg.Albums { images, err := imgur.Get(cfg.ImgurClientID, a.AlbumID) if err != nil { return err } commands = append(commands, &command{ name: a.Name, aliases: a.Aliases, child: true, validate: func(cmd commandInit) bool { return true }, run: func(cmd commandInit) (string, error) { if !memeRateLimit.Try() { return "", nil } img := images[rand.Intn(len(images))-1] return img.Link, nil }, help: a.Help, }) } commands = append(commands, &command{ deleteInvocation: true, name: "albums", validate: func(cmd commandInit) bool { return true }, run: func(cmd commandInit) (string, error) { embed := &discordgo.MessageEmbed{ Title: "Album Commands", Fields: make([]*discordgo.MessageEmbedField, len(cfg.Albums)), } for i, a := range cfg.Albums { name := a.Name if len(a.Aliases) > 0 { name += fmt.Sprintf(" (%s)", strings.Join(a.Aliases, ", ")) } embed.Fields[i] = &discordgo.MessageEmbedField{ Name: name, Value: a.Help, Inline: true, } } channel, err := cmd.session.UserChannelCreate(cmd.message.Author.ID) if err != nil { return "", err } sendEmbed(cmd.session, channel.ID, embed) return "", nil }, help: "Get all imgur albums", }) return nil }