Ejemplo n.º 1
0
        private async Task ConsumePreferenceInteractionAsync(SocketReaction reaction)
        {
            var emote = reaction.Emote;

            if (emote.Equals(Back))
            {
                _state = KinkWizardState.CategorySelection;
                await UpdateAsync();

                return;
            }

            KinkPreference?preference = null;

            if (emote.Equals(Fave))
            {
                preference = KinkPreference.Favourite;
            }

            if (emote.Equals(Like))
            {
                preference = KinkPreference.Like;
            }

            if (emote.Equals(Maybe))
            {
                preference = KinkPreference.Maybe;
            }

            if (emote.Equals(Never))
            {
                preference = KinkPreference.No;
            }

            if (emote.Equals(NoPreference))
            {
                preference = KinkPreference.NoPreference;
            }

            if (!(preference is null))
            {
                await SetCurrentKinkPreference(preference.Value);

                var getNextKinkResult = await _kinks.GetNextKinkByCurrentFListIDAsync(_currentFListKinkID);

                if (!getNextKinkResult.IsSuccess)
                {
                    _currentFListKinkID = -1;
                    _state = KinkWizardState.CategorySelection;
                    await _feedback.SendConfirmationAndDeleteAsync(this.MessageContext, "All done in that category!");
                }
                else
                {
                    _currentFListKinkID = (int)getNextKinkResult.Entity.FListID;
                }

                await UpdateAsync();
            }
        }
Ejemplo n.º 2
0
        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();
        }