Power-Ascii.psm1

$pathToArts = "$( $env:USERPROFILE )\arts";

function Update()
{
    Param()
    Read-Host "`n`n`n`nThis action requires internet connection... `n`nIf you don't have currently please press Ctrl + C `n`nOtherwise press ENTER to continue"

    Write-Output "Setting up..."
    $projectZip = "$( $env:USERPROFILE )\project.zip";
    $project = "$( $env:USERPROFILE )\project"
    $temporaryFolder = "$( $env:USERPROFILE )\project\Power-Ascii-master\*"
    $source = 'https://codeload.github.com/zozobalogh0817/Power-Ascii/zip/refs/heads/master';

    if (Test-Path -Path $pathToArts)
    {
        GetArt
        Read-Host "You already have arts! `nIf you would like to update them, press ENTER `nTo cancel update press Ctrl + C "
        Write-Output "Update already had art collection..."
        # Checking the user currently has the arts folder in the $env:USERPROFILE
        # what will point to the X:/Users/USERNAME (X could be any drive that the main SYSTEM Drive that used to be C)
        Remove-Item $pathToArts -Recurse -Force -Confirm:$false
    }

    Write-Output "Start writting the ascii arts..."
    Invoke-WebRequest -Uri $source -OutFile $projectZip

    Write-Output "Saving them to local sources..."
    Expand-Archive -Path $projectZip -DestinationPath $project
    Write-Host "Cleaning up the mess..."
    Remove-Item $projectZip
    Remove-Item $temporaryFolder -Exclude 'art'

    Write-Host "Moving to the right order..."
    Move-Item $temporaryFolder -Destination $pathToArts
    Remove-Item $project -Recurse -Force -Confirm:$false
    Write-Host "All arts has been saved to $( $pathToArts )"
    GetArt
    Write-Host "Have a nice day! `n -Z"
}

Export-ModuleMember -Function Update

function GetRandomArt()
{
    if (-Not(Test-Path -Path $pathToArts))
    {
        Update;
    }
    $arts = Get-ChildItem -Path $pathToArts;
    $number = Get-Random $arts.Length -Minimum 1;
    $art = Get-Content "$( $pathToArts )/$( $number ).txt";
    # The above written methodology will change soon
    return $art;
}

function GetArt()
{
    param([System.ConsoleColor]$color = [System.ConsoleColor]::White)
    $art = GetRandomArt
    $writeHostOptions = @{ ForegroundColor = $color }
    Write-Output $art, $writeHostOptions
}

Export-ModuleMember -Function GetArt