58 lines
1017 B
Go
58 lines
1017 B
Go
package core
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"log"
|
|
|
|
"gopkg.in/yaml.v2"
|
|
"github.com/bwmarrin/discordgo"
|
|
)
|
|
|
|
type Config struct {
|
|
Token string `yaml:"token"`
|
|
Name string `yaml:"name"`
|
|
}
|
|
|
|
type Command struct {
|
|
name string
|
|
desc string
|
|
example string
|
|
command func(
|
|
s *discordgo.Session,
|
|
m *discordgo.MessageCreate,
|
|
message string)
|
|
}
|
|
|
|
func (c *Config) LoadConf() *Config {
|
|
yamlFile, err := ioutil.ReadFile("config.yaml")
|
|
if err != nil {
|
|
log.Printf("yamlFile.Get err #%v ", err)
|
|
}
|
|
err = yaml.Unmarshal(yamlFile, c)
|
|
if err != nil {
|
|
log.Fatalf("Unmarshal: %v", err)
|
|
}
|
|
return c
|
|
}
|
|
|
|
var CommandRegister = make(
|
|
map[string]Command)
|
|
|
|
func SetCommand(
|
|
aliases []string,
|
|
desc string,
|
|
example string,
|
|
command func(s *discordgo.Session, m *discordgo.MessageCreate, message string)) {
|
|
for _, alias := range aliases {
|
|
c := Command{
|
|
name: alias,
|
|
desc: desc,
|
|
example: example,
|
|
command: command}
|
|
CommandRegister[alias] = c
|
|
log.Printf("added %s to Register", alias)
|
|
}
|
|
}
|
|
|
|
var ConfigRegister Config
|