fix: Using to init function
This commit is contained in:
parent
9af72608db
commit
60694a8705
4 changed files with 17 additions and 21 deletions
|
@ -59,20 +59,20 @@ type Component struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Chattings Category = "채팅"
|
Chatting Category = "채팅"
|
||||||
Generals Category = "일반"
|
Generals Category = "일반"
|
||||||
)
|
)
|
||||||
|
|
||||||
var commandMutex sync.Mutex
|
var commandMutex sync.Mutex
|
||||||
var componentMutex sync.Mutex
|
var componentMutex sync.Mutex
|
||||||
|
var Discommand *DiscommandStruct
|
||||||
|
|
||||||
func new() *DiscommandStruct {
|
func init() {
|
||||||
discommand := DiscommandStruct{
|
Discommand = &DiscommandStruct{
|
||||||
Commands: map[string]*Command{},
|
Commands: map[string]*Command{},
|
||||||
Aliases: map[string]string{},
|
Aliases: map[string]string{},
|
||||||
Components: []*Component{},
|
Components: []*Component{},
|
||||||
}
|
}
|
||||||
return &discommand
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DiscommandStruct) LoadCommand(c *Command) {
|
func (d *DiscommandStruct) LoadCommand(c *Command) {
|
||||||
|
@ -124,5 +124,3 @@ func (d *DiscommandStruct) ComponentRun(s *discordgo.Session, i *discordgo.Inter
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var Discommand *DiscommandStruct = new()
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ var LearnedDataListCommand *Command = &Command{
|
||||||
DetailedDescription: &DetailedDescription{
|
DetailedDescription: &DetailedDescription{
|
||||||
Usage: fmt.Sprintf("%s리스트", configs.Config.Bot.Prefix),
|
Usage: fmt.Sprintf("%s리스트", configs.Config.Bot.Prefix),
|
||||||
},
|
},
|
||||||
Category: Chattings,
|
Category: Chatting,
|
||||||
MessageRun: func(ctx *MsgContext) {
|
MessageRun: func(ctx *MsgContext) {
|
||||||
learnedDataListRun(ctx.Session, ctx.Msg)
|
learnedDataListRun(ctx.Session, ctx.Msg)
|
||||||
},
|
},
|
||||||
|
|
|
@ -26,12 +26,12 @@ type MuffinConfig struct {
|
||||||
DBName string
|
DBName string
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadConfig() *MuffinConfig {
|
var Config *MuffinConfig
|
||||||
|
|
||||||
|
func init() {
|
||||||
godotenv.Load()
|
godotenv.Load()
|
||||||
config := &MuffinConfig{Bot: botConfig{}, Train: trainConfig{}}
|
config := &MuffinConfig{Bot: botConfig{}, Train: trainConfig{}}
|
||||||
setConfig(config)
|
setValues(config)
|
||||||
|
|
||||||
return config
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getRequiredValue(key string) string {
|
func getRequiredValue(key string) string {
|
||||||
|
@ -46,7 +46,7 @@ func getValue(key string) string {
|
||||||
return os.Getenv(key)
|
return os.Getenv(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
func setConfig(config *MuffinConfig) {
|
func setValues(config *MuffinConfig) {
|
||||||
config.Bot.Prefix = getRequiredValue("BOT_PREFIX")
|
config.Bot.Prefix = getRequiredValue("BOT_PREFIX")
|
||||||
config.Bot.Token = getRequiredValue("BOT_TOKEN")
|
config.Bot.Token = getRequiredValue("BOT_TOKEN")
|
||||||
config.Bot.OwnerId = getRequiredValue("BOT_OWNER_ID")
|
config.Bot.OwnerId = getRequiredValue("BOT_OWNER_ID")
|
||||||
|
@ -56,5 +56,3 @@ func setConfig(config *MuffinConfig) {
|
||||||
config.DatabaseURL = getRequiredValue("DATABASE_URL")
|
config.DatabaseURL = getRequiredValue("DATABASE_URL")
|
||||||
config.DBName = getRequiredValue("DATABASE_NAME")
|
config.DBName = getRequiredValue("DATABASE_NAME")
|
||||||
}
|
}
|
||||||
|
|
||||||
var Config *MuffinConfig = loadConfig()
|
|
||||||
|
|
|
@ -8,13 +8,13 @@ import (
|
||||||
"go.mongodb.org/mongo-driver/v2/mongo/options"
|
"go.mongodb.org/mongo-driver/v2/mongo/options"
|
||||||
)
|
)
|
||||||
|
|
||||||
func connect() *mongo.Client {
|
var Client *mongo.Client
|
||||||
client, err := mongo.Connect(options.Client().ApplyURI(configs.Config.DatabaseURL))
|
|
||||||
|
func init() {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
Client, err = mongo.Connect(options.Client().ApplyURI(configs.Config.DatabaseURL))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return client
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var Client *mongo.Client = connect()
|
|
||||||
|
|
Loading…
Reference in a new issue