canopeas/discord/echo.go

63 lines
1.3 KiB
Go

package discord
import (
"fmt"
"strings"
"git.jojodev.com/Minecraft/canopeas/config"
"github.com/bwmarrin/discordgo"
)
func Echo(cfg *config.Config) {
for _, echo := range cfg.Echoes {
e := echo // Closure
commands = append(commands, &command{
name: e.Name,
aliases: e.Aliases,
child: true,
validate: func(cmd commandInit) bool {
return true
},
run: func(cmd commandInit) (string, error) {
return e.Message, nil
},
help: e.Help,
})
}
commands = append(commands, &command{
deleteInvocation: true,
name: "echoes",
validate: func(cmd commandInit) bool {
return true
},
run: func(cmd commandInit) (string, error) {
embed := &discordgo.MessageEmbed{
Title: "Echo Commands",
Fields: make([]*discordgo.MessageEmbedField, len(cfg.Echoes)),
}
for i, echo := range cfg.Echoes {
name := echo.Name
if len(echo.Aliases) > 0 {
name += fmt.Sprintf(" (%s)", strings.Join(echo.Aliases, ", "))
}
embed.Fields[i] = &discordgo.MessageEmbedField{
Name: name,
Value: echo.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 dynamic messages",
})
}