예제 #1
0
        async Task SaveConfig(YModule module)
        {
            string path = $"Config/Modules/{module.Name}.json";
            string json = JsonConvert.SerializeObject(module.GetConfig(), Formatting.Indented);

            await File.WriteAllTextAsync(path, json);
        }
예제 #2
0
        public async Task ModifyConfig(string moduleName, string property, string value, bool save = true)
        {
            YModule module = Bot.ModuleManager.LoadedModules.Find(a => a.Name == moduleName);

            if (module is null)
            {
                await Channel.SendMessageAsync($"Module '{moduleName} does not exist'");

                return;
            }

            Config config = module?.GetType().GetCustomAttribute <Config>(true);

            if (config is null)
            {
                await Channel.SendMessageAsync($"Module '{moduleName} does not have a config class'");

                return;
            }

            Type         configType = module.GetConfig().GetType();
            PropertyInfo pInfo      = configType.GetProperty(property);
            FieldInfo    fInfo      = configType.GetField(property);

            if (pInfo != null)
            {
                pInfo.SetValue(module.GetConfig(), ParseParameter(value, pInfo.PropertyType));
            }

            if (fInfo != null)
            {
                fInfo.SetValue(module.GetConfig(), ParseParameter(value, fInfo.FieldType));
            }


            await Channel.SendMessageAsync($"Config updated");

            if (save)
            {
                await Bot.ModuleManager.SaveConfig();

                await Channel.SendMessageAsync($"Config saved");
            }
        }
예제 #3
0
        public async Task DisplayConfig(string moduleName)
        {
            YModule module = Bot.ModuleManager.LoadedModules.Find(a => a.Name == moduleName);

            if (module is null)
            {
                await Channel.SendMessageAsync($"Module '{moduleName} does not exist'");

                return;
            }

            Config config = module?.GetType().GetCustomAttribute <Config>(true);

            if (config is null)
            {
                await Channel.SendMessageAsync($"Module '{moduleName} does not have a config class'");

                return;
            }

            await Channel.SendMessageAsync($"```{DisplayConfig(module.GetConfig())}```");
        }