diff --git a/ChaosBot/Discord/Modules/Admin/Config.cs b/ChaosBot/Discord/Modules/Admin/Config.cs index d95fd4a..bdd4dc6 100644 --- a/ChaosBot/Discord/Modules/Admin/Config.cs +++ b/ChaosBot/Discord/Modules/Admin/Config.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using Discord.Commands; using System.Threading.Tasks; using System.Reflection; @@ -30,6 +31,8 @@ namespace ChaosBot.Discord.Modules.Admin await ConfigSet(key, value); else if (cmd == "get") await ConfigGet(key); + else if (cmd == "reset" || cmd == "unset") + await ConfigReset(key); else await ReplyAsync($"{Context.User.Mention}, The Sub-Command of Config {cmd} does not exist."); } @@ -54,6 +57,8 @@ namespace ChaosBot.Discord.Modules.Admin sb.AppendLine($"{ConfigurationRepository.GetValue("Discord:Prefix", Context.Guild.Id, "!")}config set "); sb.AppendLine("To get a configuration value:"); sb.AppendLine($"{ConfigurationRepository.GetValue("Discord:Prefix", Context.Guild.Id, "!")}config get "); + sb.AppendLine("To reset a configuration value to default:"); + sb.AppendLine($"{ConfigurationRepository.GetValue("Discord:Prefix", Context.Guild.Id, "!")}config reset "); sb.AppendLine(); sb.AppendLine("To view this help:"); sb.AppendLine($"{ConfigurationRepository.GetValue("Discord:Prefix", Context.Guild.Id, "!")}config help"); @@ -151,5 +156,44 @@ namespace ChaosBot.Discord.Modules.Admin $"{MethodBase.GetCurrentMethod().ReflectedType.FullName}: Exception [{ex}] thrown, <[{ex.Message}]>."); } } + + public async Task ConfigReset(string key) + { + try + { + if ((key != null) && (await RestrictedConfig.IsAllowed(key))) + { + StringBuilder sb = new StringBuilder(); + EmbedBuilder embed = new EmbedBuilder(); + + ConfigurationRepository.DeleteValue(key, Context.Guild.Id); + + embed.WithColor(new Color(255, 255, 0)); + embed.Title = $"Configuration Reset"; + sb.AppendLine(); + sb.AppendLine($" Flag: {key}"); + + /* + * Add the string to the Embed + */ + embed.Description = sb.ToString(); + + /* + * Reply with the Embed created above + */ + await ReplyAsync(null, false, embed.Build()); + } + else + { + await ConfigHelp(); + } + + } + catch (Exception ex) + { + _logger.Error( + $"{MethodBase.GetCurrentMethod().ReflectedType.FullName}: Exception [{ex}] thrown, <[{ex.Message}]>."); + } + } } } \ No newline at end of file