public async Task <Result> RunKinkWizardAsync()
    {
        var categories = await _kinks.GetKinkCategoriesAsync(this.CancellationToken);

        var initialWizard = new KinkWizard
                            (
            _context.User.ID,
            categories.ToList(),
            _context is InteractionContext
                            );

        var getInitialEmbed = await initialWizard.GetCurrentPageAsync(_kinks, this.CancellationToken);

        if (!getInitialEmbed.IsDefined(out var initialEmbed))
        {
            return((Result)getInitialEmbed);
        }

        var initialComponents = initialWizard.GetCurrentPageComponents();

        var send = await _feedback.SendContextualEmbedAsync
                   (
            initialEmbed,
            new FeedbackMessageOptions(MessageComponents : new(initialComponents)),
            ct : this.CancellationToken
                   );

        if (!send.IsSuccess)
        {
            return((Result)send);
        }

        var messageID = send.Entity.ID;

        return(_dataService.TryAddData(messageID, initialWizard)
            ? Result.FromSuccess()
            : new InvalidOperationError("Failed to add the in-memory data for the kink wizard. Bug?"));
    }
Beispiel #2
0
    /// <summary>
    /// Updates the contents of the wizard.
    /// </summary>
    /// <param name="data">The wizard's state.</param>
    /// <returns>A result which may or may not have succeeded.</returns>
    private async Task <Result> UpdateAsync
    (
        KinkWizard data
    )
    {
        var getPage = await data.GetCurrentPageAsync(_kinks, this.CancellationToken);

        if (!getPage.IsSuccess)
        {
            return(Result.FromError(getPage));
        }

        var page = getPage.Entity;

        if (data.WasCreatedWithInteraction)
        {
            return((Result)await _interactionAPI.EditOriginalInteractionResponseAsync
                   (
                       _context.ApplicationID,
                       _context.Token,
                       embeds : new[] { page },
                       components : new Optional <IReadOnlyList <IMessageComponent>?>(data.GetCurrentPageComponents()),
                       ct : this.CancellationToken
                   ));
        }

        var message = _context.Message.Value;

        return((Result)await _channelAPI.EditMessageAsync
               (
                   message.ChannelID,
                   message.ID,
                   embeds : new[] { page },
                   components : new Optional <IReadOnlyList <IMessageComponent>?>(data.GetCurrentPageComponents()),
                   ct : this.CancellationToken
               ));
    }