modules/config: Read all config from JSON instead of hardcoding them
parent
ae09dbbe85
commit
c73d28cc79
@ -1,3 +1,4 @@
|
||||
token.txt
|
||||
roles.txt
|
||||
bot.db
|
||||
config.json
|
||||
|
@ -1,4 +0,0 @@
|
||||
package config
|
||||
|
||||
const GeneralChannelID = "645550570001924098"
|
||||
const NotInGeneralNerf = 10
|
@ -1,3 +0,0 @@
|
||||
package config
|
||||
|
||||
const CommandPrefix = "pgq"
|
@ -0,0 +1,49 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
type config struct {
|
||||
ActiveNerf activeNerf `json:"activeNerf"`
|
||||
CommandPrefix string `json:"prefix"`
|
||||
GuildID string `json:"guildID"`
|
||||
PrestigeRequirement int `json:"prestigeFactor"`
|
||||
StarChannel string `json:"starChannel"`
|
||||
}
|
||||
|
||||
type activeNerf struct {
|
||||
GeneralChannelID string `json:"channelID"`
|
||||
NotInGeneralNerf int `json:"nerfFactor"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
configFile, err := ioutil.ReadFile("config.json")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var output config
|
||||
err = json.Unmarshal([]byte(configFile), &output)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
//Place everything into high level variables
|
||||
GeneralChannelID = output.ActiveNerf.GeneralChannelID
|
||||
NotInGeneralNerf = output.ActiveNerf.NotInGeneralNerf
|
||||
CommandPrefix = output.CommandPrefix
|
||||
GuildID = output.GuildID
|
||||
PrestigeRequirement = output.PrestigeRequirement
|
||||
StarChannel = output.StarChannel
|
||||
}
|
||||
|
||||
//Exposed Variables
|
||||
var (
|
||||
GeneralChannelID string
|
||||
NotInGeneralNerf int
|
||||
)
|
||||
var CommandPrefix string
|
||||
var GuildID string
|
||||
var PrestigeRequirement int
|
||||
var StarChannel string
|
@ -1,3 +0,0 @@
|
||||
package config
|
||||
|
||||
const GuildID = "645550569573842945"
|
@ -1,3 +0,0 @@
|
||||
package config
|
||||
|
||||
const PrestigeRequirement = 90000
|
@ -1,3 +0,0 @@
|
||||
package config
|
||||
|
||||
const StarChannel = "645551408283648000"
|
Reference in New Issue