Milen/commands/commands.go

41 lines
1009 B
Go

2020-05-11 05:30:07 +07:00
package commands
import (
"strings"
"github.com/bwmarrin/discordgo"
"gitea.teamortix.com/chanbakjsd/Milen/db"
"gitea.teamortix.com/chanbakjsd/Milen/humanify"
2020-05-11 05:30:07 +07:00
"gitea.teamortix.com/chanbakjsd/Milen/util"
)
func Event(dg *discordgo.Session, m *discordgo.MessageCreate) {
if !strings.HasPrefix(m.Content, "milen ") {
return
}
split := strings.Split(m.Content, " ")
switch split[1] {
case "autorole":
util.RequireAdmin(dg, m.Author.ID, m.ChannelID, func() {
if len(split) < 6 {
util.SendCheckError(dg, m.ChannelID, humanify.Eng.Usage.Autorole)
2020-05-11 05:30:07 +07:00
return
}
role := util.ParseRole(split[2])
if role == "" {
util.SendCheckError(dg, m.ChannelID, humanify.Eng.Usage.Autorole)
2020-05-11 05:30:07 +07:00
return
}
emoji := util.ParseEmoji(split[5])
db.CreateReactRole(split[4], emoji, role)
err := dg.MessageReactionAdd(split[3], split[4], emoji)
if err != nil {
util.ReportError(dg, err)
return
}
util.SendCheckError(dg, m.ChannelID, humanify.Eng.Autorole.Success)
2020-05-11 05:30:07 +07:00
})
}
}