This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
PermissionGacha/modules/config/config.go

79 lines
1.9 KiB
Go

package config
import (
"encoding/json"
"io/ioutil"
"strings"
)
type config struct {
ActiveNerf activeNerf `json:"activeNerf"`
Admins []string `json:"admin"`
CommandPrefix string `json:"prefix"`
GuildID string `json:"guildID"`
PrestigeRequirement int `json:"prestigeFactor"`
StarChannel string `json:"starChannel"`
BotToken string `json:"token"`
Rewards []Reward `json:"rewards"`
LevelRoles []string `json:"roles"`
}
type activeNerf struct {
GeneralChannelID []string `json:"channelID"`
NotInGeneralNerf int `json:"nerfFactor"`
}
type Reward struct {
FriendlyName string `json:"friendlyName"`
Type string `json:"type"`
Weight int `json:"weight"`
Context map[string]interface{} `json:"context"`
}
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
Admins = output.Admins
CommandPrefix = strings.ToLower(output.CommandPrefix)
GuildID = output.GuildID
PrestigeRequirement = output.PrestigeRequirement
StarChannel = output.StarChannel
BotToken = output.BotToken
LevelRoles = output.LevelRoles
Rewards = output.Rewards
if len(Rewards) == 0 {
panic("modules/config: Gacha rewards not provided")
}
for _, v := range output.Rewards {
TotalRewardWeight += v.Weight
}
}
//Exposed Variables
var (
GeneralChannelID []string
NotInGeneralNerf int
)
var Admins []string
var CommandPrefix string
var GuildID string
var PrestigeRequirement int
var StarChannel string
var BotToken string
var LevelRoles []string
var (
Rewards []Reward
TotalRewardWeight int
)