2020-05-11 05:30:07 +07:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/bwmarrin/discordgo"
|
|
|
|
|
|
|
|
"gitea.teamortix.com/chanbakjsd/Milen/db"
|
2020-05-11 06:43:55 +07:00
|
|
|
"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 {
|
2020-05-11 06:43:55 +07:00
|
|
|
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 == "" {
|
2020-05-11 06:43:55 +07:00
|
|
|
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
|
|
|
|
}
|
2020-05-11 06:43:55 +07:00
|
|
|
util.SendCheckError(dg, m.ChannelID, humanify.Eng.Autorole.Success)
|
2020-05-11 05:30:07 +07:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|