PowerShell/Scripts/tell-joke.ps1
2021-12-06 18:48:32 +01:00

27 lines
659 B
PowerShell
Executable File

<#
.SYNOPSIS
Tells a joke by text-to-speech
.DESCRIPTION
This script selects a random Chuck Norris joke in Data/jokes.csv and speaks it by text-to-speech (TTS).
.EXAMPLE
PS> ./tell-joke
.NOTES
Author: Markus Fleschutz · License: CC0
.LINK
https://github.com/fleschutz/PowerShell
#>
try {
$Table = import-csv "$PSScriptRoot/../Data/jokes.csv"
$Generator = New-Object System.Random
$Index = [int]$Generator.next(0, $Table.Count - 1)
$Reply = $Table[$Index].Joke
& "$PSScriptRoot/give-reply.ps1" "$Reply"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
exit 1
}