chaosbot/ChaosBot/Discord/Modules/ConfigCommands.cs

80 lines
2.7 KiB
C#

using System;
using Discord;
using Discord.Commands;
using System.Threading.Tasks;
using System.Collections.Generic;
using NLog;
using System.Text;
using ChaosBot.Database.Repository;
namespace ChaosBot.Discord.Modules
{
public class ConfigCommands : ModuleBase
{
private static readonly Logger _logger = Program._logger;
private static readonly string _prefix = ConfigurationRepository.GetValue<string>("Discord:Prefix");
[Command("config")]
[RequireBotPermission(GuildPermission.ManageGuild)]
[RequireUserPermission(GuildPermission.ManageGuild)]
public async Task setConfig(string configFlag = null, string value = null)
{
var sb = new StringBuilder();
var embed = new EmbedBuilder();
try
{
if (configFlag == null || value == null)
{
await ReplyAsync($"Syntax Wrong. Please see {_prefix}config help");
return;
}
ConfigurationRepository.SetValue<String>(configFlag, Context.Guild.Id, value);
embed.WithColor(new Color(255, 255, 0));
embed.Title = $"Configuration Management";
sb.AppendLine($"{Context.User.Mention} has changed the Configuration.");
sb.AppendLine();
sb.AppendLine($"{configFlag} == {value}");
/*
* Add the string to the Embed
*/
embed.Description = sb.ToString();
/*
* Reply with the Embed created above
*/
await ReplyAsync(null, false, embed.Build());
}
catch (Exception ex)
{
_logger.Error($"ConfigCommands.setCfg: Exception [{ex}] thrown, <[{ex.Message}]>.");
}
}
[Command("config help")]
[RequireBotPermission(GuildPermission.ManageGuild)]
[RequireUserPermission(GuildPermission.ManageGuild)]
public async Task helpConfig(string configFlag = null, string value = null)
{
var sb = new StringBuilder();
var embed = new EmbedBuilder();
embed.WithColor(new Color(255, 255, 0));
embed.Title = $"Configuration Management Help";
sb.AppendLine();
sb.AppendLine($"{_prefix}config <configFlag> <value>");
/*
* Add the string to the Embed
*/
embed.Description = sb.ToString();
/*
* Reply with the Embed created above
*/
await ReplyAsync(null, false, embed.Build());
}
}
}