public static async Task <Embed> ChangePrefix(SocketCommandContext context, string newPrefix) { //If prefix lenght is more than 5 chars long if (newPrefix.Length > 5) { return(await EmbedHandler.CreateErrorEmbed("Configuration Error.", $"The prefix is to long. Must be 5 characters or less.")); } //Get Guild Config var config = GuildConfigFunctions.GetGuildConfig(context.Guild, _connection); //Get Guild Prefix from Config string oldPrefix = config.prefix; //If the Selected Prefix is already the Prefix if (oldPrefix == newPrefix) { return(await EmbedHandler.CreateErrorEmbed("Configuration Error.", $"\"{newPrefix}\" is already the prefix.")); } //Update Config GuildConfigFunctions.UpdateGuildConfig(context.Guild, "prefix", newPrefix, _connection); return(await EmbedHandler.CreateBasicEmbed("Configuration Changed.", $"The prefix was successfully changed to \"{newPrefix}\".")); }
private async Task CommandExecutedAsync(Optional <CommandInfo> command, ICommandContext context, IResult result) { //If Execution was successfull - return if (result.IsSuccess) { return; } //If an Error Occurs send to Discord if (!command.IsSpecified || !result.IsSuccess) { #if DEBUG LoggingService.Log("CommandExecution", $"{context.Message.Author.Username} => {context.Message} => {result.ErrorReason}", ConsoleColor.Red); #endif await context.Channel.SendMessageAsync(embed : await EmbedHandler.CreateErrorEmbed("Error.", result.ErrorReason)); } }
public static async Task <Embed> WhiteList(SocketCommandContext context, string arg, IChannel channel) { //Check if channel is specified ONLY when arg isnt list if (arg != "list") { //If no channel is specified if (channel is null) { return(await EmbedHandler.CreateErrorEmbed("Configuration Error.", $"No channel specified.")); } //Checks if the selected channel is text channel if (context.Guild.GetChannel(channel.Id) != context.Guild.GetTextChannel(channel.Id)) { return(await EmbedHandler.CreateErrorEmbed("Configuration Error.", $"{context.Guild.GetChannel(channel.Id)} is not a text channel.")); } } //Get Guild Config var guildConfig = GuildConfigFunctions.GetGuildConfig(context.Guild, _connection); //Get Whitelisted Channel List <ulong> whitelistedChannels = Array.ConvertAll(guildConfig.whitelistedChannel.Split(';'), ulong.Parse).ToList(); switch (arg) { #region Add Channel to Whitelist case "add": //Limits the whitelisted channels to 5 int limit = 5; if (whitelistedChannels.Count > limit) { return(await EmbedHandler.CreateErrorEmbed("Configuration Error.", $"You have reached the maximum of {limit} whitelisted channels.")); } //Check If the channel is already whitelisted foreach (ulong item in whitelistedChannels) { if (item == channel.Id) { return(await EmbedHandler.CreateErrorEmbed("Configuration Error.", $"{context.Guild.GetChannel(item)} is already whitelisted!")); } } //Add Channel to Whitelist whitelistedChannels.Add(channel.Id); //Update Config GuildConfigFunctions.UpdateGuildConfig(context.Guild, "whitelistedChannel", $"{string.Join(';', whitelistedChannels)}", _connection); return(await EmbedHandler.CreateBasicEmbed("Configuration Changed.", $"{context.Guild.GetChannel(channel.Id)} was whitelisted.")); #endregion #region Remove Channel from Whitelist case "remove": if (whitelistedChannels.Count == 1) { return(await EmbedHandler.CreateErrorEmbed("Configuration Error.", $"You can't have less than 1 whitelisted channel.")); } bool notFound = true; foreach (ulong item in whitelistedChannels) { if (item == channel.Id) { notFound = false; break; } } //If the Channel is not Whitelisted if (notFound) { return(await EmbedHandler.CreateErrorEmbed("Configuration Error.", $"{context.Guild.GetChannel(channel.Id)} is not whitelisted.")); } //Remove Channel from Whitelist whitelistedChannels.Remove(channel.Id); //Update Config GuildConfigFunctions.UpdateGuildConfig(context.Guild, "whitelistedChannel", $"{string.Join(';', whitelistedChannels)}", _connection); return(await EmbedHandler.CreateBasicEmbed("Configuration Changed.", $"{context.Guild.GetChannel(channel.Id)} was removed from the whitelist.")); #endregion #region List Whitelisted Channels case "list": StringBuilder builder = new StringBuilder(); builder.Append("**Whitelisted channels:**\n"); for (int i = 0; i < whitelistedChannels.Count; i++) { var whitelistedChannel = context.Guild.GetChannel(whitelistedChannels[i]); builder.Append($"{i + 1}. {whitelistedChannel.Name} (ID: {whitelistedChannel.Id})\n"); } return(await EmbedHandler.CreateBasicEmbed("Whitelist, List", $"{builder}")); #endregion default: return(await EmbedHandler.CreateErrorEmbed("Configuration Error.", $"{arg} is not a valid argument.")); } }