crude implementation for a global command object/register
This commit is contained in:
@ -5,14 +5,15 @@ import (
|
||||
"log"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
"github.com/bwmarrin/discordgo"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
type ConfigRegister struct {
|
||||
Token string `yaml:"token"`
|
||||
Name string `yaml:"name"`
|
||||
}
|
||||
|
||||
func (c *Config) LoadConf() *Config {
|
||||
func (c *ConfigRegister) LoadConf() *ConfigRegister {
|
||||
yamlFile, err := ioutil.ReadFile("config.yaml")
|
||||
if err != nil {
|
||||
log.Printf("yamlFile.Get err #%v ", err)
|
||||
@ -23,3 +24,21 @@ func (c *Config) LoadConf() *Config {
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
var CommandRegister = make(
|
||||
map[string]func(
|
||||
s *discordgo.Session,
|
||||
m *discordgo.MessageCreate))
|
||||
|
||||
func SetCommand(aliases []string, command func(
|
||||
s *discordgo.Session,
|
||||
m *discordgo.MessageCreate),
|
||||
discord *discordgo.Session) {
|
||||
for _, alias := range aliases {
|
||||
CommandRegister[alias] = command
|
||||
log.Printf("added %s to Register", alias)
|
||||
}
|
||||
discord.AddHandler(command)
|
||||
}
|
||||
|
||||
var Config ConfigRegister
|
||||
|
||||
Reference in New Issue
Block a user