canopeas/discord/links.go

50 lines
1.2 KiB
Go
Raw Normal View History

package discord
import (
"fmt"
"strings"
"go.etztech.xyz/sedbot/config"
)
func Links(cfg *config.Config) {
links := make([]string, 0)
for _, link := range cfg.Links {
commands[link.Name] = command{
validate: func(cmd commandInit) bool {
return true
},
run: func(cmd commandInit) error {
sendMessage(cmd.session, cmd.message.ChannelID, fmt.Sprintf("<%s>", link.URL))
return nil
},
help: fmt.Sprintf("Returns the link for %s", link.Name),
}
links = append(links, fmt.Sprintf("%s -> %s", link.Name, link.URL))
for _, alias := range link.Aliases {
commands[alias] = command{
validate: func(cmd commandInit) bool {
return true
},
run: func(cmd commandInit) error {
sendMessage(cmd.session, cmd.message.ChannelID, fmt.Sprintf("<%s>", link.URL))
return nil
},
help: fmt.Sprintf("Returns the link for %s", alias),
}
links = append(links, fmt.Sprintf("%s -> %s", alias, link.URL))
}
}
commands["links"] = command{
validate: func(cmd commandInit) bool {
return true
},
run: func(cmd commandInit) error {
sendMessage(cmd.session, cmd.message.ChannelID, strings.Join(links, "\n"))
return nil
},
help: "Get all dynamic links",
}
}