Check for a role before adding to whitelist

Signed-off-by: AKP <tom@tdpain.net>
This commit is contained in:
akp 2023-03-22 15:46:23 +00:00
parent 4e8100e1ed
commit ce8dbcf668
No known key found for this signature in database
GPG key ID: AA5726202C8879B7
2 changed files with 22 additions and 2 deletions

View file

@ -25,8 +25,27 @@ func handleApplicationCommand(s *discordgo.Session, i *discordgo.InteractionCrea
return
}
username, ok := cmdData.Options[0].Value.(string)
if !ok {
rolesOk := false
for _, roleID := range i.Member.Roles {
if roleID == Config.RequiredRole {
rolesOk = true
}
}
if !rolesOk {
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Embeds: []*discordgo.MessageEmbed{
{Description: "Not verified - please verify first.", Color: 0xff0000},
},
},
})
return
}
username, rolesOk := cmdData.Options[0].Value.(string)
if !rolesOk {
log.Error().Interface("val", cmdData.Options[0].Value).Msg("discord api string not a string??")
return
}

View file

@ -15,6 +15,7 @@ var Config = &struct {
ContainerName string `json:"containerName"`
GuildID string `json:"guildID"`
DockerSocket string `json:"dockerSocket"`
RequiredRole string `json:"requiredRole"`
}{}
func main() {