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); }
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"); } }
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())}```"); }