public async Task Handle(IMessage message) { if (!IsUserAdmin(message)) { await message.Channel.SendMessageAsync("Only admins can use this command.", messageReference : new MessageReference(message.Id)); return; } var parameters = message.Content.Split(" "); if (parameters.Length == 1) { await SendMessage(message, $"Parameter not received. Type `{DiscordBotCommands.RemoveWhiteList}` <word> to remove a Whitelist word.", DiscordBotCommands.RemoveWhiteList); return; } var channelConfig = await _channelConfigService.GetConfigurationByChannelId(message.Channel.Id); var word = parameters[1].Trim(); if (!channelConfig.WhiteListWords.Contains(word, new CaseInsensitiveEqualityComparer())) { await SendMessage(message, $"The word '{word}' is not in the WhiteList.", DiscordBotCommands.RemoveWhiteList); return; } channelConfig.WhiteListWords.RemoveAll(v => v.Equals(word, StringComparison.OrdinalIgnoreCase)); await _channelConfigService.Update(channelConfig); await SendMessage(message, $"Word '{word}' removed from the WhiteList.", DiscordBotCommands.RemoveWhiteList); }
public async Task Handle(IMessage message) { var channelConfig = await _channelConfigService.GetConfigurationByChannelId(message.Channel.Id); var messageBuilder = new StringBuilder(); messageBuilder.AppendLine("Algorithms:"); messageBuilder.AppendLine(GetAvailableOptions(channelConfig.GrammarAlgorithm)); messageBuilder.AppendLine("Languages:"); messageBuilder.AppendLine(GetAvailableOptions(channelConfig.SelectedLanguage)); var showCorrectionDetailsIcon = channelConfig.HideCorrectionDetails ? "❌" : "✅"; messageBuilder.AppendLine($"Show correction details {showCorrectionDetailsIcon}").AppendLine(); messageBuilder.AppendLine("Strictness level:").AppendLine($"{channelConfig.CorrectionStrictnessLevel.GetDescription()} ✅").AppendLine(); messageBuilder.AppendLine($"Whitelist Words:").AppendLine($"Type `{DiscordBotCommands.WhiteList}` to see Whitelist words configured.").AppendLine(); if (channelConfig.IsBotStopped) { messageBuilder.AppendLine($"The bot is currently stopped. Type `{DiscordBotCommands.Start}` to activate the Bot."); } await SendMessage(message, messageBuilder.ToString(), DiscordBotCommands.Settings); }
public async Task Handle(IMessage message) { if (!IsUserAdmin(message)) { await message.Channel.SendMessageAsync("Only admins can use this command.", messageReference : new MessageReference(message.Id)); return; } var parameters = message.Content.Split(" "); if (parameters.Length == 1) { await SendMessage(message, $"Parameter not received. Type `{DiscordBotCommands.AddWhiteList}` <word> to add a Whitelist word.", DiscordBotCommands.AddWhiteList); return; } var channelConfig = await _channelConfigService.GetConfigurationByChannelId(message.Channel.Id); var word = parameters[1].Trim(); if (channelConfig.WhiteListWords.Contains(word, new CaseInsensitiveEqualityComparer())) { await SendMessage(message, $"The word '{word}' is already on the WhiteList", DiscordBotCommands.AddWhiteList); return; } channelConfig.WhiteListWords.Add(word); await _channelConfigService.Update(channelConfig); await SendMessage(message, $"Word '{word}' added to the WhiteList.", DiscordBotCommands.AddWhiteList); }
public async Task Handle(IMessage message) { var channelConfig = await _channelConfigService.GetConfigurationByChannelId(message.Channel.Id); var messageBuilder = new StringBuilder(); if (channelConfig.IsBotStopped) { if (!IsUserAdmin(message)) { messageBuilder.AppendLine("Only admins can use this command."); } else { channelConfig.IsBotStopped = false; await _channelConfigService.Update(channelConfig); messageBuilder.AppendLine("Bot started"); } } else { messageBuilder.AppendLine("Bot is already started"); } await SendMessage(message, messageBuilder.ToString(), DiscordBotCommands.Start); }
public async Task Handle(IMessage message) { var messageBuilder = new StringBuilder(); if (!IsUserAdmin(message)) { messageBuilder.AppendLine("Only admins can use this command."); await message.Channel.SendMessageAsync(messageBuilder.ToString(), messageReference : new MessageReference(message.Id)); return; } var parameters = message.Content.Split(" "); if (parameters.Length == 1) { var channelConfig = await _channelConfigService.GetConfigurationByChannelId(message.Channel.Id); messageBuilder.AppendLine($"Parameter not received. Type `{DiscordBotCommands.Language}` <language_number> to set a language.").AppendLine(); messageBuilder.AppendLine("Languages:"); messageBuilder.AppendLine(GetAvailableOptions(channelConfig.SelectedLanguage)); await SendMessage(message, messageBuilder.ToString(), DiscordBotCommands.Language); return; } bool parsedOk = int.TryParse(parameters[1], out int language); if (parsedOk && language.IsAssignableToEnum <SupportedLanguages>()) { var channelConfig = await _channelConfigService.GetConfigurationByChannelId(message.Channel.Id); channelConfig.SelectedLanguage = (SupportedLanguages)language; await _channelConfigService.Update(channelConfig); await SendMessage(message, $"Language updated: {channelConfig.SelectedLanguage.GetDescription()}", DiscordBotCommands.Language); return; } await SendMessage(message, $"Invalid parameter. Type `{DiscordBotCommands.Language}` <language_number> to set a language.", DiscordBotCommands.Language); }
public async Task Handle(IMessage message) { var messageBuilder = new StringBuilder(); if (!IsUserAdmin(message)) { messageBuilder.AppendLine("Only admins can use this command."); await message.Channel.SendMessageAsync(messageBuilder.ToString(), messageReference : new MessageReference(message.Id)); return; } var parameters = message.Content.Split(" "); if (parameters.Length == 1) { var channelConfig = await _channelConfigService.GetConfigurationByChannelId(message.Channel.Id); messageBuilder.AppendLine($"Parameter not received. Type `{DiscordBotCommands.SetAlgorithm}` <algorithm_numer> to set an algorithm").AppendLine(); messageBuilder.AppendLine($"Algorithms:"); messageBuilder.AppendLine(GetAvailableOptions(channelConfig.GrammarAlgorithm)); await SendMessage(message, messageBuilder.ToString(), DiscordBotCommands.SetAlgorithm); return; } bool parsedOk = int.TryParse(parameters[1], out int algorithm); if (parsedOk && algorithm.IsAssignableToEnum <GrammarAlgorithms>()) { var channelConfig = await _channelConfigService.GetConfigurationByChannelId(message.Channel.Id); channelConfig.GrammarAlgorithm = (GrammarAlgorithms)algorithm; await _channelConfigService.Update(channelConfig); await SendMessage(message, $"Algorithm updated: {channelConfig.GrammarAlgorithm.GetDescription()}", DiscordBotCommands.SetAlgorithm); return; } await SendMessage(message, $"Invalid parameter. Type `{DiscordBotCommands.SetAlgorithm}` <algorithm_numer> to set an algorithm.", DiscordBotCommands.SetAlgorithm); }
public async Task Handle(IMessage message) { if (!IsUserAdmin(message)) { await message.Channel.SendMessageAsync("Only admins can use this command.", messageReference : new MessageReference(message.Id)); return; } var channelConfig = await _channelConfigService.GetConfigurationByChannelId(message.Channel.Id); channelConfig.IsBotStopped = true; await _channelConfigService.Update(channelConfig); await SendMessage(message, "Bot stopped", DiscordBotCommands.Stop); }
public async Task Handle(IMessage message) { if (!IsUserAdmin(message)) { await message.Channel.SendMessageAsync("Only admins can use this command.", messageReference : new MessageReference(message.Id)); return; } var channelConfig = await _channelConfigService.GetConfigurationByChannelId(message.Channel.Id); channelConfig.CorrectionStrictnessLevel = CorrectionStrictnessLevels.Tolerant; await _channelConfigService.Update(channelConfig); await SendMessage(message, "Tolerant ✅", DiscordBotCommands.Tolerant); }
public async Task Handle(IMessage message) { if (!IsUserAdmin(message)) { await message.Channel.SendMessageAsync("Only admins can use this command.", messageReference : new MessageReference(message.Id)); return; } var channelConfig = await _channelConfigService.GetConfigurationByChannelId(message.Channel.Id); channelConfig.HideCorrectionDetails = false; await _channelConfigService.Update(channelConfig); await SendMessage(message, "Show correction details ✅", DiscordBotCommands.ShowDetails); }
public async Task Handle(IMessage message) { var channelConfig = await _channelConfigService.GetConfigurationByChannelId(message.Channel.Id); if (channelConfig.WhiteListWords?.Any() != true) { await SendMessage(message, $"You don't have Whitelist words configured. Use `{DiscordBotCommands.AddWhiteList}` to add words to the WhiteList.", DiscordBotCommands.WhiteList); return; } var messageBuilder = new StringBuilder(); messageBuilder.AppendLine("Whitelist Words:\n"); foreach (var word in channelConfig.WhiteListWords) { messageBuilder.AppendLine($"- {word}"); } await SendMessage(message, messageBuilder.ToString(), DiscordBotCommands.WhiteList); }