Browse Source

Only show commands available to the user

master
Gregory Rudolph 4 years ago
parent
commit
77b6e9c780
Signed by: rudi
GPG Key ID: EF64F3CBD1A1EBDD
  1. 9
      auth.go
  2. 8
      commands.go
  3. 8
      discordMessage.go

9
auth.go

@ -186,3 +186,12 @@ func idFromUsername(username string) string {
} }
return userID return userID
} }
func isAdmin(m *discordgo.Member) bool {
for role := range m.Roles {
if fmt.Sprintf("%+v", role) == config.AdminRole {
return true
}
}
return false
}

8
commands.go

@ -75,7 +75,13 @@ func Commands(b BotCommand) bool {
defer log.PanicSafe() defer log.PanicSafe()
print := "Available commands:\n" print := "Available commands:\n"
for _, cmd := range commands { 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 return true
} }

8
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)) s.ChannelMessageSend(config.AdminChannel, fmt.Sprintf("There was an error running %+v\n%+v", cmd.Name, cmd.Help))
} }
} else { } else {
for role := range m.Member.Roles { if isAdmin(m.Member) {
if fmt.Sprintf("%+v", role) == config.AdminRole { if !cmd.Exec(b) {
if !cmd.Exec(b) { s.ChannelMessageSend(config.AdminChannel, fmt.Sprintf("There was an error running %+v\n%+v", cmd.Name, cmd.Help))
s.ChannelMessageSend(config.AdminChannel, fmt.Sprintf("There was an error running %+v\n%+v", cmd.Name, cmd.Help))
}
} }
} }
} }

Loading…
Cancel
Save