go: add help command and refactor commands.go
parent
5a31d1fe1e
commit
42ef07a1b4
@ -1,44 +1,75 @@
|
|||||||
package modules
|
package modules
|
||||||
|
|
||||||
import "github.com/bwmarrin/discordgo"
|
import (
|
||||||
|
"TerraOceanBot/discord/config"
|
||||||
|
|
||||||
|
"github.com/bwmarrin/discordgo"
|
||||||
|
)
|
||||||
|
|
||||||
type CommandHandler func(s *discordgo.Session, m *discordgo.MessageCreate, commands []string)
|
type CommandHandler func(s *discordgo.Session, m *discordgo.MessageCreate, commands []string)
|
||||||
type Command struct {
|
type Command struct {
|
||||||
Name string
|
Name string
|
||||||
Handler CommandHandler
|
Handler CommandHandler
|
||||||
|
Description string
|
||||||
|
Usage string
|
||||||
|
Admin bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var Commands = []Command{
|
var Commands = []Command{
|
||||||
Command{
|
//Admin Commands
|
||||||
Name: "!sendas",
|
|
||||||
Handler: sendAs,
|
|
||||||
},
|
|
||||||
Command{
|
Command{
|
||||||
Name: "!editas",
|
Name: "!editas",
|
||||||
Handler: editAs,
|
Handler: editAs,
|
||||||
|
Usage: config.EditAsUsage,
|
||||||
|
Admin: true,
|
||||||
},
|
},
|
||||||
Command{
|
Command{
|
||||||
Name: "!peektrust",
|
Name: "!peektrust",
|
||||||
Handler: viewTrustLevel,
|
Handler: viewTrustLevel,
|
||||||
|
Usage: config.VTLUsage,
|
||||||
|
Admin: true,
|
||||||
|
},
|
||||||
|
Command{
|
||||||
|
Name: "!sendas",
|
||||||
|
Handler: sendAs,
|
||||||
|
Usage: config.SendAsUsage,
|
||||||
|
Admin: true,
|
||||||
|
},
|
||||||
|
//Regular Commands
|
||||||
|
Command{
|
||||||
|
Name: "!help",
|
||||||
|
Handler: showHelp,
|
||||||
|
Usage: "!help",
|
||||||
|
Admin: false,
|
||||||
},
|
},
|
||||||
Command{
|
Command{
|
||||||
Name: "!invite",
|
Name: "!invite",
|
||||||
Handler: createInvite,
|
Handler: createInvite,
|
||||||
|
Usage: config.InviteUsage,
|
||||||
|
Admin: false,
|
||||||
},
|
},
|
||||||
Command{
|
Command{
|
||||||
Name: "!validate",
|
Name: "!setmcusername",
|
||||||
Handler: checkUseInvite,
|
Handler: updateMinecraftUsername,
|
||||||
|
Usage: config.SetMCUsernameUsage,
|
||||||
|
Admin: false,
|
||||||
},
|
},
|
||||||
Command{
|
Command{
|
||||||
Name: "!trust",
|
Name: "!trust",
|
||||||
Handler: changeTrust,
|
Handler: changeTrust,
|
||||||
|
Usage: config.ChangeTrustUsage,
|
||||||
|
Admin: false,
|
||||||
},
|
},
|
||||||
Command{
|
Command{
|
||||||
Name: "!setmcusername",
|
Name: "!validate",
|
||||||
Handler: updateMinecraftUsername,
|
Handler: checkUseInvite,
|
||||||
|
Usage: config.ValidateUsage,
|
||||||
|
Admin: false,
|
||||||
},
|
},
|
||||||
Command{
|
Command{
|
||||||
Name: "!votesuggest",
|
Name: "!votesuggest",
|
||||||
Handler: voteSuggestion,
|
Handler: voteSuggestion,
|
||||||
|
Usage: config.VoteSuggestionUsage,
|
||||||
|
Admin: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,35 @@
|
|||||||
|
package modules
|
||||||
|
|
||||||
|
import (
|
||||||
|
"TerraOceanBot/discord/config"
|
||||||
|
"TerraOceanBot/discord/message"
|
||||||
|
|
||||||
|
"github.com/bwmarrin/discordgo"
|
||||||
|
)
|
||||||
|
|
||||||
|
var embed *discordgo.MessageEmbed
|
||||||
|
|
||||||
|
//GenerateHelpEmbed sets up the embed variable above to be used to display the !help command.
|
||||||
|
func GenerateHelpEmbed() {
|
||||||
|
emb := message.NewEmbed().
|
||||||
|
SetTitle(config.HelpTitle).
|
||||||
|
SetColour(config.HelpColour).
|
||||||
|
SetDescription(config.HelpDescription)
|
||||||
|
|
||||||
|
for _, cmd := range Commands {
|
||||||
|
usage := cmd.Usage
|
||||||
|
if usage == "" {
|
||||||
|
usage = "No usage provided"
|
||||||
|
}
|
||||||
|
emb.AddField(cmd.Name, usage)
|
||||||
|
}
|
||||||
|
|
||||||
|
embed = emb.Build()
|
||||||
|
}
|
||||||
|
|
||||||
|
func showHelp(s *discordgo.Session, m *discordgo.MessageCreate, commands []string) {
|
||||||
|
_, err := s.ChannelMessageSendEmbed(m.ChannelID, embed)
|
||||||
|
if err != nil {
|
||||||
|
message.AuditError(s, m.ChannelID, err)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue