Merge branch 'develop' into master
This commit is contained in:
commit
0e3c3f0d22
@ -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<string>("Discord:Prefix", Context.Guild.Id, "!")}config set <configFlag> <value>");
|
||||
sb.AppendLine("To get a configuration value:");
|
||||
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("To view this 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}]>.");
|
||||
}
|
||||
}
|
||||
|
||||
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}]>.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -25,6 +25,18 @@ namespace ChaosBot.Repositories
|
||||
}
|
||||
}
|
||||
|
||||
public static void DeleteValue(string key, ulong guildId)
|
||||
{
|
||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
||||
{
|
||||
Configuration config = dbContext.Configuration
|
||||
.SingleOrDefault(c => c.DiscordGuildId == guildId && c.Key == key);
|
||||
if (config == null) return;
|
||||
dbContext.Remove(config);
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
private static T GetValueFromAppSettings<T>(string key, ulong guildId, T defaultValue)
|
||||
{
|
||||
return Program.AppSettingsHandler.GetValue($"Servers:{guildId}:{key}", Program.AppSettingsHandler.GetValue(key, defaultValue));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user