Skip to content

Instantly share code, notes, and snippets.

@RajatGoyal
Created February 12, 2023 13:41
Show Gist options
  • Save RajatGoyal/163d34243ef618f73d2597ea0b31eece to your computer and use it in GitHub Desktop.
Save RajatGoyal/163d34243ef618f73d2597ea0b31eece to your computer and use it in GitHub Desktop.
/*
# Speak Text Requested from an API
- Requests a joke from [https://icanhazdadjoke.com](https://icanhazdadjoke.com)
- Speaks the joke
- Tap `y` to speak another joke
*/
// Name: Dad Joke
// Description: Dad Joke from icanhazdadjoke.com
// Author: John Lindquist
// Twitter: @johnlindquist
import "@johnlindquist/kit"
let getJoke = async () => {
let response = await get(`https://icanhazdadjoke.com/`, {
headers: {
Accept: "text/plain",
"User-Agent": "axios 0.21.1",
},
})
say(response.data)
return `<div class="text-center text-4xl p-10 font-semibold">${response.data}</div>`
}
while (true) {
let yesOrNo = await arg(
{
placeholder: "Dad Joke",
enter: ``,
shortcuts: [
{
name: "Another",
key: `Y`,
onPress: () => submit("y"),
bar: "right",
},
{
name: "Please, make it stop!",
key: `N`,
onPress: () => submit("n"),
bar: "right",
},
],
},
async () => {
return await getJoke()
}
)
if (yesOrNo === "n") break
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment