Update tell-joke.ps1

This commit is contained in:
Markus Fleschutz 2023-08-09 17:14:17 +02:00
parent af5c1d2351
commit 937739e4a1

View File

@ -4,7 +4,8 @@
.DESCRIPTION
This PowerShell script selects a random Chuck Norris joke in Data/jokes.csv and speaks it by text-to-speech (TTS).
.EXAMPLE
PS> ./tell-joke
PS> ./tell-joke.ps1
(listen and enjoy)
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -12,13 +13,12 @@
#>
try {
$Table = Import-CSV "$PSScriptRoot/../Data/jokes.csv"
$table = Import-CSV "$PSScriptRoot/../Data/jokes.csv"
$Generator = New-Object System.Random
$Index = [int]$Generator.next(0, $Table.Count - 1)
$Reply = $Table[$Index].Joke
$randomNumberGenerator = New-Object System.Random
$row = [int]$randomNumberGenerator.next(0, $table.count - 1)
& "$PSScriptRoot/speak-english.ps1" "$Reply"
& "$PSScriptRoot/speak-english.ps1" $table[$row].Joke
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"