Milen/commands/commands.go

55 lines
1.3 KiB
Go

2020-05-11 05:30:07 +07:00
package commands
import (
"strings"
"github.com/bwmarrin/discordgo"
"gitea.teamortix.com/chanbakjsd/Milen/util"
)
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},
command{"recalclevel", "", handleRecalculateLevel, 0, false},
2020-05-30 12:47:10 +07:00
command{"level", "", handleLevel, 0, false},
}
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-30 12:47:10 +07:00
split := strings.Split(m.Content, " ")
prefix := strings.ToLower(split[0])
if prefix != "milen," && prefix != "milen" {
return
}
if len(split) == 1 {
util.SendFailEmbed(dg, m.ChannelID, ":(", "Did you just call me out for no reason? Please specify what you want me to do.")
2020-05-11 05:30:07 +07:00
return
}
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
}
}