package discord import ( "strings" "github.com/bwmarrin/discordgo" ) func init() { commands["help"] = command{ validate: func(cmd commandInit) bool { return true }, run: func(cmd commandInit) (string, error) { args := strings.Fields(cmd.message.Content)[1:] var resp *discordgo.MessageEmbed if len(args) == 1 { resp = singleHelp(cmd, args[0]) } else { resp = allHelp(cmd) } channel, err := cmd.session.UserChannelCreate(cmd.message.Author.ID) if err != nil { return "", err } sendEmbed(cmd.session, channel.ID, resp) return "", nil }, help: "HELP! HEEEEEEEEEELP!", } } func singleHelp(cmd commandInit, arg string) *discordgo.MessageEmbed { embed := &discordgo.MessageEmbed{ Title: "Unkown Command", } c, ok := commands[arg] if !ok { return embed } if c.staffOnly && !isStaff(cmd.message.Member.Roles, cmd.config.StaffRoles) { return embed } embed.Title = arg embed.Description = c.help return embed } func allHelp(cmd commandInit) *discordgo.MessageEmbed { staff := isStaff(cmd.message.Member.Roles, cmd.config.StaffRoles) embed := &discordgo.MessageEmbed{ Title: "SedBot Help", Fields: make([]*discordgo.MessageEmbedField, 0), } if staff { embed.Description = "Commands with an asterisk (*) are staff-only" } for n, c := range commands { cmdName := n if c.staffOnly { cmdName += "*" } if !c.staffOnly || staff { embed.Fields = append(embed.Fields, &discordgo.MessageEmbedField{ Name: cmdName, Value: c.help, Inline: true, }) } } return embed }