2020-05-11 05:30:07 +07:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/bwmarrin/discordgo"
|
|
|
|
|
|
|
|
"gitea.teamortix.com/chanbakjsd/Milen/util"
|
|
|
|
)
|
|
|
|
|
2020-05-12 10:18:19 +07:00
|
|
|
type command struct {
|
|
|
|
Name string
|
|
|
|
Usage string
|
|
|
|
Processor func(*discordgo.Session, *discordgo.MessageCreate, []string)
|
|
|
|
MinimumArgument int
|
|
|
|
ExactArgument bool
|
|
|
|
}
|
|
|
|
|
|
|
|
var commands = []command{
|
|
|
|
command{"autorole", "<message link> <emoji> <role to assign>", handleAutorole, 3, true},
|
|
|
|
}
|
|
|
|
|
2020-05-11 05:30:07 +07:00
|
|
|
func Event(dg *discordgo.Session, m *discordgo.MessageCreate) {
|
2020-05-12 10:35:02 +07:00
|
|
|
if m.Author.Bot {
|
|
|
|
return
|
|
|
|
}
|
2020-05-11 05:30:07 +07:00
|
|
|
if !strings.HasPrefix(m.Content, "milen ") {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
split := strings.Split(m.Content, " ")
|
2020-05-12 10:18:19 +07:00
|
|
|
for _, v := range commands {
|
|
|
|
if split[1] != v.Name {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if (v.ExactArgument && len(split) != v.MinimumArgument+2) || (!v.ExactArgument && len(split) < v.MinimumArgument+2) {
|
|
|
|
util.SendFailEmbed(dg, m.ChannelID, "Incorrect Usage", "Usage: `milen "+v.Name+" "+v.Usage+"`")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if len(split) == 2 {
|
|
|
|
v.Processor(dg, m, []string{})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
v.Processor(dg, m, split[2:])
|
|
|
|
return
|
2020-05-11 05:30:07 +07:00
|
|
|
}
|
|
|
|
}
|