Exemplo n.º 1
0
    /// <summary>
    /// Removes the given character's bodypart.
    /// </summary>
    /// <param name="invokingUser">The user that's performing the action.</param>
    /// <param name="character">The character to shift.</param>
    /// <param name="bodyPart">The bodypart to remove.</param>
    /// <param name="chirality">The chirality of the bodypart.</param>
    /// <param name="ct">The cancellation token in use.</param>
    /// <returns>A shifting result which may or may not have succeeded.</returns>
    public async Task <Result <ShiftBodypartResult> > RemoveBodypartPatternAsync
    (
        Snowflake invokingUser,
        Character character,
        Bodypart bodyPart,
        Chirality chirality  = Chirality.Center,
        CancellationToken ct = default
    )
    {
        var canTransformResult = await CanUserTransformUserAsync
                                 (
            character.Server.DiscordID,
            invokingUser,
            character.Owner.DiscordID,
            ct
                                 );

        if (!canTransformResult.IsSuccess)
        {
            return(Result <ShiftBodypartResult> .FromError(canTransformResult));
        }

        var getAppearanceResult = await GetOrCreateCurrentAppearanceAsync(character, ct);

        if (!getAppearanceResult.IsSuccess)
        {
            return(Result <ShiftBodypartResult> .FromError(getAppearanceResult));
        }

        var appearance = getAppearanceResult.Entity;

        var patternRemover = new PatternRemover(appearance, _descriptionBuilder);
        var shiftResult    = await patternRemover.RemoveAsync(bodyPart, chirality);

        if (shiftResult.IsSuccess)
        {
            await _database.SaveChangesAsync(ct);
        }

        return(shiftResult);
    }
Exemplo n.º 2
0
        /// <summary>
        /// Removes the given character's bodypart.
        /// </summary>
        /// <param name="context">The context of the command.</param>
        /// <param name="character">The character to shift.</param>
        /// <param name="bodyPart">The bodypart to remove.</param>
        /// <param name="chirality">The chirality of the bodypart.</param>
        /// <returns>A shifting result which may or may not have succeeded.</returns>
        public async Task <ShiftBodypartResult> RemoveBodypartPatternAsync
        (
            ICommandContext context,
            Character character,
            Bodypart bodyPart,
            Chirality chirality = Chirality.Center
        )
        {
            var discordUser = await context.Guild.GetUserAsync((ulong)character.Owner.DiscordID);

            var canTransformResult = await CanUserTransformUserAsync(context.Guild, context.User, discordUser);

            if (!canTransformResult.IsSuccess)
            {
                return(ShiftBodypartResult.FromError(canTransformResult));
            }

            var getAppearanceResult = await GetOrCreateCurrentAppearanceAsync(character);

            if (!getAppearanceResult.IsSuccess)
            {
                return(ShiftBodypartResult.FromError(getAppearanceResult));
            }

            var appearance = getAppearanceResult.Entity;

            var patternRemover = new PatternRemover(appearance, _descriptionBuilder);
            var shiftResult    = await patternRemover.RemoveAsync(bodyPart, chirality);

            if (shiftResult.IsSuccess)
            {
                await _database.SaveChangesAsync();
            }

            return(shiftResult);
        }