add restriction to age roles

This commit is contained in:
kageru 2019-06-08 05:30:49 +02:00
parent a99496377e
commit 943e9fcaba
Signed by: kageru
GPG Key ID: 8282A2BEA4ADA3D2

View File

@ -237,12 +237,26 @@ func echoMessage(s *discordgo.Session, m *discordgo.MessageCreate) {
func giveAgeRole(s *discordgo.Session, m *discordgo.MessageCreate) {
Member, _ := s.GuildMember(config.ServerID, m.Author.ID)
dm, _ := s.UserChannelCreate(Member.User.ID)
required := mapset.NewSetWith("416184227672096780", "416184208470310922", "416184150404628480", "416184132473847810", "440996904948465664")
for command, role := range config.RoleCommands {
if m.Content == command {
// Found the command that was triggered
// This is a restriction imposed by my own wrapper,
// but working around it is not actually necessary for performance and makes the code uglier in other places.
for _, newRole := range config.RoleCommands {
// check if the user has a twitch sub or any of the patreon roles
isAllowed := false
for _, curRole := range Member.Roles {
if required.Contains(curRole) {
isAllowed = true
}
}
if !isAllowed {
s.ChannelMessageSend(dm.ID, "Du kannst dir keine Rolle zuweisen, da weder Patreon noch Twitch mit deinem Account verlinkt ist oder du Selphy auf keiner dieser Plattformen unterstützt. Bei Problemen wende dich bitte an die `!mods`.")
log.Printf("Denied role %s to %s. User is neither patron nor sub.", roleName(s.State, newRole), userToString(m.Author))
return
}
for _, curRole := range Member.Roles {
// If the user already has one of the available roles, tell them and exit
if newRole == curRole {