mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-11-22 16:03:22 +01:00
Update tell-joke.ps1
This commit is contained in:
parent
af5c1d2351
commit
937739e4a1
@ -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])"
|
||||
|
Loading…
Reference in New Issue
Block a user