public async Task HelpAsync([CanBeNull, Remainder] string searchText) { searchText = searchText.Unquote(); var topLevelModules = _commands.Modules.Where(m => !m.IsSubmodule).ToList(); var moduleSearchTerms = _commands.Modules.Select ( m => new List <string>(m.Aliases) { m.Name } ) .SelectMany(t => t); var getModuleAliasResult = moduleSearchTerms.BestLevenshteinMatch(searchText, 0.5); if (getModuleAliasResult.IsSuccess) { var module = _commands.Modules.First(m => m.Aliases.Contains(getModuleAliasResult.Entity)); if (module.IsSubmodule) { module = module.GetTopLevelModule(); } var helpWizard = new HelpWizard(topLevelModules, _feedback, _help, this.Context.User); await helpWizard.OpenModule(module.Name); await _interactive.SendPrivateInteractiveMessageAndDeleteAsync ( this.Context, _feedback, helpWizard, TimeSpan.FromMinutes(30) ); return; } var commandSearchTerms = topLevelModules.SelectMany(m => m.GetAllCommands().SelectMany(c => c.Aliases)); var findCommandResult = commandSearchTerms.BestLevenshteinMatch(searchText, 0.5); if (findCommandResult.IsSuccess) { var foundAlias = findCommandResult.Entity; var commandGroup = topLevelModules .Select(m => m.GetAllCommands().Where(c => c.Aliases.Contains(findCommandResult.Entity))) .First(l => l.Any()) .Where(c => c.Aliases.Contains(foundAlias)) .GroupBy(c => c.Aliases.OrderByDescending(a => a).First()) .First(); var eb = _help.CreateDetailedCommandInfoEmbed(commandGroup); await _feedback.SendPrivateEmbedAsync(this.Context, this.Context.User, eb.Build()); } }
private async Task ConsumeCommandListInteractionAsync([NotNull] SocketReaction reaction) { var emote = reaction.Emote; if (!this.AcceptedEmotes.Contains(emote)) { return; } if (emote.Equals(Back)) { _state = HelpWizardState.ModuleListing; await UpdateAsync(); return; } if (emote.Equals(Next)) { // ReSharper disable once AssignNullToNotNullAttribute if (_commandListOffset + 1 > _commandListPages[_currentModule].Count - 1) { return; } _commandListOffset++; } else if (emote.Equals(Previous)) { if (_commandListOffset - 1 < 0) { return; } _commandListOffset--; } else if (emote.Equals(First)) { _commandListOffset = 0; } else if (emote.Equals(Last)) { // ReSharper disable once AssignNullToNotNullAttribute _commandListOffset = _commandListPages[_currentModule].Count - 1; } else if (emote.Equals(EnterModule)) { bool Filter(IUserMessage m) => m.Author.Id == reaction.UserId; // ReSharper disable once PossibleNullReferenceException if (!_currentModule.Commands.Any()) { await _feedback.SendWarningAndDeleteAsync ( this.MessageContext, "There aren't any commands available in the module.", TimeSpan.FromSeconds(10) ); return; } await _feedback.SendConfirmationAndDeleteAsync ( this.MessageContext, "Please enter a command name.", TimeSpan.FromSeconds(45) ); var messageResult = await this.Interactivity.GetNextMessageAsync ( this.Channel, Filter, TimeSpan.FromSeconds(45) ); if (messageResult.IsSuccess) { var searchText = messageResult.Entity.Content; var commandSearchTerms = _currentModule .GetAllCommands() .Select(c => c.GetFullCommand()); var findCommandResult = commandSearchTerms.BestLevenshteinMatch(searchText, 0.5); if (findCommandResult.IsSuccess) { var foundName = findCommandResult.Entity; var commandGroup = _currentModule.Commands .Where(c => c.GetFullCommand() == foundName) .GroupBy(c => c.Aliases.OrderByDescending(a => a).First()) .First(); var eb = _help.CreateDetailedCommandInfoEmbed(commandGroup); await _feedback.SendEmbedAndDeleteAsync ( this.Channel, eb.Build(), TimeSpan.FromSeconds(45) ); } else { var eb = _feedback.CreateEmbedBase(Color.Orange); eb.WithDescription("I couldn't find a sufficiently close command to that."); await _feedback.SendEmbedAndDeleteAsync ( this.Channel, eb.Build() ); } } } await UpdateAsync(); }