go: add help command and refactor commands.go

pull/13/head
ALI Hamza 2019-10-14 19:28:46 +07:00
parent 5a31d1fe1e
commit 42ef07a1b4
No known key found for this signature in database
GPG Key ID: BCA8A46C87798C4C
4 changed files with 84 additions and 11 deletions

@ -1,5 +1,10 @@
package config
//==Help Command==
const HelpTitle = "指令列表 Command List"
const HelpColour = 0x00E58D
const HelpDescription = "这个信息包含了所有指令的资料。\nThis message contains all the information about available commands."
//==Message Util==
const UsageTitle = "使用方法 Command Usage"
const UsageColour = 0xF00000
@ -61,6 +66,7 @@ const EditAsUsage = "!editas <频道ID> <信息ID> <信息>\n!editas <channel ID
const EditAsSuccessfulDescription = "成功编辑该信息。\nMessage edited successfully."
//VTL is view trust level
const VTLUsage = "!peektrust [目标]\n!peektrust [target]"
const VTLColour = 0xE0E000
const VTLSingleUserTitle = "<@%s>的信誉分 <@%s>'s Trust Score"
const VTLSingleUserValue = "分数 Trust Score"

@ -25,6 +25,7 @@ func StartBot(token string, kill chan bool) {
}
fmt.Println("Bot is now running. Press CTRL-C to exit.")
modules.GenerateHelpEmbed()
go modules.ListenToVoteFinishes(dg)
go backend.UpdateVoiceChannelState(dg)

@ -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)
}
}