Register reset command

This commit is contained in:
Daniel_I_Am 2020-08-13 22:38:06 +02:00
parent 61ef1e0ed9
commit e8fd7a47a4
No known key found for this signature in database
GPG Key ID: 80C428FCC9743E84

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Linq;
using Discord.Commands; using Discord.Commands;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Reflection; using System.Reflection;
@ -30,6 +31,8 @@ namespace ChaosBot.Discord.Modules.Admin
await ConfigSet(key, value); await ConfigSet(key, value);
else if (cmd == "get") else if (cmd == "get")
await ConfigGet(key); await ConfigGet(key);
else if (cmd == "reset" || cmd == "unset")
await ConfigReset(key);
else else
await ReplyAsync($"{Context.User.Mention}, The Sub-Command of Config {cmd} does not exist."); 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<string>("Discord:Prefix", Context.Guild.Id, "!")}config set <configFlag> <value>"); sb.AppendLine($"{ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!")}config set <configFlag> <value>");
sb.AppendLine("To get a configuration value:"); sb.AppendLine("To get a configuration value:");
sb.AppendLine($"{ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!")}config get <configFlag>"); sb.AppendLine($"{ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!")}config get <configFlag>");
sb.AppendLine("To reset a configuration value to default:");
sb.AppendLine($"{ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!")}config reset <configFlag>");
sb.AppendLine(); sb.AppendLine();
sb.AppendLine("To view this help:"); sb.AppendLine("To view this help:");
sb.AppendLine($"{ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!")}config help"); sb.AppendLine($"{ConfigurationRepository.GetValue<string>("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}]>."); $"{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}]>.");
}
}
} }
} }