modules/config: Read all config from JSON instead of hardcoding them

master
Luther Wen Xu 2019-12-13 17:52:36 +07:00
parent ae09dbbe85
commit c73d28cc79
Signed by: chanbakjsd
GPG Key ID: B7D77E3E9D102B70
7 changed files with 50 additions and 16 deletions

1
.gitignore vendored

@ -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"