diff --git a/auth.go b/auth.go index 6f80899..9e215f8 100644 --- a/auth.go +++ b/auth.go @@ -186,3 +186,12 @@ func idFromUsername(username string) string { } return userID } + +func isAdmin(m *discordgo.Member) bool { + for role := range m.Roles { + if fmt.Sprintf("%+v", role) == config.AdminRole { + return true + } + } + return false +} diff --git a/commands.go b/commands.go index 83d1755..4b76b32 100644 --- a/commands.go +++ b/commands.go @@ -75,7 +75,13 @@ func Commands(b BotCommand) bool { defer log.PanicSafe() print := "Available commands:\n" for _, cmd := range commands { - print += fmt.Sprintf("```%+v\n%+v\n%+v```\n", cmd.Name, cmd.Keywords, cmd.Help) + if cmd.RequiresAdmin { + if isAdmin(b.Message.Member) { + print += fmt.Sprintf("```%+v\n%+v\n%+v```\n", cmd.Name, cmd.Keywords, cmd.Help) + } + } else { + print += fmt.Sprintf("```%+v\n%+v\n%+v```\n", cmd.Name, cmd.Keywords, cmd.Help) + } } return true } diff --git a/discordMessage.go b/discordMessage.go index bd71309..a56d2c2 100644 --- a/discordMessage.go +++ b/discordMessage.go @@ -62,11 +62,9 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) { s.ChannelMessageSend(config.AdminChannel, fmt.Sprintf("There was an error running %+v\n%+v", cmd.Name, cmd.Help)) } } else { - for role := range m.Member.Roles { - if fmt.Sprintf("%+v", role) == config.AdminRole { - if !cmd.Exec(b) { - s.ChannelMessageSend(config.AdminChannel, fmt.Sprintf("There was an error running %+v\n%+v", cmd.Name, cmd.Help)) - } + if isAdmin(m.Member) { + if !cmd.Exec(b) { + s.ChannelMessageSend(config.AdminChannel, fmt.Sprintf("There was an error running %+v\n%+v", cmd.Name, cmd.Help)) } } }