2020-06-09 13:04:44 +00:00
|
|
|
package discord
|
|
|
|
|
|
|
|
import (
|
2021-02-23 05:53:55 +00:00
|
|
|
"fmt"
|
2020-06-09 13:04:44 +00:00
|
|
|
"strings"
|
2021-02-22 18:27:49 +00:00
|
|
|
|
|
|
|
"github.com/bwmarrin/discordgo"
|
2020-06-09 13:04:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2021-02-23 05:53:55 +00:00
|
|
|
commands = append(commands, &command{
|
|
|
|
deleteInvocation: true,
|
|
|
|
name: "help",
|
2020-06-09 13:04:44 +00:00
|
|
|
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 18:27:49 +00:00
|
|
|
var resp *discordgo.MessageEmbed
|
2020-06-09 13:04:44 +00:00
|
|
|
if len(args) == 1 {
|
2021-02-22 18:27:49 +00:00
|
|
|
resp = singleHelp(cmd, args[0])
|
2020-06-09 13:04:44 +00:00
|
|
|
} else {
|
2021-02-22 18:27:49 +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 18:27:49 +00:00
|
|
|
|
|
|
|
sendEmbed(cmd.session, channel.ID, resp)
|
|
|
|
return "", nil
|
2020-06-09 13:04:44 +00:00
|
|
|
},
|
|
|
|
help: "HELP! HEEEEEEEEEELP!",
|
2021-02-23 05:53:55 +00:00
|
|
|
})
|
2020-06-09 13:04:44 +00:00
|
|
|
}
|
|
|
|
|
2021-02-22 18:27:49 +00:00
|
|
|
func singleHelp(cmd commandInit, arg string) *discordgo.MessageEmbed {
|
|
|
|
embed := &discordgo.MessageEmbed{
|
|
|
|
Title: "Unkown Command",
|
2021-02-23 05:53:55 +00:00
|
|
|
Color: 0x007D96,
|
2021-02-22 18:27:49 +00:00
|
|
|
}
|
2021-02-23 05:53:55 +00:00
|
|
|
c, ok := commandMap[arg]
|
2021-02-22 18:27:49 +00:00
|
|
|
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 18:27:49 +00:00
|
|
|
|
2021-02-23 05:53:55 +00:00
|
|
|
embed.Title = c.name
|
2021-02-22 18:27:49 +00:00
|
|
|
embed.Description = c.help
|
|
|
|
return embed
|
2020-06-09 13:04:44 +00:00
|
|
|
}
|
|
|
|
|
2021-02-22 18:27:49 +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"
|
|
|
|
}
|
2021-02-23 05:53:55 +00:00
|
|
|
for _, c := range commands {
|
2021-05-14 03:10:02 +00:00
|
|
|
if c.child {
|
2021-02-23 05:53:55 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
cmdName := c.name
|
|
|
|
if len(c.aliases) > 0 {
|
|
|
|
cmdName += fmt.Sprintf(" (%s)", strings.Join(c.aliases, ", "))
|
|
|
|
}
|
2021-02-22 18:27:49 +00:00
|
|
|
if c.staffOnly {
|
2021-02-23 05:53:55 +00:00
|
|
|
cmdName = fmt.Sprintf("*%s", cmdName)
|
2021-02-22 18:27:49 +00:00
|
|
|
}
|
|
|
|
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 18:27:49 +00:00
|
|
|
return embed
|
2020-06-09 13:04:44 +00:00
|
|
|
}
|