コード例 #1
0
        private async Task DisplayHelpTextAsync()
        {
            if (this.Message is null || this.Channel is null)
            {
                return;
            }

            var eb = new EmbedBuilder();

            eb.WithColor(Color.DarkPurple);

            switch (_state)
            {
            case KinkWizardState.CategorySelection:
            {
                eb.WithTitle("Help: Category selection");
                eb.AddField
                (
                    "Usage",
                    "Use the navigation buttons to scroll through the available categories. Select a category by " +
                    $"pressing {EnterCategory} and typing in the name. The search algorithm is quite lenient, so " +
                    "you may find that things work fine even with typos.\n" +
                    "\n" +
                    $"You can quit at any point by pressing {Exit}."
                );
                break;
            }

            case KinkWizardState.KinkPreference:
            {
                eb.WithTitle("Help: Kink preference");
                eb.AddField
                (
                    "Usage",
                    "Set your preference for this kink by pressing one of the following buttons:" +
                    $"\n{Fave} : Favourite" +
                    $"\n{Like} : Like" +
                    $"\n{Maybe} : Maybe" +
                    $"\n{Never} : Never" +
                    $"\n{NoPreference} : No preference\n" +
                    "\n" +
                    $"\nPress {Back} to go back to the categories." +
                    $"\nYou can quit at any point by pressing {Exit}."
                );
                break;
            }

            default:
            {
                throw new ArgumentOutOfRangeException();
            }
            }

            await _feedback.SendEmbedAndDeleteAsync(this.Channel, eb.Build(), TimeSpan.FromSeconds(30));
        }
コード例 #2
0
        /// <summary>
        /// Sends a paginated message to the context user's direct messaging channel, alerting them if they are
        /// not already in it, and deletes it after a certain timeout. Defaults to 5 minutes.
        /// </summary>
        /// <param name="this">The interactive service.</param>
        /// <param name="context">The command context.</param>
        /// <param name="feedback">The feedback service to use.</param>
        /// <param name="message">The message to send.</param>
        /// <param name="timeout">The timeout after which the embed will be deleted. Defaults to 5 minutes.</param>
        /// <returns>The message that was sent.</returns>
        public static async Task SendPrivateInteractiveMessageAndDeleteAsync
        (
            [NotNull] this InteractivityService @this,
            [NotNull] ICommandContext context,
            [NotNull] UserFeedbackService feedback,
            [NotNull] InteractiveMessage message,
            [CanBeNull] TimeSpan?timeout = null
        )
        {
            timeout = timeout ?? TimeSpan.FromMinutes(5.0);

            var userChannel = await context.User.GetOrCreateDMChannelAsync();

            try
            {
                var eb = feedback.CreateFeedbackEmbed(context.User, Color.DarkPurple, "Loading...");
                await feedback.SendEmbedAndDeleteAsync(userChannel, eb, TimeSpan.FromSeconds(1));

                if (!(context.Channel is IDMChannel))
                {
                    await feedback.SendConfirmationAsync(context, "Please check your private messages.");
                }

                await @this.SendInteractiveMessageAndDeleteAsync(userChannel, message, timeout);
            }
            catch (HttpException hex)
            {
                if (hex.WasCausedByDMsNotAccepted())
                {
                    await feedback.SendWarningAsync
                    (
                        context,
                        "You don't accept DMs from non-friends on this server, so I'm unable to do that."
                    );
                }

                throw;
            }
        }
コード例 #3
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();
        }