This repository has been archived on 2022-10-02. You can view files and clone it, but cannot push or open issues or pull requests.
dcbot-old/discord/command.go

41 lines
748 B
Go
Raw Normal View History

2020-06-27 16:48:33 +00:00
package discord
2020-07-19 10:16:02 +00:00
import (
"github.com/bwmarrin/discordgo"
2020-07-19 10:16:02 +00:00
"github.com/nicksnyder/go-i18n/v2/i18n"
"github.com/tribalwarshelp/dcbot/model"
2020-07-19 10:16:02 +00:00
)
type command string
2020-06-27 16:48:33 +00:00
func (cmd command) String() string {
2020-06-27 16:48:33 +00:00
return string(cmd)
}
func (cmd command) WithPrefix(prefix string) string {
2021-07-18 07:14:26 +00:00
return prefix + cmd.String()
2020-06-27 16:48:33 +00:00
}
2020-07-19 10:16:02 +00:00
type commandCtx struct {
server *model.Server
2020-07-19 10:16:02 +00:00
localizer *i18n.Localizer
}
2021-07-18 07:14:26 +00:00
type commandHandler interface {
cmd() command
2021-07-18 07:14:26 +00:00
requireAdmPermissions() bool
execute(ctx *commandCtx, m *discordgo.MessageCreate, args ...string)
}
2021-07-18 07:14:26 +00:00
type commandHandlers []commandHandler
2021-07-18 07:14:26 +00:00
func (hs commandHandlers) find(prefix, cmd string) commandHandler {
for _, h := range hs {
2021-07-18 07:14:26 +00:00
if h.cmd().WithPrefix(prefix) == cmd {
return h
}
}
return nil
}