From 943e9fcaba008e273d1f95913bf9d9b1171c22b7 Mon Sep 17 00:00:00 2001 From: kageru Date: Sat, 8 Jun 2019 05:30:49 +0200 Subject: [PATCH] add restriction to age roles --- command.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/command.go b/command.go index eba1d42..021f836 100644 --- a/command.go +++ b/command.go @@ -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 {