diff --git a/discord/commands.go b/discord/commands.go new file mode 100644 index 0000000..128321a --- /dev/null +++ b/discord/commands.go @@ -0,0 +1,37 @@ +package main + +import ( + "strings" + + "github.com/bwmarrin/discordgo" +) + +/* The Command interface is a template for the implementation of a command of the discord bot. +The actual command will be executed in the Execute function. +All the actual Command objects will be (similarly to Handlers in the net/http package) put into a CommandMux */ +type Command interface { + Execute(s *discordgo.Session, m *discordgo.MessageCreate) +} + +/* The CommandMux struct is a type of mux for Discord commands. It's modelled after the net/http ServeMux */ +type CommandMux struct { + m map[string]muxEntry + prefix string +} + +func (c *CommandMux) Handler(m *discordgo.MessageCreate) (cmd Command, pattern string) { + if strings.HasPrefix(m.Content, c.prefix) { + + } +} + +func (c *CommandMux) Execute(s *discordgo.Session, m *discordgo.MessageCreate) { + +} + +/* The muxEntry struct contains the actual Command implementation as well as the pattern (discord command) +it will be matched against */ +type muxEntry struct { + h Command + pattern string +} diff --git a/discord/main.go b/discord/main.go index 8e04636..6d61691 100644 --- a/discord/main.go +++ b/discord/main.go @@ -25,6 +25,7 @@ type application struct { trigger string allBadWords map[string][]string limiter *limiter.Limiter + commandMux *CommandMux active bool stop bool