2020-04-11 14:16:09 +00:00
|
|
|
package features
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"github.com/bwmarrin/discord.go"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2020-05-04 22:03:11 +00:00
|
|
|
func (f *Features) handleUserColors(s *discordgo.Session, m *discordgo.MessageCreate) error {
|
2020-05-25 22:46:15 +00:00
|
|
|
if !f.Permissions.CheckCommandRestrictions(m) {
|
2020-04-11 14:16:09 +00:00
|
|
|
return errors.New("This command is not allowed in this channel.")
|
|
|
|
}
|
|
|
|
|
|
|
|
msgC := "You can choose from the following colors:\n\n"
|
|
|
|
for _, v := range f.Config.ColorRoles {
|
|
|
|
msgC += "<@&" + v.ID + ">\n"
|
|
|
|
}
|
2020-05-25 06:35:03 +00:00
|
|
|
msgC += "\n\nUse `" + f.Config.CommandKey + "color <color>` to set.\n"
|
|
|
|
msgC += "Example: `" + f.Config.CommandKey + "color red`.\n"
|
2020-04-11 14:16:09 +00:00
|
|
|
|
2020-04-27 18:31:26 +00:00
|
|
|
msg := f.CreateDefinedEmbed("User Colors", msgC, "", m.Author)
|
2020-04-11 14:16:09 +00:00
|
|
|
|
|
|
|
_, err := s.ChannelMessageSendEmbed(m.ChannelID, msg)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-05-04 22:03:11 +00:00
|
|
|
func (f *Features) handleUserColor(s *discordgo.Session, m *discordgo.MessageCreate) error {
|
2020-04-11 14:16:09 +00:00
|
|
|
var err error
|
|
|
|
|
2020-05-25 22:46:15 +00:00
|
|
|
if !f.Permissions.CheckCommandRestrictions(m) {
|
2020-04-11 14:16:09 +00:00
|
|
|
return errors.New("This command is not allowed in this channel.")
|
|
|
|
}
|
|
|
|
|
|
|
|
rUserID := m.Author.ID
|
|
|
|
|
|
|
|
userInput := strings.Split(m.Content, " ")
|
|
|
|
if len(userInput) < 2 {
|
2020-05-04 22:03:11 +00:00
|
|
|
err = f.handleUserColors(s, m)
|
2020-04-11 14:16:09 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
roleColorName := userInput[1]
|
|
|
|
roleColorName = strings.ToLower(roleColorName)
|
|
|
|
|
|
|
|
roleColorID := ""
|
|
|
|
for _, role := range f.Config.ColorRoles {
|
|
|
|
if role.Name == roleColorName {
|
|
|
|
roleColorID = role.ID
|
2020-09-18 11:32:19 +00:00
|
|
|
break
|
2020-04-11 14:16:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(roleColorID) == 0 {
|
2020-05-04 22:03:11 +00:00
|
|
|
err = f.handleUserColors(s, m)
|
2020-04-11 14:16:09 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, role := range f.Config.ColorRoles {
|
|
|
|
// Attempt to remove all color roles regardless of if they have them or not.
|
|
|
|
// Slow because of the REST requests...
|
|
|
|
_ = s.GuildMemberRoleRemove(m.GuildID, rUserID, role.ID)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = s.GuildMemberRoleAdd(m.GuildID, rUserID, roleColorID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
} else {
|
2020-04-27 18:31:26 +00:00
|
|
|
msg := f.CreateDefinedEmbed("User Color", "<@"+m.Author.ID+">: Your color has been set to <@&"+roleColorID+">!", "success", m.Author)
|
2020-04-11 14:16:09 +00:00
|
|
|
_, err = s.ChannelMessageSendEmbed(m.ChannelID, msg)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
err = s.ChannelMessageDelete(m.ChannelID, m.ID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|