Esempio n. 1
0
 public Startup(string[] args)
 {
     // Load in our data from our JSON config file
     GlobalConfig.LoadConfig(GlobalConfigInstance.GetInstance(
                                 $@"{AppContext.BaseDirectory}/AppConfig.json"));
     Logger.StartLogger();
 }
Esempio n. 2
0
        public static GlobalConfigInstance GetInstance(string path)
        {
            string json = File.ReadAllText(path);
            GlobalConfigInstance instance = JsonConvert.DeserializeObject <GlobalConfigInstance>(json);

            instance.DbUrl  = string.IsNullOrWhiteSpace(instance.DbUrl) ? "http://localhost:8080" : instance.DbUrl;
            instance.DbName = string.IsNullOrWhiteSpace(instance.DbName) ? "Raven" : instance.DbName;
            instance.Prefix = string.IsNullOrWhiteSpace(instance.Prefix) ? "|" : instance.Prefix;

            if (string.IsNullOrWhiteSpace(instance.Token))
            {
                throw new InvalidOperationException("Discord token is not present. Please see AppConfig.json and ensure the \"token:\" field is correct.");
            }
            if (instance.Shards is null || instance.Shards <= 0)
            {
                instance.Shards = 2;
            }

            if (instance.MinGlobalXpGeneration is null || instance.MinGlobalXpGeneration is 0)
            {
                instance.MinGlobalXpGeneration = 2;
                Logger.Log("Minimum XP was null or 0. Defaulting to 2.", "AppConfig.json", LogSeverity.Warning);
            }

            if (instance.MaxGlobalXpGeneration is null || instance.MaxGlobalXpGeneration is 0)
            {
                instance.MaxGlobalXpGeneration = 5;
                Logger.Log("Maximum XP was null or 0. Defaulting to 5.", "AppConfig.json", LogSeverity.Warning);
            }

            if (instance.MinTimeBetweenXpGeneration is null || instance.MinTimeBetweenXpGeneration is 0)
            {
                instance.MinTimeBetweenXpGeneration = 60;
                Logger.Log("Min XP Time was null or 0. Defaulting to 60.", "AppConfig.json", LogSeverity.Warning);
            }

            if (instance.MinGlobalXpGeneration > instance.MaxGlobalXpGeneration)
            {
                instance.MinGlobalXpGeneration = instance.MaxGlobalXpGeneration;
                Logger.Log("Minimum XP was greater than the maximum. Defaulting to same value.", "AppConfig.json", LogSeverity.Warning);
            }
            else if (instance.MaxGlobalXpGeneration < instance.MinGlobalXpGeneration)
            {
                instance.MaxGlobalXpGeneration = instance.MinGlobalXpGeneration;
                Logger.Log("Maximum XP was below the minimum. Defaulting to same value.", "AppConfig.json", LogSeverity.Warning);
            }

            return(instance);
        }
Esempio n. 3
0
        public Startup(string[] args)
        {
            // If in debug mode, copy our JSON config over as well as our external menu files
            // I'll probably look into a better way of packaging them for future releases

            /*if (Debugger.IsAttached)
             * {
             *  File.Copy($@"{AppContext.BaseDirectory}/../../../AppConfig.json",
             *      $@"{AppContext.BaseDirectory}/AppConfig.json", true);
             *  Directory.CreateDirectory(AppContext.BaseDirectory + "/ConfigTextFiles");
             *  foreach (var file in Directory.GetFiles(AppContext.BaseDirectory + "/../../../ConfigTextFiles"))
             *      File.Copy(file, Path.Combine(AppContext.BaseDirectory + "/ConfigTextFiles", Path.GetFileName(file)), true);
             * }*/

            // Load in our data from our JSON config file
            GlobalConfig.LoadConfig(GlobalConfigInstance.GetInstance(
                                        $@"{AppContext.BaseDirectory}/AppConfig.json"));
        }
Esempio n. 4
0
        public static void LoadConfig(GlobalConfigInstance instance)
        {
            // Get an array of all the properties
            PropertyInfo[] props = instance.GetType().GetProperties();

            // Get only the static properties
            PropertyInfo[] staticProps = typeof(GlobalConfig).GetProperties(BindingFlags.Public | BindingFlags.Static);

            // Iterate over our properties
            foreach (var prop in props)
            {
                // Find matching static properties
                var destinationProp = staticProps.Single(p => p.Name == prop.Name);

                // Set the static property value
                destinationProp.SetValue(null, prop.GetValue(instance));
            }

            if (OwnerIds is null)
            {
                OwnerIds = new ulong[0];
            }
        }