forked from chanbakjsd/TerraOceanPlugin
go: add help command and refactor commands.go
parent
5a31d1fe1e
commit
42ef07a1b4
@ -1,44 +1,75 @@
|
||||
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 Command struct {
|
||||
Name string
|
||||
Handler CommandHandler
|
||||
Name string
|
||||
Handler CommandHandler
|
||||
Description string
|
||||
Usage string
|
||||
Admin bool
|
||||
}
|
||||
|
||||
var Commands = []Command{
|
||||
Command{
|
||||
Name: "!sendas",
|
||||
Handler: sendAs,
|
||||
},
|
||||
//Admin Commands
|
||||
Command{
|
||||
Name: "!editas",
|
||||
Handler: editAs,
|
||||
Usage: config.EditAsUsage,
|
||||
Admin: true,
|
||||
},
|
||||
Command{
|
||||
Name: "!peektrust",
|
||||
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{
|
||||
Name: "!invite",
|
||||
Handler: createInvite,
|
||||
Usage: config.InviteUsage,
|
||||
Admin: false,
|
||||
},
|
||||
Command{
|
||||
Name: "!validate",
|
||||
Handler: checkUseInvite,
|
||||
Name: "!setmcusername",
|
||||
Handler: updateMinecraftUsername,
|
||||
Usage: config.SetMCUsernameUsage,
|
||||
Admin: false,
|
||||
},
|
||||
Command{
|
||||
Name: "!trust",
|
||||
Handler: changeTrust,
|
||||
Usage: config.ChangeTrustUsage,
|
||||
Admin: false,
|
||||
},
|
||||
Command{
|
||||
Name: "!setmcusername",
|
||||
Handler: updateMinecraftUsername,
|
||||
Name: "!validate",
|
||||
Handler: checkUseInvite,
|
||||
Usage: config.ValidateUsage,
|
||||
Admin: false,
|
||||
},
|
||||
Command{
|
||||
Name: "!votesuggest",
|
||||
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