private async Task ConsumeCategoryInteractionAsync(SocketReaction reaction) { if (this.Message is null || this.Channel is null) { return; } var emote = reaction.Emote; if (emote.Equals(Next)) { if (_currentCategoryOffset + 3 >= _categories.Count) { return; } _currentCategoryOffset += 3; } else if (emote.Equals(Previous)) { if (_currentCategoryOffset - 3 < 0) { _currentCategoryOffset = 0; return; } _currentCategoryOffset -= 3; } else if (emote.Equals(First)) { if (_currentCategoryOffset == 0) { return; } _currentCategoryOffset = 0; } else if (emote.Equals(Last)) { int newOffset; if (_categories.Count % 3 == 0) { newOffset = _categories.Count - 3; } else { newOffset = _categories.Count - (_categories.Count % 3); } if (newOffset <= _currentCategoryOffset) { return; } _currentCategoryOffset = newOffset; } else if (emote.Equals(EnterCategory)) { bool Filter(IUserMessage m) => m.Author.Id == reaction.UserId; if (!_categories.Any()) { await _feedback.SendWarningAndDeleteAsync ( this.MessageContext, "There aren't any categories in the database.", TimeSpan.FromSeconds(10) ); return; } await _feedback.SendConfirmationAndDeleteAsync ( this.MessageContext, "Please enter a category name.", TimeSpan.FromSeconds(45) ); var messageResult = await this.Interactivity.GetNextMessageAsync ( this.Channel, Filter, TimeSpan.FromSeconds(45) ); if (messageResult.IsSuccess) { var tryStartCategoryResult = await OpenCategory(messageResult.Entity.Content); if (!tryStartCategoryResult.IsSuccess) { await _feedback.SendWarningAndDeleteAsync ( this.MessageContext, tryStartCategoryResult.ErrorReason, TimeSpan.FromSeconds(10) ); return; } } } await UpdateAsync(); }
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(); }