mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-05-31 07:26:06 +02:00
Update tell-joke.ps1
This commit is contained in:
parent
af5c1d2351
commit
937739e4a1
@ -4,7 +4,8 @@
|
|||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This PowerShell script selects a random Chuck Norris joke in Data/jokes.csv and speaks it by text-to-speech (TTS).
|
This PowerShell script selects a random Chuck Norris joke in Data/jokes.csv and speaks it by text-to-speech (TTS).
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./tell-joke
|
PS> ./tell-joke.ps1
|
||||||
|
(listen and enjoy)
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
.NOTES
|
.NOTES
|
||||||
@ -12,13 +13,12 @@
|
|||||||
#>
|
#>
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$Table = Import-CSV "$PSScriptRoot/../Data/jokes.csv"
|
$table = Import-CSV "$PSScriptRoot/../Data/jokes.csv"
|
||||||
|
|
||||||
$Generator = New-Object System.Random
|
$randomNumberGenerator = New-Object System.Random
|
||||||
$Index = [int]$Generator.next(0, $Table.Count - 1)
|
$row = [int]$randomNumberGenerator.next(0, $table.count - 1)
|
||||||
$Reply = $Table[$Index].Joke
|
|
||||||
|
|
||||||
& "$PSScriptRoot/speak-english.ps1" "$Reply"
|
& "$PSScriptRoot/speak-english.ps1" $table[$row].Joke
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user