1import { fetch } from "https://esm.town/v/std/fetch";
2import { sqlite } from "https://esm.town/v/std/sqlite";
3// import randomPokemon from "jsr:random-pokemon";
22 console.log("handler.weather args=", args);
23 const location = encodeURIComponent(args.join(" "));
24 const res = await fetch(`https://wttr.in/${location}?format=%l:+%c+%t`);
25 if (!res.ok) {
26 console.error("weather fetch failed", res.status);
27 return `❌ Unable to fetch weather for "${args.join(" ")}"`;
28 }
29 return await res.text();
31 catfact: async () => {
32 console.log("handler.catfact");
33 const res = await fetch("https://catfact.ninja/fact");
34 if (!res.ok) {
35 console.error("catfact fetch failed", res.status);
36 return "❌ Couldn’t fetch a cat fact right now. Try again later!";
37 }
38 const { fact } = await res.json() as { fact: string };
41 advice: async () => {
42 console.log("handler.advice");
43 const res = await fetch("https://api.adviceslip.com/advice");
44 if (!res.ok) {
45 console.error("advice fetch failed", res.status);
46 return "❌ Couldn't fetch advice right now. Try again later!";
47 }
48 const { slip } = await res.json() as { slip: { advice: string } };
52 console.log("handler.dadjoke");
53 // icanhazdadjoke returns one random dad joke per request
54 const res = await fetch("https://icanhazdadjoke.com/", {
55 headers: { Accept: "application/json" },
56 });
57 if (!res.ok) {
58 console.error("dadjoke fetch failed", res.status);
59 return "❌ Couldn't fetch a joke right now. Try again later!";
60 }
61 const { joke } = await res.json() as { joke: string };
64 trivia: async () => {
65 console.log("handler.trivia");
66 const res = await fetch("http://numbersapi.com/random/trivia?json");
67 if (!res.ok) {
68 console.error("trivia fetch failed", res.status);
69 return "❌ Couldn't fetch trivia right now. Try again later!";
70 }
71 const { text, number } = await res.json() as { text: string; number: number };
74 compliment: async () => {
75 console.log("handler.compliment");
76 const res = await fetch("https://complimentr.com/api");
77 if (!res.ok) {
78 console.error("compliment fetch failed", res.status);
79 return "❌ Couldn't fetch a compliment right now. Try again later!";
80 }
81 const { compliment } = await res.json() as { compliment: string };
84 insult: async () => {
85 console.log("handler.insult");
86 const res = await fetch("https://evilinsult.com/generate_insult.php?lang=en&type=json");
87 if (!res.ok) {
88 console.error("insult fetch failed", res.status);
89 return "❌ Couldn't fetch an insult right now. Try again later!";
90 }
91 const { insult } = await res.json() as { insult: string };
215
216 try {
217 const res = await fetch(`https://ohmanda.com/api/horoscope/${sign}`);
218 if (!res.ok) {
219 console.error("horoscope fetch failed", res.status);
220 return "❌ Couldn't fetch horoscope. Try again later!";
221 }
222 const { horoscope } = await res.json() as { horoscope: string };
223 return `🔮 ${sign.charAt(0).toUpperCase() + sign.slice(1)}: ${horoscope}`;
224 } catch {
225 return "❌ Something went wrong fetching your stars!";
226 }
227 },
232 // return `🧬 Your Pokémon is: ${name.charAt(0).toUpperCase() + name.slice(1)}`;
233 // } catch {
234 // return "❌ Couldn't fetch a Pokémon!";
235 // }
236 // },
348 setTimeout(async () => {
349 try {
350 await fetch(responseUrl, {
351 method: "POST",
352 headers: { "Content-Type": "application/json" },
376 setTimeout(async () => {
377 try {
378 await fetch(responseUrl, {
379 method: "POST",
380 headers: { "Content-Type": "application/json" },
407 // }
408
409 // fetch one random chatter
410 let favorite: string;
411 try {
412 const res = await fetch(
413 `https://commands.garretcharp.com/twitch/chatter/vevisk?count=1&moderatorId=106247697`,
414 );
419 favorite = chatters[0]; // only one requested
420 } catch (err) {
421 console.error("favorite fetch failed", err);
422 return new Response("❌ Couldn't pick a favorite viewer right now.", {
423 headers: { "Content-Type": "text/plain" },
430 const drumroll = setTimeout(async () => {
431 try {
432 await fetch(responseUrl, {
433 method: "POST",
434 headers: { "Content-Type": "application/json" },
442 const reveal = setTimeout(async () => {
443 try {
444 await fetch(responseUrl, {
445 method: "POST",
446 headers: { "Content-Type": "application/json" },
473 // setTimeout(async () => {
474 // try {
475 // await fetch(responseUrl, {
476 // method: "POST",
477 // headers: { "Content-Type": "application/json" },
486 setTimeout(async () => {
487 try {
488 await fetch(responseUrl, {
489 method: "POST",
490 headers: { "Content-Type": "application/json" },