/// <summary> /// Attempts to open the information page for the given module in the wizard. /// </summary> /// <param name="moduleName">The name of the module.</param> /// <returns>A execution result which may or may not have succeeded.</returns> public Task <ModifyEntityResult> OpenModule(string moduleName) { var moduleSearchTerms = _modules.Select ( m => new List <string>(m.Aliases) { m.Name } ) .SelectMany(t => t); var getModuleResult = moduleSearchTerms.BestLevenshteinMatch(moduleName, 0.75); if (!getModuleResult.IsSuccess) { return(Task.FromResult(ModifyEntityResult.FromError(getModuleResult))); } var bestMatch = getModuleResult.Entity; var module = _modules.First(m => m.Name == bestMatch || m.Aliases.Contains(bestMatch)); if (!_commandListPages.ContainsKey(module)) { var commandPages = BuildCommandListPages(module); _commandListPages.Add(module, commandPages); } _commandListOffset = 0; _currentModule = module; _state = HelpWizardState.CommandListing; return(Task.FromResult(ModifyEntityResult.FromSuccess())); }
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(); }