Add use of give-reply.ps1

This commit is contained in:
Markus Fleschutz 2021-12-06 17:00:49 +01:00
parent 589ba8e93c
commit 3a0cb4a001
38 changed files with 74 additions and 116 deletions

View File

@ -13,9 +13,8 @@
try {
$Rates = (Invoke-WebRequest -uri "https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=USD,EUR" -userAgent "curl" -useBasicParsing).Content | ConvertFrom-Json
$Reply = "Bitcoin is currently at $($Rates.USD) US$ and $($Rates.EUR) Euro."
"✔️ $Reply"
& "$PSScriptRoot/speak-english.ps1" "$Reply"
& "$PSScriptRoot/give-reply.ps1" "Bitcoin is currently at $($Rates.USD) US$ and $($Rates.EUR) Euro."
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"

View File

@ -15,9 +15,7 @@ try {
$Now = [DateTime]::Now
$Diff = [Datetime]("12/25/" + $Now.Year) $Now
$Reply = "Christmas is in $($Diff.Days) days."
"✔️ $Reply"
& "$PSScriptRoot/speak-english.ps1" "$Reply"
& "$PSScriptRoot/give-reply.ps1" "Christmas is in $($Diff.Days) days."
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"

View File

@ -33,8 +33,8 @@ try {
} else {
$Reply = "$($Temp)°C CPU temperature, that's too low!"
}
"✔️ $Reply"
& "$PSScriptRoot/speak-english.ps1" "$Reply"
& "$PSScriptRoot/give-reply.ps1" "$Reply"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"

View File

@ -16,9 +16,8 @@ try {
[system.threading.thread]::currentthread.currentculture=[system.globalization.cultureinfo]"en-US"
$Weekday = (Get-Date -format "dddd")
$CurrentDate = (Get-Date).ToShortDateString()
$Reply = "It's $Weekday, $CurrentDate"
"✔️ $Reply"
& "$PSScriptRoot/speak-english.ps1" "$Reply"
& "$PSScriptRoot/give-reply.ps1" "It's $Weekday, $CurrentDate"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"

View File

@ -13,8 +13,8 @@
try {
$Reply = (Invoke-WebRequest http://wttr.in/?format="Dawn is at %D." -UserAgent "curl" -useBasicParsing).Content
"✔️ $Reply"
& "$PSScriptRoot/speak-english.ps1" "$Reply"
& "$PSScriptRoot/give-reply.ps1" "$Reply"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"

View File

@ -31,9 +31,8 @@ try {
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
$Average = [math]::round($Count / $Elapsed, 1)
$Reply = "$Average domains per second DNS resolution"
"✔️ $Reply"
& "$PSScriptRoot/speak-english.ps1" "$Reply"
& "$PSScriptRoot/give-reply.ps1" "$Average domains per second DNS resolution"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"

View File

@ -13,9 +13,8 @@
try {
$Rates = (Invoke-WebRequest -uri "https://min-api.cryptocompare.com/data/price?fsym=DOGE&tsyms=USD,EUR" -userAgent "curl" -useBasicParsing).Content | ConvertFrom-Json
$Reply = "Dogecoin is currently at $($Rates.USD) US$ and $($Rates.EUR) Euro."
"✔️ $Reply"
& "$PSScriptRoot/speak-english.ps1" "$Reply"
& "$PSScriptRoot/give-reply.ps1" "Dogecoin is currently at $($Rates.USD) US$ and $($Rates.EUR) Euro."
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"

View File

@ -30,7 +30,8 @@ try {
write-warning "Drive $Drive has only $Free GB left to use! ($Used of $Total GB used, minimum is $MinLevel GB)"
exit 1
}
"✔️ Drive $Drive has $Free GB left ($Total GB total)"
& "$PSScriptRoot/give-reply.ps1" "Drive $Drive has $Free GB left ($Total GB total)"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"

View File

@ -29,8 +29,7 @@ try {
} else {
$Reply = "Drive $($Drive.Name) has $($Free)GB left ($($Total)GB total)"
}
"✔️ $Reply"
& "$PSScriptRoot/speak-english.ps1" "$Reply"
& "$PSScriptRoot/give-reply.ps1" "$Reply"
}
exit 0 # success
} catch {

View File

@ -13,8 +13,8 @@
try {
$Reply = (Invoke-WebRequest http://wttr.in/?format="Dusk is at %d." -UserAgent "curl" -useBasicParsing).Content
"✔️ $Reply"
& "$PSScriptRoot/speak-english.ps1" "$Reply"
& "$PSScriptRoot/give-reply.ps1" "$Reply"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"

View File

@ -12,9 +12,7 @@
#>
try {
$Reply = "Earth still spins with 1040mph."
"✔️ $Reply"
& "$PSScriptRoot/speak-english.ps1" "$Reply"
& "$PSScriptRoot/speak-english.ps1" "Earth still spins with 1040mph."
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"

View File

@ -13,9 +13,8 @@
try {
$Rates = (Invoke-WebRequest -uri "https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD,EUR" -userAgent "curl" -useBasicParsing).Content | ConvertFrom-Json
$Reply = "Ethereum is currently at $($Rates.USD) US$ and $($Rates.EUR) Euro."
"✔️ $Reply"
& "$PSScriptRoot/speak-english.ps1" "$Reply"
& "$PSScriptRoot/give-reply.ps1" "Ethereum is currently at $($Rates.USD) US$ and $($Rates.EUR) Euro."
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"

View File

@ -24,7 +24,7 @@ try {
$Result = repair-volume -driveLetter $Drive -scan
if ($Result -ne "NoErrorsFound") { throw "'repair-volume' failed" }
"✔️ file system on drive $Drive is clean"
& "$PSScriptRoot/give-reply.ps1" "File system on drive $Drive is clean."
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"

View File

@ -21,8 +21,7 @@ try {
[xml]$Content = (invoke-webRequest -uri $RSS_URL -useBasicParsing).Content
[int]$Count = 0
foreach ($item in $Content.rss.channel.item) {
"$($item.title)"
& "$PSScriptRoot/speak-english.ps1" "$($item.title)"
& "$PSScriptRoot/give-reply.ps1" "$($item.title)"
$Count++
if ($Count -eq $MaxCount) { break }
}

View File

@ -14,9 +14,7 @@
try {
$ISS = (Invoke-WebRequest "http://api.open-notify.org/iss-now.json" -userAgent "curl" -useBasicParsing).Content | ConvertFrom-Json
$Reply = "ISS is at $($ISS.iss_position.longitude)° longitude, $($ISS.iss_position.latitude)° latitude."
"✔️ $Reply"
& "$PSScriptRoot/speak-english.ps1" "$Reply"
& "$PSScriptRoot/give-reply.ps1" "ISS is at $($ISS.iss_position.longitude)° longitude, $($ISS.iss_position.latitude)° latitude."
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"

View File

@ -35,8 +35,7 @@ try {
} else { $Reply += ", last new moon was $MoonAge days ago"
}
"✔️ $Reply"
& "$PSScriptRoot/speak-english.ps1" "$Reply"
& "$PSScriptRoot/give-reply.ps1" "$Reply"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"

View File

@ -11,12 +11,5 @@
https://github.com/fleschutz/PowerShell
#>
try {
$Reply = "OK, what's your account number?"
"✔️ $Reply"
& "$PSScriptRoot/speak-english.ps1" "$Reply"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
exit 1
}
& "$PSScriptRoot/give-reply.ps1" "OK, what's your account number?"
exit 0 # success

View File

@ -15,9 +15,7 @@ try {
$Now = [DateTime]::Now
$Diff = [Datetime]("12/31/" + $Now.Year) $Now
$Reply = "New Year is in $($Diff.Days) days."
"✔️ $Reply"
& "$PSScriptRoot/speak-english.ps1" "$Reply"
& "$PSScriptRoot/give-reply.ps1" "New Year is in $($Diff.Days) days."
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"

View File

@ -21,8 +21,7 @@ try {
$OSversion = $OS.Version
$Reply = "$OSname for $OSarchitecture version $OSversion"
}
"✔️ $Reply"
& "$PSScriptRoot/speak-english.ps1" "$Reply"
& "$PSScriptRoot/give-reply.ps1" "$Reply"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"

View File

@ -37,9 +37,7 @@ try {
}
$Avg = $Avg / $Pings.count
$Reply = "$($Avg)ms average ping time ($($Min)ms min, $($Max)ms max)"
"✔️ $Reply"
& "$PSScriptRoot/speak-english.ps1" "$Reply"
& "$PSScriptRoot/give-reply.ps1" "$($Avg)ms average ping time ($($Min)ms min, $($Max)ms max)"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"

View File

@ -13,8 +13,7 @@
try {
$Reply = (Invoke-WebRequest http://wttr.in/?format="Sunrise is at %S." -UserAgent "curl" -useBasicParsing).Content
"✔️ $Reply"
& "$PSScriptRoot/speak-english.ps1" "$Reply"
& "$PSScriptRoot/give-reply.ps1" "$Reply"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"

View File

@ -13,8 +13,7 @@
try {
$Reply = (Invoke-WebRequest http://wttr.in/?format="Sunset is at %s." -UserAgent "curl" -useBasicParsing).Content
"✔️ $Reply"
& "$PSScriptRoot/speak-english.ps1" "$Reply"
& "$PSScriptRoot/give-reply.ps1" "$Reply"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"

View File

@ -38,8 +38,7 @@ try {
} else {
$Reply = "Swap space has $Free GB left ($Total GB total)"
}
"✔️ $Reply"
& "$PSScriptRoot/speak-english.ps1" "$Reply"
& "$PSScriptRoot/give-reply.ps1" "$Reply"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"

View File

@ -13,9 +13,8 @@
try {
$TimeZone = (Get-Timezone)
$Reply = "It's $($TimeZone.DisplayName)"
"✔️ $Reply"
& "$PSScriptRoot/speak-english.ps1" "$Reply"
& "$PSScriptRoot/give-reply.ps1" "It's $($TimeZone.DisplayName)"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"

View File

@ -14,9 +14,8 @@
try {
[system.threading.thread]::currentThread.currentCulture=[system.globalization.cultureInfo]"en-US"
$CurrentTime = $((Get-Date).ToShortTimeString())
$Reply = "It's $CurrentTime"
"✔️ $Reply"
& "$PSScriptRoot/speak-english.ps1" "$Reply"
& "$PSScriptRoot/give-reply.ps1" "It's $CurrentTime"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"

View File

@ -41,8 +41,7 @@ try {
$Reply += "and $Minutes minutes"
}
$Reply += "."
"✔️ $Reply"
& "$PSScriptRoot/speak-english.ps1" "$Reply"
& "$PSScriptRoot/give-reply.ps1" "$Reply"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"

View File

@ -20,8 +20,7 @@ try {
}
if ("$Reply" -eq "") { $Reply = "No VPN connection available" }
"✔️ $Reply"
& "$PSScriptRoot/speak-english.ps1" "$Reply"
& "$PSScriptRoot/give-reply.ps1" "$Reply"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"

View File

@ -31,9 +31,7 @@ try {
$Area = $Weather.nearest_area.areaName.value
$Region = $Weather.nearest_area.region.value
$Reply = "$($Temp)°C, $($Precip)mm rain, $($Humidity)% humidity, $($WindSpeed)km/h wind from $WindDir with $($Clouds)% clouds and $($Visib)km visibility at $Area ($Region)."
"✔️ $Reply"
& "$PSScriptRoot/speak-english.ps1" "$Reply"
& "$PSScriptRoot/give-reply.ps1" "$($Temp)°C, $($Precip)mm rain, $($Humidity)% humidity, $($WindSpeed)km/h wind from $WindDir with $($Clouds)% clouds and $($Visib)km visibility at $Area ($Region)."
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"

View File

@ -13,8 +13,7 @@
try {
$Reply = (Invoke-WebRequest http://wttr.in/?format="Zenith is at %z." -UserAgent "curl" -useBasicParsing).Content
"✔️ $Reply"
& "$PSScriptRoot/speak-english.ps1" "$Reply"
& "$PSScriptRoot/give-reply.ps1" "$Reply"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"

View File

@ -2,7 +2,7 @@
.SYNOPSIS
Gives a reply
.DESCRIPTION
This script gives a reply in English by text-to-speech (TTS).
This script gives a reply in English on the console and by text-to-speech (TTS).
.PARAMETER text
Specifies the text to speak
.EXAMPLE
@ -16,16 +16,21 @@
param([string]$text = "")
try {
"📣$text"
# print reply on the console:
"$text"
# speak by text-to-speech (TTS):
$TTSVoice = New-Object -ComObject SAPI.SPVoice
foreach ($Voice in $TTSVoice.GetVoices()) {
if ($Voice.GetDescription() -like "*- English*") {
$TTSVoice.Voice = $Voice
[void]$TTSVoice.Speak($text)
exit 0 # success
break
}
}
# remember last reply:
"$text" > "$HOME/.last_reply.txt"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"

View File

@ -1,8 +1,8 @@
<#
.SYNOPSIS
Answers to 'good bye'
Replies to 'good bye'
.DESCRIPTION
This script says a reply to "good bye" by text-to-speech (TTS).
This script says a reply to 'good bye' by text-to-speech (TTS).
.EXAMPLE
PS> ./good-bye
.NOTES
@ -13,6 +13,5 @@
$Reply = "Good bye.", "See you.", "Bye bye." | Get-Random
"$Reply"
& "$PSScriptRoot/speak-english.ps1" "$Reply"
& "$PSScriptRoot/give-reply.ps1" "$Reply"
exit 0 # success

View File

@ -1,8 +1,8 @@
<#
.SYNOPSIS
Answers to 'good evening'
Replies to 'good evening'
.DESCRIPTION
This script says a reply to "good evening" by text-to-speech (TTS).
This script says a reply to 'good evening' by text-to-speech (TTS).
.EXAMPLE
PS> ./good-evening
.NOTES
@ -13,6 +13,5 @@
$Reply = "And a special good evening to you too."
"$Reply"
& "$PSScriptRoot/speak-english.ps1" "$Reply"
& "$PSScriptRoot/give-reply.ps1" "$Reply"
exit 0 # success

View File

@ -13,6 +13,5 @@
$Reply = "Good morning.", "Good morning to you too.", "Well, good morning to you too.", "Good morning! How are you?", "Morning." | Get-Random
"$Reply"
& "$PSScriptRoot/speak-english.ps1" "$Reply"
& "$PSScriptRoot/give-reply.ps1" "$Reply"
exit 0 # success

View File

@ -1,8 +1,8 @@
<#
.SYNOPSIS
Answers to 'good night'
Replies to 'good night'
.DESCRIPTION
This script says a reply to "good night" by text-to-speech (TTS).
This script says a reply to 'good night' by text-to-speech (TTS).
.EXAMPLE
PS> ./good-night
.NOTES
@ -13,6 +13,5 @@
$Reply = "Good night to you, too.", "Good night to you, my friend.", "Have a good night. Sleep well.", "Good night and sweet dreams." | Get-Random
"$Reply"
& "$PSScriptRoot/speak-english.ps1" "$Reply"
& "$PSScriptRoot/give-reply.ps1" "$Reply"
exit 0 # success

View File

@ -2,7 +2,7 @@
.SYNOPSIS
Replies to "Hi"
.DESCRIPTION
This script replies to "Hi" by text-to-speech (TTS).
This script replies to 'Hi' by text-to-speech (TTS).
.EXAMPLE
PS> ./hi
.NOTES
@ -11,12 +11,7 @@
https://github.com/fleschutz/PowerShell
#>
try {
$Reply = "Hello, how can I help?"
"✔️ $Reply"
& "$PSScriptRoot/speak-english.ps1" "$Reply"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
exit 1
}
$Reply = "Hello, how can I help?"
& "$PSScriptRoot/give-reply.ps1" "$Reply"
exit 0 # success

View File

@ -1,8 +1,8 @@
<#
.SYNOPSIS
Answers 'I'll be back'
Replies to 'I'll be back'
.DESCRIPTION
This script answers "I'll be back" by text-to-speech (TTS).
This script replies to "I'll be back" by text-to-speech (TTS).
.EXAMPLE
PS> ./i-will-be-back
.NOTES
@ -11,8 +11,7 @@
https://github.com/fleschutz/PowerShell
#>
$Answer = "Hasta la vista, baby."
$Reply = "Hasta la vista, baby."
& "$PSScriptRoot/speak-english.ps1" "$Answer"
write-output "$Answer"
& "$PSScriptRoot/give-reply.ps1" "$Reply"
exit 0 # success

View File

@ -1,8 +1,8 @@
<#
.SYNOPSIS
Say an answer to 'thank you'
Replies to 'thank you'
.DESCRIPTION
This script answers to "thank you" by text-to-speech (TTS).
This script replies to 'thank you' by text-to-speech (TTS).
.EXAMPLE
PS> ./thank-you
.NOTES
@ -11,8 +11,7 @@
https://github.com/fleschutz/PowerShell
#>
$Answer = "It's a pleasure.", "Never mind." | Get-Random
$Reply = "It's a pleasure.", "Never mind.", "Pleasure is mine." | Get-Random
& "$PSScriptRoot/speak-english.ps1" "$Answer"
write-output "$Answer"
& "$PSScriptRoot/give-reply.ps1" "$Reply"
exit 0 # success

View File

@ -16,8 +16,7 @@
param([string]$abbreviation = "")
function Reply { param([string]$Text)
"$Text"
& "$PSScriptRoot/speak-english.ps1" "$Text"
& "$PSScriptRoot/give-reply.ps1" "$Text"
}
try {
@ -31,7 +30,7 @@ try {
foreach($Row in $Table) {
if ($Row.Abbreviation -eq $abbreviation) {
$Basename = (get-item "$File").Basename
Reply " - $($Row.Definition) ($($Row.Abbreviation)) in $Basename"
Reply "$($Row.Definition) ($($Row.Abbreviation)) in $Basename"
$FoundOne = $true
}
}