2020-06-09 13:04:44 +00:00
|
|
|
package discord
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
2021-02-22 05:36:06 +00:00
|
|
|
|
|
|
|
"github.com/bwmarrin/discordgo"
|
2020-06-09 13:04:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
commands["help"] = command{
|
|
|
|
validate: func(cmd commandInit) bool {
|
|
|
|
return true
|
|
|
|
},
|
2020-06-12 05:17:58 +00:00
|
|
|
run: func(cmd commandInit) (string, error) {
|
2020-06-09 13:04:44 +00:00
|
|
|
args := strings.Fields(cmd.message.Content)[1:]
|
|
|
|
|
2021-02-22 05:36:06 +00:00
|
|
|
var resp *discordgo.MessageEmbed
|
2020-06-09 13:04:44 +00:00
|
|
|
if len(args) == 1 {
|
2021-02-22 05:36:06 +00:00
|
|
|
resp = singleHelp(cmd, args[0])
|
2020-06-09 13:04:44 +00:00
|
|
|
} else {
|
2021-02-22 05:36:06 +00:00
|
|
|
resp = allHelp(cmd)
|
|
|
|
}
|
|
|
|
|
|
|
|
channel, err := cmd.session.UserChannelCreate(cmd.message.Author.ID)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
2020-06-09 13:04:44 +00:00
|
|
|
}
|
2021-02-22 05:36:06 +00:00
|
|
|
|
|
|
|
sendEmbed(cmd.session, channel.ID, resp)
|
|
|
|
return "", nil
|
2020-06-09 13:04:44 +00:00
|
|
|
},
|
|
|
|
help: "HELP! HEEEEEEEEEELP!",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-22 05:36:06 +00:00
|
|
|
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
|
2020-06-09 13:04:44 +00:00
|
|
|
}
|
2021-02-22 05:36:06 +00:00
|
|
|
|
|
|
|
embed.Title = arg
|
|
|
|
embed.Description = c.help
|
|
|
|
return embed
|
2020-06-09 13:04:44 +00:00
|
|
|
}
|
|
|
|
|
2021-02-22 05:36:06 +00:00
|
|
|
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"
|
|
|
|
}
|
2020-06-09 13:04:44 +00:00
|
|
|
for n, c := range commands {
|
2021-02-22 05:36:06 +00:00
|
|
|
cmdName := n
|
|
|
|
if c.staffOnly {
|
|
|
|
cmdName += "*"
|
|
|
|
}
|
|
|
|
if !c.staffOnly || staff {
|
|
|
|
embed.Fields = append(embed.Fields, &discordgo.MessageEmbedField{
|
|
|
|
Name: cmdName,
|
|
|
|
Value: c.help,
|
|
|
|
Inline: true,
|
|
|
|
})
|
|
|
|
}
|
2020-06-09 13:04:44 +00:00
|
|
|
}
|
2021-02-22 05:36:06 +00:00
|
|
|
return embed
|
2020-06-09 13:04:44 +00:00
|
|
|
}
|