Exemplo n.º 1
0
    /// <summary>
    /// Deletes the given character.
    /// </summary>
    /// <param name="guildID">The ID of the guild the user is on.</param>
    /// <param name="userID">The ID of the discord user.</param>
    /// <param name="character">The character to delete.</param>
    /// <param name="ct">The cancellation token in use.</param>
    /// <returns>A deletion result which may or may not have succeeded.</returns>
    public async Task <Result> DeleteCharacterAsync
    (
        Snowflake guildID,
        Snowflake userID,
        Character character,
        CancellationToken ct = default
    )
    {
        var getCurrentCharacter = await _characters.GetCurrentCharacterAsync(character.Owner, character.Server, ct);

        if (getCurrentCharacter.IsSuccess)
        {
            // Forcibly load the role so we can access it later
            _ = getCurrentCharacter.Entity.Role;
        }

        var deleteCharacter = await _characters.DeleteCharacterAsync(character, ct);

        if (!deleteCharacter.IsSuccess)
        {
            return(deleteCharacter);
        }

        if (!getCurrentCharacter.IsSuccess)
        {
            return(Result.FromSuccess());
        }

        var currentCharacter = getCurrentCharacter.Entity;

        if (currentCharacter != character)
        {
            return(Result.FromSuccess());
        }

        // Update the user's nickname
        var updateNickname = await UpdateUserNickname(guildID, userID, ct);

        if (!updateNickname.IsSuccess)
        {
            return(updateNickname);
        }

        return(await _characterRoles.UpdateUserRolesAsync(guildID, userID, getCurrentCharacter.Entity, ct));
    }