-
Notifications
You must be signed in to change notification settings - Fork 0
/
jokes.ts
37 lines (32 loc) · 1.04 KB
/
jokes.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import chalk from "chalk";
import axios from "axios";
import { Command, flags } from "@oclif/command";
import chalkAnimation from "chalk-animation";
export default class Jokes extends Command {
static description = "Get a random joke";
async run() {
this.getJokes();
}
getJokes = async () => {
try {
const JOKES_URL = "https://dad-jokes.p.rapidapi.com/random/joke";
const API_KEY = "8efac4fd3amshf239fb505eb2a21p12a89djsne89b3fa02711";
const { data } = await axios.get(JOKES_URL, {
headers: {
"x-rapidapi-key": API_KEY,
"x-rapidapi-host": "dad-jokes.p.rapidapi.com",
useQueryString: true,
},
});
const { punchline, setup } = data.body[0];
console.log("\n", chalk.green(setup));
chalkAnimation.karaoke(".....................................");
setTimeout(() => {
console.log("\n", chalk.yellow(punchline));
console.log("\n", "(〃´艸`)");
}, 6000);
} catch (e) {
console.log(chalk.red(e.message));
}
};
}